diff --git a/examples/maps/map_editor/js/example.js b/examples/maps/map_editor/js/example.js index e9e9e10d..e4a6f93b 100644 --- a/examples/maps/map_editor/js/example.js +++ b/examples/maps/map_editor/js/example.js @@ -5,43 +5,12 @@ In this example, we use Ox.MapEditor 'use strict'; Ox.load(['UI', 'Geo'], function() { - var $storage = Ox.localStorage("map_editor") - var places = $storage('places') || [] var $map = Ox.MapEditor({ addPlace: function(place, callback) { console.log("addPlace", place) - place.id = Ox.encodeBase26(Ox.uid()) - places.push(place) - $storage("places", places) - $map.options({ - places: Ox.api(places, { - geo: true, - sort: '-area' - }) - }) - setTimeout(() => { - callback({ - status: { - code: 200 - }, - data: place - }) - }, 200) }, editPlace: function(place, callback) { - places.forEach(p => { - if (p.id == place.id) { - Object.assign(p, place); - place = p - } - }) - $storage("places", places) - callback({ - status: { - code: 200 - }, - data: place - }) + console.log("editPlace", place) }, getMatches: function(names, callback) { console.log("getMatches", names) @@ -51,28 +20,9 @@ Ox.load(['UI', 'Geo'], function() { height: 800, mode: 'add', // 'define', names: null, - places: Ox.api(places, { - geo: true, - sort: '-area' - }), + places: [], 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) - $map.options({ - places: Ox.api(places, { - geo: true, - sort: '-area' - }) - }) - setTimeout(() => { - callback({ - status: { - code: 200 - }, - }) - }, 100) + console.log("removePlace", place) }, selected: '', showControls: false, diff --git a/source/UI/js/Map/Map.js b/source/UI/js/Map/Map.js index 47022935..7ba855a1 100644 --- a/source/UI/js/Map/Map.js +++ b/source/UI/js/Map/Map.js @@ -621,6 +621,8 @@ Ox.Map = function(options, self) { } function clickMap(event) { + console.log("not this one", event) + return var place = getSelectedPlace(); if (self.options.clickable/* && !editing()*/) { getPlaceByLatLng(event.lngLat, self.map.getBounds(), function(place) { @@ -716,7 +718,6 @@ Ox.Map = function(options, self) { callback = point; point = self.map.getCenter(); } - // fixme, why is getMaxZoom off by one? let maxZoom = self.map.getMaxZoom() setTimeout(() => { callback(maxZoom) diff --git a/source/UI/js/Map/MapEditor.js b/source/UI/js/Map/MapEditor.js index e6fc09ea..64b36988 100644 --- a/source/UI/js/Map/MapEditor.js +++ b/source/UI/js/Map/MapEditor.js @@ -46,15 +46,6 @@ Ox.MapEditor = function(options, self) { self.$list.size(); self.$map.resizeMap(); }, - places: function() { - self.isAsync = Ox.isFunction(self.options.places); - self.$list.options({ - items: Ox.clone(self.options.places) - }) - self.$map.options({ - places: self.options.places - }) - }, selected: function() { self.$list.options({selected: self.options.selected}); }, diff --git a/source/UI/js/Map/MapRectangle.js b/source/UI/js/Map/MapRectangle.js index c80c8b1d..57c23f94 100644 --- a/source/UI/js/Map/MapRectangle.js +++ b/source/UI/js/Map/MapRectangle.js @@ -22,25 +22,23 @@ class MapLibreRectangle { id: this.id } }; - var sourceId = `${this.id}-rectangles` - this.source = this.map.getSource(sourceId) + this.source = this.map.getSource('rectangles') if (!this.source) { - this.map.addSource(sourceId, { + this.map.addSource('rectangles', { type: 'geojson', data: { type: 'FeatureCollection', features: [] } }); - this.source = this.map.getSource(sourceId) + this.source = this.map.getSource('rectangles') // Add fill layer - var layerId = `${this.id}-fill` - if (!this.map.getLayer(layerId)) { + if (!this.map.getLayer('rectangles-fill')) { this.map.addLayer({ - id: layerId, + id: 'rectangles-fill', type: 'fill', - source: sourceId, + source: 'rectangles', paint: { 'fill-color': '#088', 'fill-opacity': 0.3 @@ -49,12 +47,11 @@ class MapLibreRectangle { } // Add outline layer - var layerId = `${this.id}-outline` - if (!this.map.getLayer(layerId)) { + if (!this.map.getLayer('rectangles-outline')) { this.map.addLayer({ - id: layerId, + id: 'rectangles-outline', type: 'line', - source: sourceId, + source: 'rectangles', paint: { 'line-color': '#000', 'line-width': 2 @@ -143,7 +140,7 @@ class MapLibreRectangle { }); } _enableClicking() { - this.map.on('click', `${this.id}-fill`, e => { + this.map.on('click', `rectangles-fill`, e => { console.log('click', e) if (this.onclick) { e.preventDefault() diff --git a/source/UI/js/Map/MapRectangleMarker.js b/source/UI/js/Map/MapRectangleMarker.js index 8bf7cbb3..b123ece6 100644 --- a/source/UI/js/Map/MapRectangleMarker.js +++ b/source/UI/js/Map/MapRectangleMarker.js @@ -103,9 +103,12 @@ Ox.MapRectangleMarker = function(options) { @*/ that.add = function() { that.marker.addTo(that.map.map); - that.marker.on('dragstart', dragstart); - that.marker.on('drag', drag); - that.marker.on('dragend', dragend); + console.log("add marker, fix events") + /* + google.maps.event.addListener(that.marker, 'dragstart', dragstart); + google.maps.event.addListener(that.marker, 'drag', drag); + google.maps.event.addListener(that.marker, 'dragend', dragend); + */ }; /*@ @@ -121,7 +124,7 @@ Ox.MapRectangleMarker = function(options) { update update @*/ that.update = function() { - var marker = new maplibregl.Marker({ + marker = new maplibregl.Marker({ cursor: that.position + '-resize', draggable: true, element: Ox.MapMarkerImage({