From 8fc5297f39bcbdf511b88b66d3a0937076b1dce8 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Sat, 9 Aug 2025 17:11:18 +0200 Subject: [PATCH] fix marker duplication bug when editing a newly added place --- source/UI/js/Map/Map.js | 19 ++++++++++++++++++- source/UI/js/Map/MapMarker.js | 2 ++ source/UI/js/Map/MapPlace.js | 7 +++++++ source/UI/js/Map/MapRectangle.js | 7 +++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/source/UI/js/Map/Map.js b/source/UI/js/Map/Map.js index aeb633f8..1a3d785d 100644 --- a/source/UI/js/Map/Map.js +++ b/source/UI/js/Map/Map.js @@ -123,6 +123,16 @@ Ox.Map = function(options, self) { that.resizeMap(); }, places: function() { + console.log('MAP OPTIONS.PLACES UPDATE - Processing places array, count:', self.options.places ? self.options.places.length : 0); + console.trace('MAP OPTIONS.PLACES UPDATE - Stack trace'); + + // Prevent rebuilding places while editing to avoid breaking references + var editingPlace = getSelectedPlace(); + if (editingPlace && editingPlace.editing) { + console.log('MAP OPTIONS.PLACES UPDATE - Skipping rebuild because place is being edited:', editingPlace.id); + return; + } + if (Ox.isArray(self.options.places)) { self.options.places.forEach(function(place) { if (Ox.isUndefined(place.id)) { @@ -248,6 +258,8 @@ Ox.Map = function(options, self) { }); //FIXME: duplicated in update + console.log('MAP INIT - Processing places array (duplicated code), count:', self.options.places ? self.options.places.length : 0); + console.trace('MAP INIT - Stack trace'); if (Ox.isArray(self.options.places)) { self.options.places.forEach(function(place) { if (Ox.isUndefined(place.id)) { @@ -1727,7 +1739,12 @@ Ox.Map = function(options, self) { that.value = function(id, key, value) { // fixme: should be like the corresponding List/TableList/etc value function Ox.Log('Map', 'Map.value', id, key, value); - getPlaceById(id).options(key, value); + var place = getPlaceById(id); + if (!place) { + console.error('Map.value - place not found for id:', id, 'Available places:', Object.keys(self.options.places || {})); + return; + } + place.options(key, value); if (id == self.options.selected) { if (key == 'name') { self.$placeControls.name.options({title: value}); diff --git a/source/UI/js/Map/MapMarker.js b/source/UI/js/Map/MapMarker.js index b9eabc1f..caec8001 100644 --- a/source/UI/js/Map/MapMarker.js +++ b/source/UI/js/Map/MapMarker.js @@ -306,7 +306,9 @@ Ox.MapMarker = function(options) { () -> edit marker, returns MapMarker @*/ that.edit = function() { + console.log('MAPMARKER.EDIT - before setOptions, marker on map?', that.marker._map !== null); setOptions(); + console.log('MAPMARKER.EDIT - after setOptions, marker on map?', that.marker._map !== null); that.marker.on('dragstart', dragstart); that.marker.on('drag', drag); that.marker.on('dragend', dragend); diff --git a/source/UI/js/Map/MapPlace.js b/source/UI/js/Map/MapPlace.js index a749f13c..94140084 100644 --- a/source/UI/js/Map/MapPlace.js +++ b/source/UI/js/Map/MapPlace.js @@ -41,6 +41,13 @@ Ox.MapPlace = function(options) { Ox.forEach(options, function(val, key) { that[key] = val; }); + + // Ensure editable is set for existing places that might not have this property + if (that.editable === undefined) { + that.editable = true; + } + + console.log('MAPPLACE CONSTRUCTOR - Creating place with ID:', that.id, 'name:', that.name); update(); diff --git a/source/UI/js/Map/MapRectangle.js b/source/UI/js/Map/MapRectangle.js index 387f0d89..8a7e7adf 100644 --- a/source/UI/js/Map/MapRectangle.js +++ b/source/UI/js/Map/MapRectangle.js @@ -225,11 +225,18 @@ Ox.MapRectangle = function(options) { setOptions(); function click(e) { + console.log('RECTANGLE CLICK DEBUG:'); + console.log('- map.editable:', that.map.options('editable')); + console.log('- place.editable:', that.place.editable); + console.log('- place.editing:', that.place.editing); + console.log('- place object:', that.place); + if ( that.map.options('editable') && that.place.editable && !that.place.editing ) { + console.log('- Calling place.edit()'); that.place.edit(); } else if (that.map.getKey() == 'meta') { that.place.submit();