merge places
This commit is contained in:
commit
fe026fc0e5
8 changed files with 979 additions and 284 deletions
140
build/js/ox.js
140
build/js/ox.js
|
@ -415,6 +415,7 @@ Ox.isEqual = function(obj0, obj1) {
|
|||
if (obj0 == obj1) {
|
||||
ret = true;
|
||||
} else if (Ox.isArray(obj0) && obj0.length == obj1.length) {
|
||||
ret = true;
|
||||
Ox.forEach(obj0, function(v, i) {
|
||||
ret = Ox.isEqual(v, obj1[i]);
|
||||
return ret;
|
||||
|
@ -1331,7 +1332,7 @@ Encoding functions
|
|||
>>> Ox.encodeUTF8('¥€$')
|
||||
'\u00C2\u00A5\u00E2\u0082\u00AC\u0024'
|
||||
*/
|
||||
return Ox.map(Array.prototype.slice.call(str), function(chr) {
|
||||
return Ox.map(str, function(chr) {
|
||||
var code = chr.charCodeAt(0),
|
||||
str = '';
|
||||
if (code < 128) {
|
||||
|
@ -1399,6 +1400,10 @@ Format functions
|
|||
================================================================================
|
||||
*/
|
||||
|
||||
Ox.formatArea = function(num, dec) {
|
||||
return Ox.formatNumber(Ox.round(num / 1000000, dec)) + ' km²';
|
||||
}
|
||||
|
||||
Ox.formatColor = function() {
|
||||
|
||||
};
|
||||
|
@ -1713,6 +1718,132 @@ Geo functions
|
|||
================================================================================
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
function rad(point) {
|
||||
return {
|
||||
lat: Ox.rad(point.lat),
|
||||
lng: Ox.rad(point.lng)
|
||||
};
|
||||
}
|
||||
|
||||
Ox.crossesDateline = function(point0, point1) {
|
||||
return point0.lng > point1.lng;
|
||||
}
|
||||
|
||||
Ox.getArea = function(point0, point1) {
|
||||
/*
|
||||
area of a ring between two latitudes:
|
||||
2 * PI * r^2 * abs(sin(lat0) - sin(lat1))
|
||||
see http://mathforum.org/library/drmath/view/63767.html
|
||||
*/
|
||||
/*
|
||||
2 * Math.PI *
|
||||
Math.pow(Ox.EARTH_RADIUS, 2) *
|
||||
Math.abs(Math.sin(Ox.rad(0)) - Math.sin(Ox.rad(1))) *
|
||||
Math.abs(Ox.rad(0) - Ox.rad(1)) /
|
||||
(2 * Math.PI)
|
||||
*/
|
||||
if (Ox.crossesDateline(point0, point1)) {
|
||||
point1.lng += 360;
|
||||
}
|
||||
var point0 = rad(point0),
|
||||
point1 = rad(point1);
|
||||
return Math.pow(Ox.EARTH_RADIUS, 2) *
|
||||
Math.abs(Math.sin(point0.lat) - Math.sin(point1.lat)) *
|
||||
Math.abs(point0.lng - point1.lng);
|
||||
};
|
||||
|
||||
Ox.getBearing = function(point0, point1) {
|
||||
/*
|
||||
>>> Ox.getBearing({lat: -45, lng: 0}, {lat: 45, lng: 0})
|
||||
0
|
||||
*/
|
||||
var point0 = rad(point0),
|
||||
point1 = rad(point1),
|
||||
x = Math.cos(point0.lat) * Math.sin(point1.lat) -
|
||||
Math.sin(point0.lat) * Math.cos(point1.lat) *
|
||||
Math.cos(point1.lng - point0.lng),
|
||||
y = Math.sin(point1.lng - point0.lng) *
|
||||
Math.cos(point1.lat);
|
||||
return (Ox.deg(Math.atan2(y, x)) + 360) % 360;
|
||||
};
|
||||
|
||||
Ox.getCenter = function(point0, point1) {
|
||||
/*
|
||||
>>> Ox.values(Ox.getCenter({lat: -45, lng: -90}, {lat: 45, lng: 90}))
|
||||
[0, 0]
|
||||
*/
|
||||
var point0 = rad(point0),
|
||||
point1 = rad(point1),
|
||||
x = Math.cos(point1.lat) *
|
||||
Math.cos(point1.lng - point0.lng),
|
||||
y = Math.cos(point1.lat) *
|
||||
Math.sin(point1.lng - point0.lng),
|
||||
d = Math.sqrt(
|
||||
Math.pow(Math.cos(point0.lat) + x, 2) + Math.pow(y, 2)
|
||||
),
|
||||
lat = Ox.deg(
|
||||
Math.atan2(Math.sin(point0.lat) + Math.sin(point1.lat), d)
|
||||
),
|
||||
lng = Ox.deg(
|
||||
point0.lng + Math.atan2(y, Math.cos(point0.lat) + x)
|
||||
);
|
||||
return {lat: lat, lng: lng};
|
||||
};
|
||||
|
||||
Ox.getDistance = function(point0, point1) {
|
||||
/*
|
||||
>>> Ox.EARTH_CIRCUMFERENCE == Ox.getDistance({lat: -45, lng: -90}, {lat: 45, lng: 90}) * 2
|
||||
true
|
||||
*/
|
||||
var point0 = rad(point0),
|
||||
point1 = rad(point1);
|
||||
return Math.acos(
|
||||
Math.sin(point0.lat) * Math.sin(point1.lat) +
|
||||
Math.cos(point0.lat) * Math.cos(point1.lat) *
|
||||
Math.cos(point1.lng - point0.lng)
|
||||
) * Ox.EARTH_RADIUS;
|
||||
};
|
||||
|
||||
Ox.getLatLngByXY = function(xy) {
|
||||
/*
|
||||
>>> Ox.values(Ox.getLatLngByXY({x: 0.5, y: 0.5}))
|
||||
[0, 0]
|
||||
*/
|
||||
function getVal(val) {
|
||||
return (val - 0.5) * 2 * Math.PI;
|
||||
}
|
||||
return {
|
||||
lat: -Ox.deg(Math.atan(Ox.sinh(getVal(xy.y)))),
|
||||
lng: Ox.deg(getVal(xy.x))
|
||||
}
|
||||
};
|
||||
|
||||
Ox.getMetersPerDegree = function(lat) {
|
||||
/*
|
||||
>>> Ox.EARTH_CIRCUMFERENCE == Ox.getMetersPerDegree(0) * 360
|
||||
true
|
||||
*/
|
||||
return Math.cos(lat * Math.PI / 180) * Ox.EARTH_CIRCUMFERENCE / 360;
|
||||
};
|
||||
|
||||
Ox.getXYByLatLng = function(latlng) {
|
||||
/*
|
||||
>>> Ox.values(Ox.getXYByLatLng({lat: 0, lng: 0}))
|
||||
[0.5, 0.5]
|
||||
*/
|
||||
function getVal(val) {
|
||||
return (val / (2 * Math.PI) + 0.5)
|
||||
}
|
||||
return {
|
||||
x: getVal(Ox.rad(latlng.lng)),
|
||||
y: getVal(Ox.asinh(Math.tan(Ox.rad(-latlng.lat))))
|
||||
};
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
Ox.Line = function(point0, point1) {
|
||||
|
||||
var self = {
|
||||
|
@ -1734,13 +1865,6 @@ Ox.Line = function(point0, point1) {
|
|||
};
|
||||
|
||||
that.getBearing = function() {
|
||||
var points = rad(),
|
||||
x = Math.cos(point[0].lat) * Math.sin(point[1].lat) -
|
||||
Math.sin(point[0].lat) * Math.cos(point[1].lat) *
|
||||
Math.cos(point[1].lng - point[0].lng),
|
||||
y = Math.sin(point[1].lng - point[0].lng) *
|
||||
Math.cos(point[1].lat);
|
||||
return (Ox.deg(math.atan2(y, x)) + 360) % 360;
|
||||
};
|
||||
|
||||
that.getDistance = function() {
|
||||
|
|
|
@ -215,7 +215,7 @@ Ox.COUNTRIES = [
|
|||
{code: 'MD-TR', continent: 'Europe', name: 'Transnistria', region: 'Eastern Europe', type: 'unrecognized'},
|
||||
{code: 'AQ', continent: 'Antarctica', country: ['Argentina', 'Australia', 'Chile', 'France', 'New Zealand', 'Norway', 'United Kingdom'], name: 'Antarctica'},
|
||||
{code: 'CX', continent: 'Asia', country: 'Australia', name: 'Christmas Island', region: 'South-Eastern Asia', type: 'dependent'},
|
||||
{code: 'CC', continent: 'Asia', country: 'Australia', name: 'Cocos Island', region: 'South-Eastern Asia', type: 'dependent'},
|
||||
{code: 'CC', continent: 'Asia', country: 'Australia', name: 'Cocos Islands', region: 'South-Eastern Asia', type: 'dependent'},
|
||||
{code: 'HM', continent: 'Antarctica', country: 'Australia', name: 'Heard Island and McDonald Islands', type: 'dependent'},
|
||||
{code: 'NF', continent: 'Oceania', country: 'Australia', name: 'Norfolk Island', region: 'Australia and New Zealand', type: 'dependent'},
|
||||
{code: 'HK', continent: 'Asia', country: 'China', name: 'Hong Kong', region: 'Eastern Asia', type: 'dependent'},
|
||||
|
@ -312,3 +312,75 @@ Ox.COUNTRIES = [
|
|||
{code: 'EU', continent: 'Europe', name: 'European Union', type: 'other'},
|
||||
{code: 'UK', continent: 'Europe', name: 'United Kingdom', region: 'Northern Europe', type: 'other'}
|
||||
];
|
||||
|
||||
Ox.COUNTRY_CODES = Ox.map(Ox.COUNTRIES, function(country) {
|
||||
return country.code.length == 2 && ['EU', 'UK'].indexOf(country.code) == -1 ? country.code : null;
|
||||
}).sort();
|
||||
|
||||
Ox.getCountryCode = (function() {
|
||||
var aliases = {
|
||||
'The Bahamas': 'Bahamas',
|
||||
'The Netherlands': 'Netherlands',
|
||||
'UK': 'United Kingdom',
|
||||
'US Virgin Islands': 'United States Virgin Islands',
|
||||
'USA': 'United States'
|
||||
};
|
||||
return function(geoname) {
|
||||
var countryCode = '',
|
||||
countryName = geoname.split(', ').pop();
|
||||
Ox.forEach(aliases, function(val, key) {
|
||||
if (countryName == key) {
|
||||
countryName = val;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
Ox.forEach(Ox.COUNTRIES, function(country) {
|
||||
if (country.name == countryName) {
|
||||
countryCode = country.code;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return countryCode;
|
||||
};
|
||||
}());
|
||||
|
||||
Ox.Place = function(options) {
|
||||
|
||||
/*
|
||||
in: geoname, name, south, west, north, east
|
||||
out: country, countryCode, geonameReverse, lat, lng
|
||||
*/
|
||||
|
||||
var self = {},
|
||||
that = Ox.extend(this, options);
|
||||
|
||||
['south', 'west', 'north', 'east'].forEach(function(v) {
|
||||
self[v + 'Rad'] = Ox.rad(that[v]);
|
||||
});
|
||||
|
||||
self.geonames = that.geoname.split(', ').reverse();
|
||||
that.geonameReverse = self.geonames.join(', ');
|
||||
|
||||
Ox.forEach(Ox.COUNTRIES, function(country) {
|
||||
if (country.name == self.geonames[0]) {
|
||||
that.country = country.name;
|
||||
that.countryCode = country.code;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
function getArea() {
|
||||
|
||||
}
|
||||
|
||||
function getCenter() {
|
||||
|
||||
}
|
||||
|
||||
function getRad(points) {
|
||||
|
||||
}
|
||||
|
||||
return that;
|
||||
|
||||
};
|
1039
build/js/ox.ui.js
1039
build/js/ox.ui.js
File diff suppressed because it is too large
Load diff
|
@ -5,10 +5,6 @@
|
|||
"png/ox.ui/browserOpera128.png",
|
||||
"png/ox.ui/browserSafari128.png",
|
||||
"png/ox.ui/icon16.png",
|
||||
"png/ox.ui/markerBlue.png",
|
||||
"png/ox.ui/markerGreen.png",
|
||||
"png/ox.ui/markerRed.png",
|
||||
"png/ox.ui/markerYellow.png",
|
||||
"png/ox.ui/transparent.png",
|
||||
"png/ox.ui/videoMarkerCut.png",
|
||||
"png/ox.ui/videoMarkerIn.png",
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in a new issue