Mapbox GL JS自定义标记偏移量

问题描述

我已按照此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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...