2
所以,我在3.9.0的OpenLayers地圖關閉地理定位功能的想法是有一個切換按鈕,單擊時被停止跟蹤,並從地理位置層去除功能關閉的OpenLayers 3地理位置
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);
好了,這在技術上不能算作轉彎開/關地理定位,因爲它去除了所有的視覺元素, t實際上並不打開/關閉API。有沒有這樣的可能性,或者上述情況足夠了?
有史以來最有用的觀察。非常感謝 – slevin