Rotating markers depending on field value

360 views
Skip to first unread message

Stephan Besser

unread,
May 11, 2013, 3:11:22 PM5/11/13
to leaflet-ve...@googlegroups.com
Hi there,

first of all, thanks for this great plugin! It's absolutely easy to use and works very well.
My use case is to add an automatically updated layer to my leaflet map using "vector layers" plugin. I'm querying a pgsql/postgis backend using PRWSF. (One site note here is that the "vector layers" queries have to be adjusted to use "ST_" prepended to most postgis functions if postgis version 2.x is in use.) After new data is received from the backend, I would like to rotate the markers depending on a fetched postgis column value. Now I'm wondering if there is an elegant way of doing this with "vector layers" or am I forced to use unique/range symbology to request a LOT of rotated images via iconUrl? If someone could point me to a documentation/example where this has been successfully implemented I would be very happy because all things I have found so far only apply to the standard leaflet layers/icons that will be updated/rotated after map panning events or on first load.

Thanks in advance,

Stephan

Jason Sanford

unread,
May 14, 2013, 3:44:13 PM5/14/13
to leaflet-ve...@googlegroups.com
Hi Stephan

I'm glad you're finding Leaflet Vector Layers useful. Have you checked out the `dynaimic` and `autoUpdate` options for layers yet? The combination of these two options should allow you to do what you need.

Do you have a publicly accessible endpoint available that I could help debug with?

Thanks
Jason

--
You received this message because you are subscribed to the Google Groups "Leaflet Vector Layers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-vector-l...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Stephan Besser

unread,
May 27, 2013, 1:34:24 AM5/27/13
to leaflet-ve...@googlegroups.com

Ji Jason,

thanks for replying to my issue. Meanwhile I was fighting with javascript and our leaflet map to get things working. I now finally use a completely different approach since I switched the backend service to a standardized WFS that is serving geojson if requested. For my markers I use the standard leaflet DivIcon. Rotation is applied to each feature after successful AJAX request by simply altering the html property of the DivIcon. Here is some sample code:

rotateString = "rotate(" + calc_bearing + "deg)";
layer.options.icon.options.html = "<div style='width: " + getSize() + "px; height: " + getSize() + "px; transform: " + rotateString + "'>" + layer.options.icon.options.iconSvg + "</div>";

Since I'm fairly new to javascript there may be a much better way to do this but currently it is working fine. 

Best wishes,

Stephan
Reply all
Reply to author
Forward
0 new messages