This demo show the functionality of the SelectAreaFeature plugin.
The user can enable the plugin by pressing the button "enable". The map can not be dragged anymore.
After that the user can draw an area, by holding the left mouse button and start moving, on the map. More areas can be draw on the map at the same time. Untill the user clicks on the "disable" button.
button | plugin method | description |
---|---|---|
enable | selectfeature = map.selectAreaFeature.enable(); selectfeature.options.color = '#663399' ; selectfeature.options.weight = 3 ; |
activate the plugin |
disable | selectfeature.disable(); |
deactivates the plugin |
get polygons features | var selected_features = selectfeature.getFeaturesSelected( 'polygon' ); |
selects all polygons/rectangles that are in the Bounds of the area(s) into an array |
set fill color to selected polygons | ## no methods from pluginif ( selected_features.length != 0 && selected_features.length >= 1 ) { alert('change fill color of selected polygon'); for (i=0; i < selected_features.length; i++ ) { selected_features[i].setStyle({fillColor: 'green', fillOpacity: 1 });} |
once you have access to the array of features you can manapulate the features |
get all features | var selected_features = selectfeature.getFeaturesSelected( 'all' ); |
puts all the features into an array that are in the Bounds of the area(s) |
set weigt 4 if feature is a line | ## no methods from pluginif ( selected_features.length != 0 && selected_features.length >= 1 ) { alert('change weight of selected polylines'); for (i=0; i < selected_features.length; i++ ) { if ( selected_features[i] instanceof L.Polyline ){ selected_features[i].setStyle({ weight: 4 }); } } } |
loops through the array of features and if it is a line set the weight to 4 |
get latlng of latest area drawn | var latlng_area = selectfeature.getAreaLatLng( ); |
get the LatLng pairs of the last area drawn |
show latlng of latest area drawn | ## no methods from pluginalert(latlng_area); |
show an alert with the LatLngs of the area |
delete last area drawn | selectfeature.removeLastArea(); |
deletes the area on the map |
delete all area(s) drawn | selectfeature.removeAllArea(); |
removes all areas from the map |