【发布时间】:2015-11-05 17:44:39
【问题描述】:
所以,我在 Openlayers 3.9.0 地图中关闭地理定位功能的想法是有一个切换按钮,当点击该按钮时,它会停止跟踪并从地理定位图层中删除该功能
geolocation.setTracking('false');
featuresOverlay.getSource().clear();
然后再次打开它,它会打开跟踪,向地理定位图层添加一个特征,设置其坐标并重新居中地图
geolocation.setTracking('true');
featuresOverlay.getSource().addFeature(positionFeature);
var coordinates = geolocation.getPosition();
positionFeature.setGeometry(coordinates ? new ol.geom.Point(coordinates) : null);
view.setCenter(coordinates);
嗯,这在技术上不算是打开/关闭地理定位,因为它移除了所有视觉元素,实际上并没有打开/关闭 API。有没有这样的可能,还是以上就够了?
【问题讨论】: