How to use the ol/View function in ol

To help you get started, we’ve selected a few ol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Viglino / ol-ext / src / overlay / Magnify.js View on Github external
var ol_Overlay_Magnify = function (options) {
	var elt = document.createElement("div");
			elt.className = "ol-magnify";
	this._elt = elt;

	ol_Overlay.call(this,
		{	positioning: options.positioning || "center-center",
			element: this._elt,
			stopEvent: false
		});
	// Create magnify map
	this.mgmap_ = new ol_Map(
	{	controls: new ol_Collection(),
		interactions: new ol_Collection(),
		target: options.target || this._elt,
		view: new ol_View({ projection: options.projection }),
		layers: options.layers
	});
	this.mgview_ = this.mgmap_.getView();

	this.external_ = options.target?true:false;

	this.set("zoomOffset", options.zoomOffset||1);
	this.set("active", true);
	this.on("propertychange", this.setView_.bind(this));
};
ol_ext_inherits(ol_Overlay_Magnify, ol_Overlay);
github Viglino / ol-games / game / Game.js View on Github external
var ol_Game = function(options) {
  options = options || {};
  
  ol_Object.call (this);

  var map = options.map || new ol_Map ({
    target: options.target,
    loadTilesWhileAnimating: true,
    loadTilesWhileInteracting: true,
    view: new ol_View ({
      zoom: options.zoom,
      center: options.center
    }),
    interactions: [],
    controls: [],
    layers: options.layers,
  });

  if (options.controls) for (var i=0; i
github openlayers / ol-mapbox-style / index.js View on Github external
function processStyle(glStyle, map, baseUrl, host, path, accessToken) {
  const promises = [];
  let view = map.getView();
  if (!view.isDef() && !view.getRotation() && !view.getResolutions()) {
    view = new View({
      maxResolution: defaultResolutions[0]
    });
    map.setView(view);
  }

  if ('center' in glStyle && !view.getCenter()) {
    view.setCenter(fromLonLat(glStyle.center));
  }
  if ('zoom' in glStyle && view.getZoom() === undefined) {
    view.setResolution(defaultResolutions[0] / Math.pow(2, glStyle.zoom));
  }
  if (!view.getCenter() || view.getZoom() === undefined) {
    view.fit(view.getProjection().getExtent(), {
      nearest: true,
      size: map.getSize()
    });
github infra-geo-ouverte / igo2-lib / projects / geo / src / lib / map / shared / map.ts View on Github external
setView(options: MapViewOptions) {
    const view = new olView(options);
    this.ol.setView(view);

    this.unsubscribeGeolocate();
    if (options) {
      if (options.center) {
        const center = olproj.fromLonLat(options.center, this.projection);
        view.setCenter(center);
      }

      if (options.geolocate) {
        this.geolocate(true);
      }
    }
  }
github openlayers / workshop / src / en / examples / vector / download.js View on Github external
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import GeoJSON from 'ol/format/GeoJSON';
import GeometryType from 'ol/geom/GeometryType';
import {DragAndDrop, Draw, Modify, Snap} from 'ol/interaction';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import sync from 'ol-hashed';

const map = new Map({
  target: 'map-container',
  view: new View({
    center: [0, 0],
    zoom: 2
  })
});

sync(map);

const source = new VectorSource();

const layer = new VectorLayer({
  source: source
});
map.addLayer(layer);

map.addInteraction(new DragAndDrop({
  source: source,
github hslayers / hslayers-ng / components / map / map.service.js View on Github external
function createPlaceholderView() {
        return new View({
            center: transform([17.474129, 52.574000], 'EPSG:4326', 'EPSG:3857'), //Latitude longitude    to Spherical Mercator
            zoom: 4,
            units: "m"
        })
    }
github infra-geo-ouverte / igo2-lib / packages / geo / src / lib / map / shared / map.ts View on Github external
setView(options: MapViewOptions) {
    if (this.viewController !== undefined) {
      this.viewController.clearStateHistory();
    }

    const view = new olView(options);
    this.ol.setView(view);

    this.unsubscribeGeolocate();
    if (options) {
      if (options.center) {
        const projection = view.getProjection().getCode();
        const center = olproj.fromLonLat(options.center, projection);
        view.setCenter(center);
      }

      if (options.geolocate) {
        this.geolocate(true);
      }
    }
  }
github openlayers / openlayers / examples / export-map.js View on Github external
import {OSM, Vector as VectorSource} from 'ol/source';

const map = new Map({
  layers: [
    new TileLayer({
      source: new OSM()
    }),
    new VectorLayer({
      source: new VectorSource({
        url: 'data/geojson/countries.geojson',
        format: new GeoJSON()
      })
    })
  ],
  target: 'map',
  view: new View({
    center: [0, 0],
    zoom: 2
  })
});

document.getElementById('export-png').addEventListener('click', function() {
  map.once('rendercomplete', function() {
    domtoimage.toPng(map.getViewport().querySelector('.ol-layers'))
      .then(function(dataURL) {
        const link = document.getElementById('image-download');
        link.href = dataURL;
        link.click();
      });
  });
  map.renderSync();
});
github ghettovoice / vuelayers / src / component / map / view.vue View on Github external
createOlObject () {
        const view = new View({
          center: this.pointToViewProj(this.center),
          constrainRotation: this.constrainRotation,
          enableRotation: this.enableRotation,
          extent: this.extent ? this.extentToViewProj(this.extent) : undefined,
          maxResolution: this.maxResolution,
          minResolution: this.minResolution,
          maxZoom: this.maxZoom,
          minZoom: this.minZoom,
          projection: this.projection,
          resolution: this.resolution,
          resolutions: this.resolutions,
          rotation: this.rotation,
          zoom: this.zoom,
          zoomFactor: this.zoomFactor,
        })
github dcmjs-org / dicom-microscopy-viewer / src / api.js View on Github external
extent: extent,
      source: this[_drawingSource],
      projection: projection,
      updateWhileAnimating: true,
      updateWhileInteracting: true,
    });

    const view = new View({
      center: getCenter(extent),
      extent: extent,
      projection: projection,
      resolutions: resolutions,
      rotation: rotation
    });

    const overviewView = new View({
      projection: projection,
      resolutions: resolutions,
      rotation: rotation
    });

    this[_interactions] = {
      draw: undefined,
      select: undefined,
      modify: undefined
    };

    this[_controls] = {
      scale: new ScaleLine({
        units: 'metric',
        className: ''
      })