oxjs/source/UI/js/Map/MapRectangle.js

133 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 10:49:48 +00:00
/*@
Ox.MapRectangle <f> MapRectangle Object
2012-05-31 10:32:54 +00:00
(options) -> <o> MapRectangle Object
2011-05-16 10:49:48 +00:00
options <o> Options object
map <o|null> map
place <o|null> place
@*/
2012-05-31 10:32:54 +00:00
Ox.MapRectangle = function(options) {
2011-04-22 22:03:10 +00:00
options = Ox.extend({
2012-05-28 16:21:00 +00:00
map: null,
place: null
}, options);
2011-04-22 22:03:10 +00:00
2012-12-28 17:00:02 +00:00
var that = this,
themeData = Ox.Theme.getThemeData();
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,
2012-05-26 15:48:19 +00:00
bounds: that.place.bounds
2011-04-22 22:03:10 +00:00
});
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() {
2012-01-17 17:56:26 +00:00
if (
that.map.options('editable')
&& that.place.editable
&& !that.place.editing
) {
2011-04-22 22:03:10 +00:00
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() {
2012-12-28 17:00:02 +00:00
var color = '#' + Ox.toHex(themeData[
that.place.editing
? 'mapPlaceEditingBorder'
: 'mapPlaceSelectedBorder'
]);
2011-04-22 22:03:10 +00:00
that.rectangle.setOptions({
bounds: that.place.bounds,
2011-04-22 22:03:10 +00:00
fillColor: color,
fillOpacity: that.place.editing ? 0.1 : 0,
strokeColor: color,
strokeOpacity: that.place.id[0] == '_' ? 0.5 : 1,
2011-04-22 22:03:10 +00:00
strokeWeight: 2
});
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.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();
2011-11-04 15:54:28 +00:00
Ox.Log('Map', 'MARKERS', that.markers)
2011-04-22 22:03:10 +00:00
Ox.forEach(that.markers, function(marker) {
marker.remove();
});
return that;
2011-04-22 22:03:10 +00:00
};
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-04-22 22:03:10 +00:00
}
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();
});
return that;
2011-04-22 22:03:10 +00:00
};
2011-05-16 10:49:48 +00:00
/*@
update <f> udpate
@*/
2011-04-22 22:03:10 +00:00
that.update = function() {
2011-11-04 15:54:28 +00:00
Ox.Log('Map', 'UPDATE...')
setOptions();
2011-04-22 22:03:10 +00:00
Ox.forEach(that.markers, function(marker) {
marker.update();
});
return that;
2011-04-22 22:03:10 +00:00
}
return that;
2011-11-03 15:42:41 +00:00
2011-04-22 22:03:10 +00:00
};