简体   繁体   English

将运行时中的maxZoom选项更改为angular-openlayers-directive中的ol.View

[英]Change maxZoom option in runtime to ol.View in angular-openlayers-directive

I posted this question to change maxZoom in runtime using openlayers3 and that works perfect: 我发布了这个问题 ,使用openlayers3在运行时更改maxZoom,并且完美无缺:

map.setView(new ol.View({
  zoom: 10,
  maxZoom: 17,
  minZoom: 10,
}));

However, im trying to integrate this solution using the angular-openlayers-directive and the map is disappearing. 但是,我试图使用angular-openlayers-directive和地图整合这个解决方案正在消失。 Here a Plunker demo failing . 这里有一个Plunker演示失败 I tried creating new directive and also didn't work. 我尝试创建新指令,但也没有用。

olData.getMap().then(function(map){
  map.setView(new ol.View({
    zoom: 11,
    maxZoom: 11,
    minZoom: 0,
  }));
});

Any suggestions on how to integrate this and if you could make it work in the Plunker demo would be great. 关于如何整合这个以及如果你能在Plunker演示中使用它的任何建议都会很棒。

See the documentation of ol.View object 请参阅ol.View对象的文档

http://openlayers.org/en/v3.2.1/apidoc/ol.View.html http://openlayers.org/en/v3.2.1/apidoc/ol.View.html

If center option is not given while creating ol.View object it is taken as undefined . 如果在创建ol.View对象时未给出center选项, ol.View其视为undefined If its undefined then layer sources will not be fetched..In $scope.changeZoom() method center was undefined since it was not provided while creating. 如果undefined则不会获取图层源。在$scope.changeZoom()方法中心未定义,因为创建时未提供。 Because of this map object was not loaded correctly. 由于此映射对象未正确加载。

Fix 固定

olData.getMap().then(function(map){
   map.setView(new ol.View({
      center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
      zoom: 11,
      maxZoom: 11,
      minZoom: 0,
   }));
});

I have given some random coordinates as center. 我给了一些随机坐标作为中心。 See the working plunk code here 请在此处查看工作插件代码

I'm not entirely sure why they aren't the same (I didn't investigate the ordinary ol3 solution you stated) but after stepping through the ol-debug.js code it seems it's drawing a blank frame because the new view doesn't have a center. 我不完全确定为什么它们不一样(我没有调查你所说的普通ol3解决方案)但是在逐步完成ol-debug.js代码后,似乎它正在绘制一个空白框架因为新视图没有有一个中心。

You can set the center using the existing view's center: 您可以使用现有视图的中心设置中心:

$scope.changeZoom = function () {
    olData.getMap().then(function (map) {
        newView = new ol.View({
            zoom: 5,
            maxZoom: 20,
            minZoom: 0,
        });
        newView.setCenter(map.getView().getCenter());
        map.setView(newView);
    });
};

And here's a working plunker *. 这是一个工作的plunker *。

*I haven't used plunker before this so if it doesn't work let me know and I'll try again! *我之前没有使用过plunker所以如果它不起作用请告诉我,我会再试一次!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM