Raruto / leaflet-rotate

Leaflet plugin that allows to add rotation functionality to map tiles
GNU General Public License v3.0
81 stars 23 forks source link

Question: Is there an option to rotate the marker from center? #40

Closed DSoftwareArtist closed 11 months ago

DSoftwareArtist commented 1 year ago

@Raruto ,

Currently, the behavior of the marker rotation is like this:

But what I want to achieve is like this:

Here's my code:

const marker = L.marker( L.latLng(0,0), {
   draggable: false,
   icon: L.icon( ... )
}).addTo(map)

marker.setRotation(70) 

I hope there's an option that I can apply for this. Thanks!

DSoftwareArtist commented 1 year ago

I also don't think if the angle is properly set. @Raruto

const x = L.marker(L.latLng(0,0)).bindTooltip('<b>' + 'reamon' + '</b>').addTo(map)
x.setRotation(30)

Screenshot from 2023-08-31 16-21-29

Raruto commented 1 year ago

Hi Reamon

Is there an option to rotate the marker from center?

I don't think so (out of the box).

Eventually you could test with some other L.Icon properties, eg:

BTW, please start poring over the code to get a feel for possibile alternatives.

For instance, you can start from here:

https://github.com/Raruto/leaflet-rotate/blob/48e97a6408df7796b3e06e6d8eb0729eb504b1be/src/layer/marker/Marker.js#L1-L159

https://github.com/Raruto/leaflet-rotate/blob/48e97a6408df7796b3e06e6d8eb0729eb504b1be/src/layer/marker/Icon.js#L1-L38

With some effort, you should be able to come up with something similar on your own.

👋 Raruto