2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-16 10:49:48 +00:00
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.MapRectangle <f> MapRectangle Object
|
|
|
|
() -> <f> MapRectangle Object
|
|
|
|
(options) -> <f> MapRectangle Object
|
|
|
|
(options, self) -> <f> MapRectangle Object
|
|
|
|
options <o> Options object
|
|
|
|
map <o|null> map
|
|
|
|
place <o|null> place
|
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.MapRectangle = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
var that = this;
|
|
|
|
options = Ox.extend({
|
2011-04-22 22:03:10 +00:00
|
|
|
map: null,
|
|
|
|
place: null
|
2011-06-19 17:48:32 +00:00
|
|
|
}, options);
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
Ox.forEach(options, function(val, key) {
|
|
|
|
that[key] = val;
|
|
|
|
});
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
rectangle <f> google.maps.Rectangle
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.rectangle = new google.maps.Rectangle({
|
|
|
|
clickable: true,
|
|
|
|
bounds: that.place.bounds,
|
|
|
|
});
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
markers <a> array of markers
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.markers = Ox.map(that.place.points, function(point, position) {
|
2011-06-20 12:53:00 +00:00
|
|
|
return new Ox.MapRectangleMarker({
|
2011-04-22 22:03:10 +00:00
|
|
|
map: that.map,
|
|
|
|
place: that.place,
|
|
|
|
position: position
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
setOptions();
|
|
|
|
|
|
|
|
function click() {
|
|
|
|
if (that.map.options('editable') && that.place.editable && !that.place.editing) {
|
|
|
|
that.place.edit();
|
|
|
|
} else if (that.map.getKey() == 'meta') {
|
|
|
|
that.place.submit();
|
|
|
|
} else if (that.map.getKey() == 'shift') {
|
|
|
|
that.map.zoomToPlace();
|
|
|
|
} else {
|
|
|
|
that.map.panToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setOptions() {
|
|
|
|
var color = that.place.editing ? '#8080FF' : '#FFFFFF';
|
|
|
|
that.rectangle.setOptions({
|
|
|
|
fillColor: color,
|
|
|
|
fillOpacity: that.place.editing ? 0.1 : 0,
|
|
|
|
strokeColor: color,
|
|
|
|
strokeOpacity: 1,
|
|
|
|
strokeWeight: 2
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
add <f> add
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.add = function() {
|
|
|
|
that.rectangle.setMap(that.map.map);
|
|
|
|
google.maps.event.addListener(that.rectangle, 'click', click);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
deselect <f> deselect
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.deselect = function() {
|
|
|
|
setOptions();
|
|
|
|
Ox.print('MARKERS', that.markers)
|
|
|
|
Ox.forEach(that.markers, function(marker) {
|
|
|
|
marker.remove();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
remove <f> remove
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.remove = function() {
|
|
|
|
that.rectangle.setMap(null);
|
|
|
|
google.maps.event.clearListeners(that.rectangle);
|
|
|
|
return that
|
|
|
|
}
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
select <f> select
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.select = function() {
|
|
|
|
setOptions();
|
|
|
|
Ox.forEach(that.markers, function(marker) {
|
|
|
|
marker.add();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
update <f> udpate
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.update = function() {
|
2011-06-01 13:53:09 +00:00
|
|
|
Ox.print('UPDATE...')
|
2011-04-22 22:03:10 +00:00
|
|
|
that.rectangle.setOptions({
|
|
|
|
bounds: that.place.bounds
|
|
|
|
});
|
|
|
|
Ox.forEach(that.markers, function(marker) {
|
|
|
|
marker.update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
2011-11-03 15:42:41 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|