javascript - How to dynamically set shadow in Leaflet.js -
i dynamically set shadow of custom marker icon @ runtime, because want emphasize clicked icon. i'm using leaflet 1.0. things i've tried:
adding shadow @ runtime
createshadow
functionadding blank png shadow image custom icon , changing @ runtime either
createshadow
function or directly modifying shadow's image source
here's psuedocode:
function addmyshadow(marker) { /* try leaflet's `createshadow` function */ // directly modify marker: uncaught typeerror: marker.createshadow not function marker.createshadow('lib/images/shadow.png'); // createshadow available under options.icon, // doesn't seem change marker.options.icon.createshadow('lib/images/shadow.png'); /* try directly modifying shadow's image source */ // changes `currectsrc` property, // doesn't icon on map marker._shadow.currentsrc = 'lib/images/shadow.png'; }
i tried appending custom class
-webkit-filter: drop-shadow
, i'm using-webkit-filter
color set of icons. want change selected icon, not entire class. apparently nesting-webkit-filter
overwrites outside-webkit-filter
instead of stacking filters. isn't viable option me.currently i'm experimenting adding custom class uses css
drop-shadow
; seems can manually change class @ runtime, i'm hoping there's better built-in way add shadow. it's not pretty, because makes shadow square if image has transparency.
edit: want marker draggable (and have shadow follow marker dragged). solution 2 icons need bind both icons somehow.
i think should have 2 l.icon objects: 1 without shadow , 1 shadow.
to show shadow, switch l.icon
marker.on('click', function(e) { if(selectedmarker) { if(selectedmarker !== e.target) { // selected marker not 1 selectedmarker.seticon(greenicon); e.target.seticon(greeniconwithshadow); selectedmarker = e.target; } else { // selected marker 1 selectedmarker.seticon(greenicon); selectedmarker = false; } } else { // no marker selected selectedmarker = e.target; e.target.seticon(greeniconwithshadow); } });
the shadow part of l.icon , should follow when dragged
see example http://plnkr.co/edit/pnxzjqmbcrtuo0jwpgyj?p=preview
Comments
Post a Comment