oxjs/source/Ox.UI/js/Map/MapRectangleMarker.js

122 lines
3.2 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 10:49:48 +00:00
/*@
Ox.MapRectangleMarker <f> MapRectangleMarker Object
2012-05-31 10:32:54 +00:00
(options) -> <o> MapRectangleMarker Object
2011-05-16 10:49:48 +00:00
options <o> Options object
map <o|null> map
place <o|null> place
position <s|''>
@*/
2012-05-31 10:32:54 +00:00
Ox.MapRectangleMarker = function(options) {
2011-04-22 22:03:10 +00:00
options = Ox.extend({
map: null,
place: null,
position: ''
}, options);
var that = this;
2011-04-22 22:03:10 +00:00
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'
}),
2011-04-22 22:03:10 +00:00
position: that.place.points[that.position],
raiseOnDrag: false
});
function dragstart(e) {
that.drag = {
lat: e.latLng.lat(),
lng: e.latLng.lng()
};
}
function drag(e) {
// fixme: implement shift+drag (center stays the same)
2011-11-04 15:54:28 +00:00
Ox.Log('Map', e.pixel.x, e.pixel.y)
2011-04-22 22:03:10 +00:00
var lat = Ox.limit(e.latLng.lat(), Ox.MIN_LATITUDE, Ox.MAX_LATITUDE),
lng = e.latLng.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;
}
2011-11-04 15:54:28 +00: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-22 22:03:10 +00:00
that.place.update();
that.place.marker.update();
that.place.rectangle.update();
}
function dragend(e) {
var south;
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);
2011-04-22 22:03:10 +00:00
}
2011-05-16 10:49:48 +00:00
/*@
add <f> add
@*/
2011-04-22 22:03:10 +00:00
that.add = function() {
that.marker.setMap(that.map.map);
google.maps.event.addListener(that.marker, 'dragstart', dragstart);
google.maps.event.addListener(that.marker, 'drag', drag);
google.maps.event.addListener(that.marker, 'dragend', dragend);
};
2011-05-16 10:49:48 +00:00
/*@
remove <f> remove
@*/
2011-04-22 22:03:10 +00:00
that.remove = function() {
that.marker.setMap(null);
google.maps.event.clearListeners(that.marker);
};
2011-05-16 10:49:48 +00:00
/*@
update <f> update
@*/
2011-04-22 22:03:10 +00:00
that.update = function() {
that.marker.setOptions({
icon: Ox.MapMarkerImage({
mode: 'editing',
rectangle: true,
type: that.place.id[0] == '_' ? 'result' : 'place'
}),
2012-05-26 15:48:19 +00:00
position: that.place.points[that.position]
2011-04-22 22:03:10 +00:00
});
};
return that;
};