【发布时间】:2017-06-21 16:13:44
【问题描述】:
我想在用户找到自己之后添加一个标记。
我尝试收听 geolocate 事件,但没有添加任何标记。 我应该怎么做?
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...),标记会显示吗?
标签: geolocation mapbox mapbox-gl-js