0
我想在用戶找到自己後添加標記。Hopw使用mapboxgl.GeolocateControl添加標記到地圖框
我嘗試收聽地理定位事件,但沒有添加標記。 我應該如何繼續?
map.addControl(new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true,
watchPosition: true
}
}));
map.on('geolocate ',() => {
map.loadImage('images/pin2.png', (error, image, data) => {
if (error) throw error;
console.log(data);
map.addImage('pin2', image);
map.addLayer({
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [data.position]
}
}]
}
},
"layout": {
"icon-image": "pin2",
"icon-size": 1
}
});
});
});
是先計算出如果問題是地理定位的控制不射擊,或標記不可見,或兩者的某種組合。所以 - 如果您將代碼移動到「on('load' ...)''上,標記是否會顯示? –