This commit is contained in:
rlx 2011-03-04 16:24:54 +00:00
parent 122cc33cb5
commit 9067e96499
2 changed files with 141 additions and 35 deletions

View file

@ -1870,6 +1870,14 @@ Geo functions
return {lat: lat, lng: lng}; return {lat: lat, lng: lng};
}; };
Ox.getDegreesPerMeter = function(lat) {
/*
>>> Ox.EARTH_CIRCUMFERENCE = 360 / Ox.getDegreesPerMeter(0)
true
*/
return 360 / Ox.EARTH_CIRCUMFERENCE / Math.cos(lat * Math.PI / 180);
};
Ox.getDistance = function(point0, point1) { Ox.getDistance = function(point0, point1) {
/* /*
>>> Ox.EARTH_CIRCUMFERENCE == Ox.getDistance({lat: -45, lng: -90}, {lat: 45, lng: 90}) * 2 >>> Ox.EARTH_CIRCUMFERENCE == Ox.getDistance({lat: -45, lng: -90}, {lat: 45, lng: 90}) * 2

View file

@ -8789,11 +8789,11 @@ requires
if (self.options.data) { if (self.options.data) {
self.options.items = []; self.options.items = [];
Ox.print('d', self.options.data, 'i', self.options.items) //Ox.print('d', self.options.data, 'i', self.options.items)
Ox.forEach(self.options.data, function(value, key) { Ox.forEach(self.options.data, function(value, key) {
self.options.items.push(parseData(key, value)); self.options.items.push(parseData(key, value));
}); });
Ox.print('d', self.options.data, 'i', self.options.items) //Ox.print('d', self.options.data, 'i', self.options.items)
} }
that.$element = new Ox.List({ that.$element = new Ox.List({
@ -8885,7 +8885,7 @@ requires
} }
function parseData(key, value) { function parseData(key, value) {
Ox.print('parseData', key, value) //Ox.print('parseData', key, value)
var ret = { var ret = {
id: key, id: key,
title: key.toString().split('.').pop() title: key.toString().split('.').pop()
@ -8952,6 +8952,12 @@ requires
}); });
} }
self.onChange = function(key, value) {
if (key == 'data') {
}
};
return that; return that;
}; };
@ -9221,7 +9227,7 @@ requires
resize: function() { resize: function() {
self.$map.resizeMap(); self.$map.resizeMap();
}, },
select: selectPlace selectplace: selectPlace
}); });
that.$element.replaceWith( that.$element.replaceWith(
that.$element = new Ox.SplitPanel({ that.$element = new Ox.SplitPanel({
@ -9691,7 +9697,8 @@ requires
function parseGeodata(data) { function parseGeodata(data) {
var bounds = data.geometry.bounds || data.geometry.viewport, var bounds = data.geometry.bounds || data.geometry.viewport,
place = { place = {
// countryCode: Ox.getCountryCode(data.formatted_address), components: data.address_components,
countryCode: Ox.getCountryCode(data.formatted_address),
east: bounds.getNorthEast().lng(), east: bounds.getNorthEast().lng(),
geoname: data.formatted_address, geoname: data.formatted_address,
id: '_' + Ox.uid(), id: '_' + Ox.uid(),
@ -9699,6 +9706,7 @@ requires
name: data.formatted_address.split(', ')[0], name: data.formatted_address.split(', ')[0],
north: bounds.getNorthEast().lat(), north: bounds.getNorthEast().lat(),
south: bounds.getSouthWest().lat(), south: bounds.getSouthWest().lat(),
types: data.types,
west: bounds.getSouthWest().lng() west: bounds.getSouthWest().lng()
}; };
return place; return place;
@ -9754,7 +9762,7 @@ requires
self.options.selected = id; self.options.selected = id;
self.selected = id; self.selected = id;
setStatus(); setStatus();
that.triggerEvent('select', place); that.triggerEvent('selectplace', place);
/* /*
that.triggerEvent('select', { that.triggerEvent('select', {
id: self.options.selected id: self.options.selected
@ -10257,31 +10265,45 @@ requires
Ox.forEach(options, function(val, key) { Ox.forEach(options, function(val, key) {
that[key] = val; that[key] = val;
}); });
that.points = {
ne: new google.maps.LatLng(that.north, that.east), update();
sw: new google.maps.LatLng(that.south, that.west)
}; function update() {
that.bounds = new google.maps.LatLngBounds(that.points.sw, that.points.ne); that.points = {
that.center = that.bounds.getCenter(); ne: new google.maps.LatLng(that.north, that.east),
that.lat = that.center.lat(); sw: new google.maps.LatLng(that.south, that.west)
that.lng = that.center.lng(); };
Ox.extend(that.points, { that.bounds = new google.maps.LatLngBounds(that.points.sw, that.points.ne);
center: that.center, that.center = that.bounds.getCenter();
e: new google.maps.LatLng(that.lat, that.east), that.lat = that.center.lat();
s: new google.maps.LatLng(that.south, that.lng), that.lng = that.center.lng();
se: new google.maps.LatLng(that.south, that.east), Ox.extend(that.points, {
n: new google.maps.LatLng(that.north, that.lng), e: new google.maps.LatLng(that.lat, that.east),
nw: new google.maps.LatLng(that.north, that.west), s: new google.maps.LatLng(that.south, that.lng),
w: new google.maps.LatLng(that.lat, that.west), se: new google.maps.LatLng(that.south, that.east),
}); n: new google.maps.LatLng(that.north, that.lng),
that.marker = new Ox.MapMarker({ nw: new google.maps.LatLng(that.north, that.west),
map: that.map, w: new google.maps.LatLng(that.lat, that.west),
place: that });
}); that.crossesDateline = that.west > that.east;
that.polygon = new Ox.MapPolygon({ that.sizeNorthSouth = (that.north - that.south) * Ox.EARTH_CIRCUMFERENCE / 360;
map: that.map, that.sizeEastWest = Math.abs(that.west - that.east) * Ox.getMetersPerDegree(that.lat);
place: that that.size = Ox.getArea(
}); {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
});
that.polygon = new Ox.MapPolygon({
map: that.map,
place: that
});
}
Ox.print('PLACE', that)
}
that.add = function() { that.add = function() {
Ox.print('MapPlace add', that) Ox.print('MapPlace add', that)
@ -10299,7 +10321,7 @@ requires
that.edit = function() { that.edit = function() {
that.editing = true; that.editing = true;
that.marker.update(); that.marker.edit();
that.polygon.select(); that.polygon.select();
return that; return that;
} }
@ -10325,6 +10347,10 @@ requires
that.marker.update(); that.marker.update();
that.polygon.deselect(); that.polygon.deselect();
return that; return that;
};
that.update = function(str) {
update();
} }
return that; return that;
@ -10344,6 +10370,7 @@ requires
}); });
that.marker = new google.maps.Marker({ that.marker = new google.maps.Marker({
position: that.place.center, position: that.place.center,
raiseOnDrag: false,
title: that.place.name title: that.place.name
}); });
@ -10364,6 +10391,7 @@ requires
function setOptions() { function setOptions() {
that.marker.setOptions({ that.marker.setOptions({
draggable: that.place.editing,
icon: new google.maps.MarkerImage( icon: new google.maps.MarkerImage(
oxui.path + 'png/ox.ui/mapMarker' + oxui.path + 'png/ox.ui/mapMarker' +
(that.place.id[0] == '_' ? 'Result' : '') + (that.place.id[0] == '_' ? 'Result' : '') +
@ -10373,10 +10401,30 @@ requires
new google.maps.Size(16, 16), new google.maps.Size(16, 16),
new google.maps.Point(0, 0), new google.maps.Point(0, 0),
new google.maps.Point(8, 8) new google.maps.Point(8, 8)
) ),
position: that.place.center
}); });
} }
function dragstart(e) {
}
function drag(e) {
var lat = e.latLng.lat(),
lng = e.latLng.lng();
Ox.print(lat - that.place.lat)
that.place.south += lat - that.place.lat;
that.place.north += lat - that.place.lat;
that.place.west = lng - that.place.sizeEastWest * Ox.getDegreesPerMeter(lat) / 2;
that.place.east = lng + that.place.sizeEastWest * Ox.getDegreesPerMeter(lat) / 2;
that.place.update();
that.place.polygon.update();
}
function dragend(e) {
}
that.add = function() { that.add = function() {
Ox.print('MapMarker add', that) Ox.print('MapMarker add', that)
that.marker.setMap(that.map.map); that.marker.setMap(that.map.map);
@ -10384,12 +10432,25 @@ requires
return that; return that;
}; };
that.edit = function() {
setOptions();
google.maps.event.addListener(that.marker, 'dragstart', dragstart);
google.maps.event.addListener(that.marker, 'drag', drag);
google.maps.event.addListener(that.marker, 'dragend', dragend);
};
that.remove = function() { that.remove = function() {
that.marker.setMap(null); that.marker.setMap(null);
google.maps.event.clearListeners(that.marker); google.maps.event.clearListeners(that.marker);
return that; return that;
}; };
that.submit = function() {
google.maps.event.clearListeners(that.marker, 'dragstart');
google.maps.event.clearListeners(that.marker, 'drag');
google.maps.event.clearListeners(that.marker, 'dragend');
}
that.update = function() { that.update = function() {
setOptions(); setOptions();
} }
@ -10440,7 +10501,6 @@ requires
} else { } else {
that.map.panToPlace(); that.map.panToPlace();
} }
} }
function setOptions() { function setOptions() {
@ -10480,6 +10540,21 @@ requires
}); });
}; };
that.update = function() {
that.polygon.setOptions({
paths: [
that.place.points.sw,
that.place.points.nw,
that.place.points.ne,
that.place.points.se,
that.place.points.sw
]
});
Ox.forEach(that.markers, function(marker) {
marker.update();
});
}
return that; return that;
}; };
@ -10516,7 +10591,24 @@ requires
} }
function drag(e) { function drag(e) {
var lat = e.latLng.lat(),
lng = e.latLng.lng(),
degreesPerMeter = Ox.getDegreesPerMeter(that.place.lat);
if (that.position.indexOf('s') > -1) {
that.place.south = Math.min(lat, that.place.north - degreesPerMeter);
}
if (that.position.indexOf('w') > -1) {
that.place.west = Math.min(lng, that.place.east - degreesPerMeter);
}
if (that.position.indexOf('n') > -1) {
that.place.north = Math.max(lat, that.place.south + degreesPerMeter);
}
if (that.position.indexOf('e') > -1) {
that.place.east = Math.max(lng, that.place.west + degreesPerMeter)
}
that.place.update();
that.place.marker.update();
that.place.polygon.update();
} }
function dragend(e) { function dragend(e) {
@ -10535,6 +10627,12 @@ requires
google.maps.event.clearListeners(that.marker); google.maps.event.clearListeners(that.marker);
}; };
that.update = function() {
that.marker.setOptions({
position: that.place.points[that.position]
});
};
return that; return that;
}; };