diff --git a/examples/maps/map_editor/js/example.js b/examples/maps/map_editor/js/example.js index 420a95cb..317c05b3 100644 --- a/examples/maps/map_editor/js/example.js +++ b/examples/maps/map_editor/js/example.js @@ -7,22 +7,19 @@ In this example, we use Ox.MapEditor Ox.load(['UI', 'Geo'], function() { var $storage = Ox.localStorage("map_editor") var places = $storage('places') || [] - var placesAPI = Ox.api(places, { - geo: true, - sort: '-area', - cache: true, - }) var $map = Ox.MapEditor({ addPlace: function(place, callback) { - place = Ox.clone(place) place.id = Ox.encodeBase26((places.length ? Ox.max(places.map(p => Ox.decodeBase26(p.id))) : 0) + 1) - place.editable = true console.log("addPlace", place.id, place) places.push(place) $storage("places", places) - placesAPI.update(places) + $map.options({ + places: Ox.api(places, { + geo: true, + sort: '-area' + }) + }) setTimeout(() => { - Ox.Request.clearCache(); callback({ status: { code: 200 @@ -32,7 +29,6 @@ Ox.load(['UI', 'Geo'], function() { }, 200) }, editPlace: function(place, callback) { - place = Ox.clone(place) places.forEach(p => { if (p.id == place.id) { Object.assign(p, place); @@ -40,16 +36,12 @@ Ox.load(['UI', 'Geo'], function() { } }) $storage("places", places) - placesAPI.update(places) - setTimeout(() => { - Ox.Request.clearCache(); - callback({ - status: { - code: 200 - }, - data: place - }) - }, 200) + callback({ + status: { + code: 200 + }, + data: place + }) }, getMatches: function(names, callback) { console.log("getMatches", names) @@ -59,21 +51,28 @@ Ox.load(['UI', 'Geo'], function() { height: 800, mode: 'add', // 'define', names: null, - places: placesAPI, + places: Ox.api(places, { + geo: true, + sort: '-area' + }), removePlace: function(place, callback) { console.log("removePlace", place.id, places) places = places.filter(p => { return p.id != place.id }) console.log("new places", places) $storage("places", places) - placesAPI.update(places) + $map.options({ + places: Ox.api(places, { + geo: true, + sort: '-area' + }) + }) setTimeout(() => { - Ox.Request.clearCache(); callback({ status: { code: 200 }, }) - }, 200) + }, 100) }, selected: '', showControls: false, diff --git a/source/UI/js/Map/MapEditor.js b/source/UI/js/Map/MapEditor.js index a37be8e5..e6fc09ea 100644 --- a/source/UI/js/Map/MapEditor.js +++ b/source/UI/js/Map/MapEditor.js @@ -49,7 +49,7 @@ Ox.MapEditor = function(options, self) { places: function() { self.isAsync = Ox.isFunction(self.options.places); self.$list.options({ - items: self.isAsync ? self.options.places : Ox.clone(self.options.places) + items: Ox.clone(self.options.places) }) self.$map.options({ places: self.options.places @@ -337,7 +337,7 @@ Ox.MapEditor = function(options, self) { columns: self.columns, columnsRemovable: true, columnsVisible: true, - items: self.isAsync ? self.options.places : Ox.clone(self.options.places), + items: Ox.clone(self.options.places), //items: self.options.places, // area needed for icon, geoname needed for flag keys: ['area', 'geoname', 'matches'],