cancel drawing and prvent multiple drawings at once

This commit is contained in:
Laura Klünder 2016-09-20 12:08:16 +02:00
parent 52d7b5b121
commit de35a20854

View file

@ -30,7 +30,7 @@ editor = {
editcontrols.append( editcontrols.append(
$('<fieldset>').attr('name', feature_type.name).append( $('<fieldset>').attr('name', feature_type.name).append(
$('<legend>').text(feature_type.title_plural).append( $('<legend>').text(feature_type.title_plural).append(
$('<button class="btn btn-primary btn-xs pull-right"><i class="glyphicon glyphicon-plus"></i></button>') $('<button class="btn btn-default btn-xs pull-right start-drawing"><i class="glyphicon glyphicon-plus"></i></button>')
) )
) )
); );
@ -126,7 +126,7 @@ editor = {
}); });
editor.map.addControl(new L.DrawControl()); editor.map.addControl(new L.DrawControl());
$('#mapeditcontrols').on('click', 'fieldset legend .btn', function() { $('#mapeditcontrols').on('click', '.start-drawing', function() {
console.log($(this).closest('fieldset')); console.log($(this).closest('fieldset'));
editor.start_drawing($(this).closest('fieldset').attr('name')); editor.start_drawing($(this).closest('fieldset').attr('name'));
}); });
@ -140,16 +140,17 @@ editor = {
closeButton: false, closeButton: false,
autoClose: false, autoClose: false,
}).setContent('<img src="/static/img/loader.gif">').setLatLng(e.layer.getCenter()).openOn(editor.map); }).setContent('<img src="/static/img/loader.gif">').setLatLng(e.layer.getCenter()).openOn(editor.map);
console.log(e.layer.toGeoJSON()); $('.leaflet-drawbar').hide();
}).on('editable:drawing:cancel', function (e) { }).on('editable:drawing:cancel', function (e) {
if (editor._drawing !== null && editor._adding === null) { if (editor._drawing !== null && editor._adding === null) {
e.layer.remove(); e.layer.remove();
$('.start-drawing').prop('disabled', false);
} }
}); });
}, },
start_drawing: function(feature_type) { start_drawing: function(feature_type) {
console.log(feature_type); if (editor._drawing !== null || editor._adding !== null) return;
editor._drawing = feature_type; editor._drawing = feature_type;
var options = editor.feature_types[feature_type]; var options = editor.feature_types[feature_type];
if (options.geomtype == 'polygon') { if (options.geomtype == 'polygon') {
@ -157,16 +158,14 @@ editor = {
} else if (options.geomtype == 'polyline') { } else if (options.geomtype == 'polyline') {
editor.map.editTools.startPolyline(null, options); editor.map.editTools.startPolyline(null, options);
} }
$('.leaflet-editbar').toggleClass('usable', false); $('.leaflet-drawbar').show();
$('#drawstart').hide(); $('.start-drawing').prop('disabled', true);
$('#drawcancel').show();
}, },
cancel_drawing: function() { cancel_drawing: function() {
if (editor._drawing === null || editor._adding !== null) return; if (editor._drawing === null || editor._adding !== null) return;
editor.map.editTools.stopDrawing(); editor.map.editTools.stopDrawing();
editor._drawing = null; editor._drawing = null;
$('#drawcancel').hide(); $('.leaflet-drawbar').hide();
$('#drawstart').show();
}, },
}; };