OpenLayers 4阻止在所有resolutoins中拖出外边界

时间:2018-04-17 04:39:55

标签: javascript openlayers

我需要将地图限制为仅在地图视图中拖动,但它还需要在多个分辨率下工作:

  var extent = [0, 0, 1685, 895];
  var projection = new ol.proj.Projection({
    units: 'pixels',
    extent: extent
  });

  var map = new ol.Map({
    layers: [
      new ol.layer.Image({
        source: new ol.source.ImageStatic({
          url: 'assets/img/map.png',
          projection: projection,
          imageExtent: [0, 0, 1685, 895]
        })
      })
    ],
    target: 'map',
    view: new ol.View({
      projection: projection,
      center: ol.extent.getCenter(extent),
      zoom: 3,
      maxZoom: 5,
      minZoom: 3
    })
  });

0 个答案:

没有答案