'use strict'; /*@ Ox.MapRectangleMarker MapRectangleMarker Object (options) -> MapRectangleMarker Object options Options object map map place place position @*/ Ox.MapRectangleMarker = function(options) { options = Ox.extend({ map: null, place: null, position: '' }, options); var that = this; Ox.forEach(options, function(val, key) { that[key] = val; }); /* that.markerImage = new google.maps.MarkerImage that.marker = new google.maps.Marker({ cursor: that.position + '-resize', draggable: true, icon: Ox.MapMarkerImage({ mode: 'editing', rectangle: true, type: that.place.id[0] == '_' ? 'result' : 'place' }), position: that.place.points[that.position], raiseOnDrag: false }); */ that.marker = new maplibregl.Marker({ cursor: that.position + '-resize', draggable: true, element: Ox.MapMarkerImage({ mode: 'editing', rectangle: true, type: that.place.id[0] == '_' ? 'result' : 'place' }), }); that.marker.setLngLat(that.place.points[that.position]) function dragstart(e) { Ox.$body.addClass('OxDragging'); that.drag = { lat: e.lngLat.lat, lng: e.lngLat.lng }; } function drag(e) { // fixme: implement shift+drag (center stays the same) Ox.Log('Map', e.pixel.x, e.pixel.y) var lat = Ox.limit(e.lngLat.lat, Ox.MIN_LATITUDE, Ox.MAX_LATITUDE), lng = e.lngLat.lng; that.drag = { lat: lat, lng: lng }; if (that.position.indexOf('s') > -1) { that.place.south = lat; } if (that.position.indexOf('n') > -1) { that.place.north = lat; } if (that.position.indexOf('w') > -1) { that.place.west = lng; } if (that.position.indexOf('e') > -1) { that.place.east = lng; } //Ox.Log('Map', 'west', that.place.west, 'east', that.place.east); //Ox.Log('Map', 'south', that.place.south, 'north', that.place.north); that.place.update(); that.place.marker.update(); that.place.rectangle.update(); } function dragend(e) { var south; Ox.$body.removeClass('OxDragging'); if (that.place.south > that.place.north) { south = that.place.south; that.place.south = that.place.north; that.place.north = south; that.place.update(); that.place.marker.update(); that.place.rectangle.update(); } that.map.triggerEvent('changeplaceend', that.place); } /*@ add add @*/ that.add = function() { that.marker.addTo(that.map.map); that.marker.on('dragstart', dragstart); that.marker.on('drag', drag); that.marker.on('dragend', dragend); }; /*@ remove remove @*/ that.remove = function() { that.marker.remove(); console.log("remove marker, fix events") //google.maps.event.clearListeners(that.marker); }; /*@ update update @*/ that.update = function() { var marker = new maplibregl.Marker({ cursor: that.position + '-resize', draggable: true, element: Ox.MapMarkerImage({ mode: 'editing', rectangle: true, type: that.place.id[0] == '_' ? 'result' : 'place' }), }); marker.setLngLat(that.place.points[that.position]) that.marker.remove() that.marker = marker }; return that; };