snap to original
This commit is contained in:
parent
51c0117b9d
commit
593d4179e3
1 changed files with 43 additions and 0 deletions
|
@ -163,6 +163,7 @@ editor = {
|
||||||
},
|
},
|
||||||
_sidebar_unload: function () {
|
_sidebar_unload: function () {
|
||||||
// unload the sidebar. called on sidebar_get and form submit.
|
// unload the sidebar. called on sidebar_get and form submit.
|
||||||
|
editor._hide_original_geometry();
|
||||||
editor._level_control.disable();
|
editor._level_control.disable();
|
||||||
editor._sublevel_control.disable();
|
editor._sublevel_control.disable();
|
||||||
|
|
||||||
|
@ -1687,6 +1688,8 @@ editor = {
|
||||||
editor._add_snap_controls();
|
editor._add_snap_controls();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_add_snap_controls: function() {
|
_add_snap_controls: function() {
|
||||||
|
|
||||||
// add snap to edge toggle
|
// add snap to edge toggle
|
||||||
|
@ -1743,6 +1746,45 @@ editor = {
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
toggle.classList.toggle('active', editor._snap_to_original_enabled);
|
toggle.classList.toggle('active', editor._snap_to_original_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show/hide original geometry
|
||||||
|
if (editor._snap_to_original_enabled) {
|
||||||
|
editor._show_original_geometry();
|
||||||
|
} else {
|
||||||
|
editor._hide_original_geometry();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_show_original_geometry: function() {
|
||||||
|
if (!editor._bounds_layer || editor._original_geometry_layer) return;
|
||||||
|
|
||||||
|
// Create a copy of the original geometry with different styling
|
||||||
|
var originalFeature = editor._bounds_layer.feature;
|
||||||
|
if (!originalFeature) return;
|
||||||
|
|
||||||
|
editor._original_geometry_layer = L.geoJSON(originalFeature, {
|
||||||
|
style: function() {
|
||||||
|
return {
|
||||||
|
stroke: true,
|
||||||
|
color: '#888888',
|
||||||
|
weight: 2,
|
||||||
|
opacity: 0.7,
|
||||||
|
fill: false,
|
||||||
|
dashArray: '5, 5',
|
||||||
|
className: 'original-geometry'
|
||||||
|
};
|
||||||
|
},
|
||||||
|
pointToLayer: editor._point_to_layer
|
||||||
|
});
|
||||||
|
|
||||||
|
editor._original_geometry_layer.addTo(editor.map);
|
||||||
|
},
|
||||||
|
|
||||||
|
_hide_original_geometry: function() {
|
||||||
|
if (editor._original_geometry_layer) {
|
||||||
|
editor.map.removeLayer(editor._original_geometry_layer);
|
||||||
|
editor._original_geometry_layer = null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_handle_snap_during_draw: function(e) {
|
_handle_snap_during_draw: function(e) {
|
||||||
|
@ -1785,6 +1827,7 @@ editor = {
|
||||||
|
|
||||||
// find snap candidates from existing geometries with area-limited infinite extension
|
// find snap candidates from existing geometries with area-limited infinite extension
|
||||||
editor._geometries_layer.eachLayer(function(layer) {
|
editor._geometries_layer.eachLayer(function(layer) {
|
||||||
|
if (layer === editor._bounds_layer && !editor._snap_to_original_enabled) return; //don't snap to original if not toggled.
|
||||||
if (layer === editor._editing_layer) return; // don't snap to self
|
if (layer === editor._editing_layer) return; // don't snap to self
|
||||||
|
|
||||||
// check if layer is within the area limit for infinite extension
|
// check if layer is within the area limit for infinite extension
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue