oxjs/source/UI/js/Map/MapPlace.js

219 lines
5.2 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.MapPlace <f> MapPlace Object
2012-05-31 10:32:54 +00:00
(options) -> <o> MapPlace Object
2011-05-16 10:49:48 +00:00
options <o> Options object
east <n|0>
editing <b|false>
geoname <s|''>
map <o|null>
markerColor <a|[255> 0> 0]>
markerSize <n|16>
name <s|''>
north <n|0>
selected <b|false>
south <n|0>
2011-06-01 08:39:33 +00:00
type <s|''>
2011-05-16 10:49:48 +00:00
visible <b|false>
2011-11-03 15:42:41 +00:00
west <n|0>
2011-05-16 10:49:48 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.MapPlace = function(options) {
options = Ox.extend({
east: 0,
editing: false,
geoname: '',
map: null,
name: '',
north: 0,
selected: false,
south: 0,
2011-06-01 08:39:33 +00:00
type: '',
2011-04-22 22:03:10 +00:00
visible: false,
2011-11-03 15:42:41 +00:00
west: 0
2011-04-22 22:03:10 +00:00
}, options);
var that = this;
Ox.forEach(options, function(val, key) {
that[key] = val;
});
update();
2011-06-01 14:27:25 +00:00
function update(updateMarker) {
2011-04-22 22:03:10 +00:00
that.points = {
ne: new google.maps.LatLng(that.north, that.east),
sw: new google.maps.LatLng(that.south, that.west)
};
that.bounds = new google.maps.LatLngBounds(that.points.sw, that.points.ne);
that.center = that.bounds.getCenter();
that.lat = that.center.lat();
that.lng = that.center.lng();
2013-06-02 20:19:36 +00:00
Ox.extend(that.points, {
2011-04-22 22:03:10 +00:00
e: new google.maps.LatLng(that.lat, that.east),
s: new google.maps.LatLng(that.south, that.lng),
se: new google.maps.LatLng(that.south, that.east),
n: new google.maps.LatLng(that.north, that.lng),
nw: new google.maps.LatLng(that.north, that.west),
2012-05-26 15:48:19 +00:00
w: new google.maps.LatLng(that.lat, that.west)
2011-04-22 22:03:10 +00:00
});
// fixme: use bounds.toSpan()
2012-01-17 17:56:26 +00:00
that.sizeNorthSouth = (that.north - that.south)
* Ox.EARTH_CIRCUMFERENCE / 360;
that.sizeEastWest = (that.east + (that.west > that.east ? 360 : 0) - that.west)
* Ox.getMetersPerDegree(that.lat);
2011-05-24 11:43:27 +00:00
that.area = Ox.getArea(
2011-04-22 22:03:10 +00:00
{lat: that.south, lng: that.west},
{lat: that.north, lng: that.east}
);
if (!that.marker) {
that.marker = new Ox.MapMarker({
map: that.map,
place: that
2011-04-22 22:03:10 +00:00
});
that.rectangle = new Ox.MapRectangle({
map: that.map,
place: that
});
2011-06-01 14:27:25 +00:00
} else if (updateMarker) {
2011-06-01 14:03:02 +00:00
that.marker.update();
2011-06-01 14:42:45 +00:00
that.rectangle.update();
2011-04-22 22:03:10 +00:00
}
}
function editable() {
return that.map.options('editable') && that.editable;
}
2011-05-16 10:49:48 +00:00
/*@
add <f> add
@*/
2011-04-22 22:03:10 +00:00
that.add = function() {
that.visible = true;
that.marker.add();
return that;
};
2011-05-16 10:49:48 +00:00
/*@
cancel <f> cancel
@*/
2011-04-22 22:03:10 +00:00
that.cancel = function() {
if (editable()) {
that.undo();
that.editing = false;
that.marker.update();
that.rectangle.deselect();
}
return that;
};
2011-05-16 10:49:48 +00:00
/*@
crossesDateline <f> crossesDateline
@*/
2011-04-22 22:03:10 +00:00
that.crossesDateline = function() {
return that.west > that.east;
}
2011-05-16 10:49:48 +00:00
/*@
deselect <f> dselect
@*/
2011-04-22 22:03:10 +00:00
that.deselect = function() {
that.editing && that.submit();
that.selected = false;
that.marker.update();
that.rectangle.remove();
return that;
};
2011-05-16 10:49:48 +00:00
/*@
edit <f> edit
@*/
2011-04-22 22:03:10 +00:00
that.edit = function() {
if (editable()) {
that.editing = true;
that.original = {
south: that.south,
west: that.west,
north: that.north,
east: that.east
};
that.marker.edit();
that.rectangle.select();
}
return that;
2011-06-01 08:39:33 +00:00
};
// fixme: make this an Ox.Element to get options handling for free?
that.options = function(options) {
2011-06-01 14:04:50 +00:00
options = Ox.makeObject(arguments);
2011-06-01 13:51:35 +00:00
Ox.forEach(options, function(value, key) {
2011-06-01 14:34:26 +00:00
that[key] = value;
2011-06-01 08:39:33 +00:00
});
2011-06-01 14:27:25 +00:00
update(true);
2011-06-01 08:39:33 +00:00
};
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.editing && that.submit();
that.selected && that.deselect();
that.visible = false;
that.marker.remove();
return that;
};
2011-05-16 10:49:48 +00:00
/*@
select <f> select
@*/
2011-04-22 22:03:10 +00:00
that.select = function() {
that.selected = true;
!that.visible && that.add();
that.marker.update();
that.rectangle.add();
return that;
};
2011-05-16 10:49:48 +00:00
/*@
submit <f> submit
@*/
2011-04-22 22:03:10 +00:00
that.submit = function() {
if (editable()) {
that.editing = false;
that.marker.update();
that.rectangle.deselect();
}
return that;
};
2011-05-16 10:49:48 +00:00
/*@
update <f> update
@*/
2011-06-01 14:27:25 +00:00
that.update = function(updateMarker) {
update(updateMarker);
2011-05-22 12:39:57 +00:00
that.map.triggerEvent('changeplace', that);
2011-04-22 22:03:10 +00:00
return that;
};
2011-11-03 15:42:41 +00:00
2011-05-16 10:49:48 +00:00
/*@
undo <f> undo
@*/
2011-04-22 22:03:10 +00:00
that.undo = function() {
if (editable()) {
Ox.forEach(that.original, function(v, k) {
that[k] = v;
});
that.update();
that.marker.update();
that.rectangle.update();
}
return that;
};
return that;
2011-05-16 10:49:48 +00:00
};