【问题标题】:How to identify if the pushpin is visible in the current view/zoom of bingMaps or not? if not visible setView to Location of the pushpin?如何识别图钉在 bingMaps 的当前视图/缩放中是否可见?如果不可见 setView 到图钉的位置?
【发布时间】:2021-05-18 15:14:18
【问题描述】:

我正在使用 Bing Maps V8,根据要求,我必须移动/平移 bing 地图以设置图钉的可见性。根据图钉位置,我们可以直接设置视图,如下所示,但只有当 bing 地图的当前视图没有肉眼可见的图钉时,我才会调整/移动 bing 地图。

this.map.setView({
     center: new Microsoft.Maps.Location(pin.lat, pin.long),
});

您能否分享您对如何识别图钉在当前视图中是否可见的想法?

提前致谢。

【问题讨论】:

    标签: javascript bing-maps


    【解决方案1】:

    获取地图的边界框,然后检查它是否包含您的图钉位置。如果它不更新地图视图。这是执行此操作的代码块。

    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
    var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(45, -110), null);
    map.entities.push(pushpin);
    
    //Get the bounding box of the current map view.
    var bounds = map.getBounds();
    
    //Check to see if the bounding box contains the pushpins location. 
    //And if it doesn't, center the map.
    if(!bounds.contains(pushpin.getLocation())) {
        map.setView({
            center: pushpin.getLocation()
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 2014-08-04
      相关资源
      最近更新 更多