Mapbox标记旋转/轴承

时间:2019-01-17 13:16:35

标签: javascript reactjs mapbox-gl-js

是否有机会设置标记的旋转度?现在,我将地图方位角设置为一个标记的角度,但其他标记应具有自己的标记方位。

此刻,我正在使用标记定义,如下所示:

var marker_el = document.createElement('div');
marker_el .className = 'marker';
var new_marker = new mapboxgl.Marker(marker_el)
    .setPopup(marker_PopUp);

并将其设置为地图:

new_marker.setLngLat([lon, lat]);
new_marker.addTo(map);

我正在使用JS并做出反应,并为地图mapbox-gl

1 个答案:

答案 0 :(得分:2)

所以因为没有答案,所以我用适合自己的解决方案自行回答了我的帖子:

var angle = "yourAngle";
var rotateString = "rotate(" + angle + "deg)";

var marker_el = document.createElement('div');
marker_el.className = 'marker';
var new_marker = new mapboxgl.Marker(marker_el);
new_marker.addTo(map);

/* important here is to append the rotate property because the transform 
property is already being updated */
marker_el.style.transform = marker_el.style.transform + rotateString;