update several plugins to use window.addLayerGroup, instead of manually adding the layer to the map and Layer control.

this gives automatic handling of remembering shown/hidden layers

also, draw tools plugin hides the controls while the drawn items layer is hidden
This commit is contained in:
Jon Atkins
2013-05-18 03:42:56 +01:00
parent 2f482bf4a4
commit 6e8dd15052
4 changed files with 24 additions and 9 deletions

View File

@ -119,14 +119,31 @@ window.plugin.drawTools.boot = function() {
//create a leaflet FeatureGroup to hold drawn items
window.plugin.drawTools.drawnItems = new L.FeatureGroup();
var drawnItems = window.plugin.drawTools.drawnItems;
window.layerChooser.addOverlay(drawnItems, 'Drawn Items');
map.addLayer(drawnItems);
//add the draw control - this references the above FeatureGroup for editing purposes
plugin.drawTools.addDrawControl();
//start off hidden. if the layer is enabled, the below addLayerGroup will add it, triggering a 'show'
$('.leaflet-draw-section').hide();
//hide the draw tools when the 'drawn items' layer is off, show it when on
map.on('layeradd', function(obj) {
if(obj.layer === window.plugin.drawTools.drawnItems) {
$('.leaflet-draw-section').show();
}
});
map.on('layerremove', function(obj) {
if(obj.layer === window.plugin.drawTools.drawnItems) {
$('.leaflet-draw-section').hide();
}
});
//add the layer
window.addLayerGroup('Drawn Items', window.plugin.drawTools.drawnItems);
//place created items into the specific layer
map.on('draw:created', function(e) {
var type=e.layerType;
var layer=e.layer;