2011-11-05 17:46:53 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-05-16 12:49:48 +02:00
|
|
|
/*@
|
|
|
|
|
Ox.MapRectangleMarker <f> MapRectangleMarker Object
|
2012-05-31 12:32:54 +02:00
|
|
|
(options) -> <o> MapRectangleMarker Object
|
2011-05-16 12:49:48 +02:00
|
|
|
options <o> Options object
|
|
|
|
|
map <o|null> map
|
|
|
|
|
place <o|null> place
|
|
|
|
|
position <s|''>
|
|
|
|
|
@*/
|
|
|
|
|
|
2012-05-31 12:32:54 +02:00
|
|
|
Ox.MapRectangleMarker = function(options) {
|
2011-04-23 00:03:10 +02:00
|
|
|
|
2011-04-27 21:24:33 +02:00
|
|
|
options = Ox.extend({
|
|
|
|
|
map: null,
|
|
|
|
|
place: null,
|
|
|
|
|
position: ''
|
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
|
|
var that = this;
|
2011-04-23 00:03:10 +02:00
|
|
|
|
|
|
|
|
Ox.forEach(options, function(val, key) {
|
|
|
|
|
that[key] = val;
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-05 18:50:06 +02:00
|
|
|
/*
|
2011-04-23 00:03:10 +02:00
|
|
|
that.markerImage = new google.maps.MarkerImage
|
|
|
|
|
that.marker = new google.maps.Marker({
|
|
|
|
|
cursor: that.position + '-resize',
|
|
|
|
|
draggable: true,
|
2011-04-27 21:24:33 +02:00
|
|
|
icon: Ox.MapMarkerImage({
|
|
|
|
|
mode: 'editing',
|
2012-03-07 13:28:45 +00:00
|
|
|
rectangle: true,
|
|
|
|
|
type: that.place.id[0] == '_' ? 'result' : 'place'
|
2011-04-27 21:24:33 +02:00
|
|
|
}),
|
2011-04-23 00:03:10 +02:00
|
|
|
position: that.place.points[that.position],
|
|
|
|
|
raiseOnDrag: false
|
|
|
|
|
});
|
2025-08-05 18:50:06 +02:00
|
|
|
*/
|
2025-08-09 14:15:54 +02:00
|
|
|
// Create a simple DOM element for the corner handle
|
|
|
|
|
var element = document.createElement('div');
|
|
|
|
|
element.style.width = '8px';
|
|
|
|
|
element.style.height = '8px';
|
|
|
|
|
element.style.backgroundColor = 'white';
|
|
|
|
|
element.style.border = '2px solid black';
|
|
|
|
|
element.style.borderRadius = '2px';
|
|
|
|
|
element.style.cursor = that.position + '-resize';
|
|
|
|
|
element.style.boxSizing = 'border-box';
|
|
|
|
|
|
2025-08-05 18:50:06 +02:00
|
|
|
that.marker = new maplibregl.Marker({
|
|
|
|
|
draggable: true,
|
2025-08-09 14:15:54 +02:00
|
|
|
element: element,
|
2025-08-05 18:50:06 +02:00
|
|
|
});
|
2025-08-06 21:50:00 +02:00
|
|
|
that.marker.setLngLat(that.place.points[that.position])
|
2011-04-23 00:03:10 +02:00
|
|
|
|
|
|
|
|
function dragstart(e) {
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.addClass('OxDragging');
|
2025-08-09 14:15:54 +02:00
|
|
|
// In MapLibre GL, get position from marker directly
|
|
|
|
|
var lngLat = that.marker.getLngLat();
|
2011-04-23 00:03:10 +02:00
|
|
|
that.drag = {
|
2025-08-09 14:15:54 +02:00
|
|
|
lat: lngLat.lat,
|
|
|
|
|
lng: lngLat.lng
|
2011-04-23 00:03:10 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function drag(e) {
|
|
|
|
|
// fixme: implement shift+drag (center stays the same)
|
2025-08-09 14:15:54 +02:00
|
|
|
// In MapLibre GL, get current position from marker directly
|
|
|
|
|
var lngLat = that.marker.getLngLat();
|
|
|
|
|
var lat = Ox.limit(lngLat.lat, Ox.MIN_LATITUDE, Ox.MAX_LATITUDE),
|
|
|
|
|
lng = lngLat.lng;
|
2011-04-23 00:03:10 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2011-11-04 16:54:28 +01:00
|
|
|
//Ox.Log('Map', 'west', that.place.west, 'east', that.place.east);
|
|
|
|
|
//Ox.Log('Map', 'south', that.place.south, 'north', that.place.north);
|
2011-04-23 00:03:10 +02:00
|
|
|
that.place.update();
|
|
|
|
|
that.place.marker.update();
|
|
|
|
|
that.place.rectangle.update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dragend(e) {
|
|
|
|
|
var south;
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.removeClass('OxDragging');
|
2011-04-23 00:03:10 +02:00
|
|
|
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();
|
|
|
|
|
}
|
2011-05-30 09:21:11 +02:00
|
|
|
that.map.triggerEvent('changeplaceend', that.place);
|
2011-04-23 00:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-16 12:49:48 +02:00
|
|
|
/*@
|
|
|
|
|
add <f> add
|
|
|
|
|
@*/
|
2011-04-23 00:03:10 +02:00
|
|
|
that.add = function() {
|
2025-08-06 21:50:00 +02:00
|
|
|
that.marker.addTo(that.map.map);
|
2025-08-06 23:31:07 +02:00
|
|
|
that.marker.on('dragstart', dragstart);
|
|
|
|
|
that.marker.on('drag', drag);
|
|
|
|
|
that.marker.on('dragend', dragend);
|
2025-08-09 14:15:54 +02:00
|
|
|
return that;
|
2011-04-23 00:03:10 +02:00
|
|
|
};
|
|
|
|
|
|
2011-05-16 12:49:48 +02:00
|
|
|
/*@
|
|
|
|
|
remove <f> remove
|
|
|
|
|
@*/
|
2011-04-23 00:03:10 +02:00
|
|
|
that.remove = function() {
|
2025-08-09 14:15:54 +02:00
|
|
|
// Clean up MapLibre events
|
|
|
|
|
that.marker.off('dragstart');
|
|
|
|
|
that.marker.off('drag');
|
|
|
|
|
that.marker.off('dragend');
|
|
|
|
|
// Remove marker from map
|
2025-08-05 18:50:06 +02:00
|
|
|
that.marker.remove();
|
2025-08-09 14:15:54 +02:00
|
|
|
return that;
|
2011-04-23 00:03:10 +02:00
|
|
|
};
|
|
|
|
|
|
2011-05-16 12:49:48 +02:00
|
|
|
/*@
|
|
|
|
|
update <f> update
|
|
|
|
|
@*/
|
2011-04-23 00:03:10 +02:00
|
|
|
that.update = function() {
|
2025-08-09 14:15:54 +02:00
|
|
|
// Just update position - visual stays the same during editing
|
|
|
|
|
that.marker.setLngLat(that.place.points[that.position]);
|
|
|
|
|
return that;
|
2011-04-23 00:03:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
|
|
};
|