问题描述
我已按照此Mapbox教程制作了带有自定义标记的地图。 https://docs.mapbox.com/help/tutorials/custom-markers-gl-js/
在此代码中的某处,我应该能够调整标记的偏移量,因为标记根本没有放置在坐标上。
var geojson = {
type: 'FeatureCollection',features: [{
type: 'Feature',geometry: {
type: 'Point',coordinates: [31.442553,31.656087]
},properties: {
title: 'Diametta,Egypt',description: 'Horus Academy'
}
}]
};
var map = new mapboxgl.Map({
container: 'map',style: 'mapbox://styles/torkjellt/ckdpx4l7r0n5c1inwgw0pl1pq',location
center: ([30.71,30.41]),// starting position [lng,lat]
zoom: 5 // starting zoom
});
geojson.features.forEach(function(marker) {
var el = document.createElement('div');
el.className = 'marker';
new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
.setPopup(new mapboxgl.Popup({ offset: 5 }) // add popups
.setHTML('<strong>My spot</strong><br>Egypt'))
.addTo(map);
});
关于在哪里调整偏移量的任何想法?
解决方法
值offset
应该是PointLike
,因此是一个数组:
.setPopup(new mapboxgl.Popup({ offset: [0,-5] }) // 5 pixels upwards