diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index a4448da0..3919f296 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -163,6 +163,7 @@ editor = { }, _sidebar_unload: function () { // unload the sidebar. called on sidebar_get and form submit. + editor._hide_original_geometry(); editor._level_control.disable(); editor._sublevel_control.disable(); @@ -1687,6 +1688,8 @@ editor = { editor._add_snap_controls(); }, + + _add_snap_controls: function() { // add snap to edge toggle @@ -1743,6 +1746,45 @@ editor = { if (toggle) { 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) { @@ -1785,6 +1827,7 @@ editor = { // find snap candidates from existing geometries with area-limited infinite extension 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 // check if layer is within the area limit for infinite extension