Skip to content

How do change the color and other properties of polygon and polyline drawings on the map? #1180

Discussion options

You must be logged in to vote

To change the color while drawing you can set pathOptions:

// set the options for the different draw modes, will be also applied to the buttons in the toolbar
map.pm.enableDraw('Line',{pathOptions:{color:'red'}});
map.pm.enableDraw('Polygon', {pathOptions:{color:'green'}});
map.pm.disableDraw();

or

map.pm.setGlobalOptions({pathOptions:{color:'red'}});

https://jsfiddle.net/falkedesign/3tyr8pcz/

To style after drawing listen on the pm:create:

map.on('pm:create',(e)=>{
   if(e.layer instanceof L.Polyline){
       e.layer.setStyle({color: 'orange'});
    }
});

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@hamish0361
Comment options

@Falke-Design
Comment options

@hamish0361
Comment options

Answer selected by Falke-Design
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants