3

I try to rotate a custom Marker icon inside Mapbox gl-js. All the commented attempts not working. Are we absolutely need to go with geojson sources to rotate an icon and a custom one that is not able to fit on Maki svg standard! ?

$.get(mapyim, function (resp) {
  resp.features.forEach(function(marker) {
  var el = document.createElement('div');
  el.className = 'myMarkerClassCss';
  // el.style.transform = 'rotate(' + marker.properties.angle + 'deg)';
  el.addEventListener('click', function() {
    window.alert(marker.properties.title + '/' + marker.properties.date);
  });

  // add marker to map
  new mapboxgl.Marker(el, {
    // rotate: marker.properties.angle,
    offset: [
      -26 / 2,
      -33 / 2
    ]
  })
  .setLngLat(marker.geometry.coordinates)
  .addTo(map);
 });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.