makeArray -> toArray

This commit is contained in:
rlx 2011-02-22 18:52:26 +00:00
parent 2f457f6ad0
commit 4326c307b4
4 changed files with 12598 additions and 11736 deletions

View file

@ -185,7 +185,7 @@ Ox.COUNTRIES = [
{code: 'TG', continent: 'Africa', name: 'Togo', region: 'Western Africa', type: 'sovereign'},
{code: 'TO', continent: 'Oceania', name: 'Tonga', region: 'Polynesia', type: 'sovereign'},
{code: 'TT', continent: 'North America', name: 'Trinidad and Tobago', region: 'Carribean', type: 'sovereign'},
{code: 'TN', continent: 'Africa', name: 'Tunisia', type: 'sovereign'},
{code: 'TN', continent: 'Africa', name: 'Tunisia', region: 'Northern Africa', type: 'sovereign'},
{code: 'TR', continent: 'Asia', name: 'Turkey', region: 'Western Asia', type: 'sovereign'},
{code: 'TM', continent: 'Asia', name: 'Turkmenistan', region: 'Central Asia', type: 'sovereign'},
{code: 'TV', continent: 'Oceania', name: 'Tuvalu', region: 'Polynesia', type: 'sovereign'},
@ -231,7 +231,7 @@ Ox.COUNTRIES = [
{code: 'MQ', continent: 'North America', country: 'France', name: 'Martinique', region: 'Carribean', type: 'dependent'},
{code: 'YT', continent: 'Africa', country: 'France', name: 'Mayotte', region: 'Eastern Africa', type: 'dependent'},
{code: 'NC', continent: 'Oceania', country: 'France', name: 'New Caledonia', region: 'Melanesia', type: 'dependent'},
{code: 'RE', continent: 'Africa', country: 'France', name: 'Réunion', region: 'Eastern Africa', type: 'dependent'},
{code: 'RE', continent: 'Africa', country: 'France', name: 'Réunion', region: 'Eastern Africa', type: 'dependent', flag: 'png'},
{code: 'BL', continent: 'North America', country: 'France', name: 'Saint Barthélemy', region: 'Carribean', type: 'dependent'},
{code: 'MF', continent: 'North America', country: 'France', name: 'Saint Martin', region: 'Carribean', type: 'dependent'},
{code: 'PM', continent: 'North America', country: 'France', name: 'Saint Pierre and Miquelon', region: 'Northern America', type: 'dependent'},
@ -281,7 +281,7 @@ Ox.COUNTRIES = [
{code: 'CSHH', continent: 'Europe', name: 'Czechoslovakia', region: 'Eastern Europe', type: 'former'},
{code: 'DYBJ', continent: 'Africa', name: 'Dahomey', region: 'Western Africa', type: 'former'},
{code: 'TPTL', continent: 'Asia', name: 'East Timor', region: 'South-Eastern Asia', type: 'former'},
{code: 'DDDE', continent: 'Europe', name: 'East Germany', region: 'Western Europe', type: 'former'},
{code: 'DDDE', continent: 'Europe', name: 'East Germany', region: 'Eastern Europe', type: 'former'},
{code: 'GEHH', name: 'Gilbert and Ellice Islands', type: 'former'},
{code: 'KOHH', continent: 'Asia', name: 'Korea', region: 'Eastern Asia', type: 'former'},
{code: 'NTHH', continent: 'Asia', name: 'Neutral Zone', region: 'Western Asia', type: 'former'},
@ -293,10 +293,10 @@ Ox.COUNTRIES = [
{code: 'YDYE', continent: 'Asia', name: 'South Yemen', region: 'Western Asia', type: 'former'},
{code: 'SUHH', continent: 'Europe', name: 'Soviet Union', region: 'Eastern Europe', type: 'former'},
{code: 'HVBF', continent: 'Africa', name: 'Upper Volta', region: 'Western Africa', type: 'former'},
{code: 'DE', continent: 'Europe', name: 'West Germany', region: 'Western Europe', type: 'former'},
{code: 'YUCS', continent: 'Europe', name: 'Yugoslavia', type: 'former'},
{code: 'DEDE', continent: 'Europe', name: 'West Germany', region: 'Western Europe', type: 'former'},
{code: 'YUCS', continent: 'Europe', name: 'Yugoslavia', region: 'Southern Europe', type: 'former'},
{code: 'ZRCD', continent: 'Africa', name: 'Zaire', region: 'Middle Africa', type: 'former'},
{code: 'AIDJ', country: 'France',name: 'French Afar and Issas', type: 'former'},
{code: 'AIDJ', continent: 'Africa', country: 'France', name: 'French Afar and Issas', region: 'Eastern Africa', type: 'former'},
{code: 'FQHH', continent: 'Antarctica', country: 'France', name: 'French Southern and Antarctic Territories', type: 'former'},
{code: 'FXFR', continent: 'Europe', country: 'France', name: 'Metropolitan France', type: 'former'},
{code: 'NHVU', country: ['France', 'United Kingdom'], name: 'New Hebrides', region: 'Melanesia', type: 'former'},
@ -306,9 +306,9 @@ Ox.COUNTRIES = [
{code: 'JTUM', continent: 'Oceania', country: 'United States', name: 'Johnston Island', region: 'Mictonesia', type: 'former'},
{code: 'MIUM', continent: 'Oceania', country: 'United States', name: 'Midway Islands', type: 'former'},
{code: 'PCHH', continent: 'Oceania', country: 'United States', name: 'Pacific Islands', region: 'Micronesia', type: 'former'},
{code: 'PZPA', continent: 'North America', country: 'United States', name: 'Panama Canal Zone', region: 'Central America', type: 'former'},
{code: 'PZPA', continent: 'North America', country: 'United States', name: 'Panama Canal Zone', region: 'Central America', type: 'former', flag: 'png'},
{code: 'PUUM', continent: 'Oceania', country: 'United States', name: 'United States Miscellaneous Pacific Islands', type: 'former'},
{code: 'WKUM', continent: 'Oceania', country: 'United States', name: 'Wake Island', region: 'Micronesia', type: 'former'}
{code: 'WKUM', continent: 'Oceania', country: 'United States', name: 'Wake Island', region: 'Micronesia', type: 'former'},
{code: 'EU', continent: 'Europe', name: 'European Union', type: 'other'},
{code: 'UK', continent: 'Europe', name: 'United Kingdom', region: 'Northern Europe', type: 'other'}
];

View file

@ -7970,12 +7970,13 @@ requires
columnsVisible: false,
columnWidth: [40, 800],
id: '',
items: null,
max: -1,
min: 0,
pageLength: 100,
scrollbarVisible: false,
selected: [],
request: function() {}, // {sort, range, keys, callback}
request: null, // function() {} {sort, range, keys, callback}
sort: []
})
.options(options || {})
@ -8079,6 +8080,7 @@ requires
that.$body = new Ox.List({
construct: constructItem,
id: self.options.id,
items: self.options.items,
itemHeight: 16,
itemWidth: getItemWidth(),
format: self.format, // fixme: not needed, happens in TextList
@ -8844,10 +8846,19 @@ requires
that = new Ox.Element('div', self)
.defaults({
clickable: false,
height: 256,
labels: false,
places: [],
type: 'satellite'
statusbar: false,
toolbar: false,
width: 256,
zoombar: false
})
.options(options || {})
.css({
width: self.options.width + 'px',
height: self.options.height + 'px'
})
.bindEvent({
key_up: function() {
pan(0, -1);
@ -8873,16 +8884,76 @@ requires
key_escape: deselectPlace
});
if (Ox.isUndefined(window.google)) {
window.google = function() {};
$.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() {
var interval = setInterval(function() {
if (!Ox.isUndefined(google.maps)) {
clearInterval(interval);
initMap();
if (self.options.toolbar) {
self.$toolbar = new Ox.Bar({
size: 24
})
.appendTo(that);
self.$labelsButton = new Ox.Button({
title: 'Show Labels',
width: 80
})
.css({float: 'left', margin: '4px'})
.bindEvent({
click: toggleLabels
})
.appendTo(self.$toolbar)
self.$findInput = new Ox.Input({
clear: true,
placeholder: 'Find on Map',
width: 192
})
.css({float: 'right', margin: '4px'})
.bindEvent({
submit: submitFind
})
.appendTo(self.$toolbar)
}
}, 100);
});
self.$map = new Ox.Element('div')
.css({
width: self.options.width + 'px',
height: (
self.options.height -
self.options.statusbar * 16 -
self.options.toolbar * 24 -
self.options.zoombar * 16
) + 'px'
})
.appendTo(that);
if (self.options.zoombar) {
self.$zoombar = new Ox.Bar({
size: 16
})
.appendTo(that);
self.$zoomInput = new Ox.Range({
arrows: true,
max: 22,
size: self.options.width,
thumbSize: 32,
thumbValue: true
})
.bindEvent({
change: changeZoom
})
.appendTo(self.$zoombar)
}
if (self.options.statusbar) {
self.$statusbar = new Ox.Bar({
size: 16
})
.appendTo(that);
self.$status = new Ox.Element()
.css({float: 'right', margin: '2px 4px'})
.appendTo(self.$statusbar);
}
if (Ox.isUndefined(window.google)) {
googleCallback = function() {
Ox.print('googleCallback')
delete googleCallback;
initMap();
};
$.getScript('http://maps.google.com/maps/api/js?callback=googleCallback&sensor=false');
} else {
initMap();
}
@ -8892,46 +8963,17 @@ requires
geocoder: new google.maps.Geocoder(),
selected: -1
});
if (self.options.places.length == 0 || Ox.isObject(self.options.places[0])) {
$.each(self.options.places, function(i, place) {
place.bounds = getBounds(),
place.center = place.bounds.getCenter();
$.extend(place, {
marker: new Marker(place),
polygon: new Polygon(place)
});
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
self.options.places[i] = place;
function getBounds() {
return new google.maps.LatLngBounds(
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
);
}
});
loadMap();
} else {
self.counter = 0;
$.each(self.options.places, function(i, place) {
getLocationByName(place, function(place) {
//Ox.print(self.counter, i, place);
self.options.places[i] = place;
if (self.counter++ == self.options.places.length - 1) {
loadMap();
}
});
});
}
loadPlaces(loadMap);
}
function loadMap() {
self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0);
self.zoom = 1;
$.extend(self, {
map: new google.maps.Map(that.$element[0], {
map: new google.maps.Map(self.$map.$element[0], {
center: self.center,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()],
mapTypeId: google.maps.MapTypeId[getMapType()],
zoom: self.zoom
})
});
@ -8950,6 +8992,40 @@ requires
that.triggerEvent('loaded');
}
function loadPlaces(callback) {
if (self.options.places.length == 0 || Ox.isObject(self.options.places[0])) {
$.each(self.options.places, function(i, place) {
place.bounds = getBounds(),
place.center = place.bounds.getCenter();
$.extend(place, {
marker: new Marker(place),
polygon: new Polygon(place)
});
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
self.options.places[i] = place;
function getBounds() {
return new google.maps.LatLngBounds(
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
);
}
});
callback && callback();
} else {
self.counter = 0;
$.each(self.options.places, function(i, place) {
getLocationByName(place, function(place) {
//Ox.print(self.counter, i, place);
self.options.places[i] = place;
if (self.counter++ == self.options.places.length - 1) {
callback && callback();
}
});
});
}
}
function canContain(outerBounds, innerBounds) {
var outerSpan = outerBounds.toSpan(),
innerSpan = innerBounds.toSpan();
@ -8957,6 +9033,10 @@ requires
outerSpan.lng() > innerSpan.lng();
}
function changeZoom(event, data) {
self.map.setZoom(data.value);
}
function click(event) {
//Ox.print('event', event);
that.gainFocus();
@ -8978,6 +9058,12 @@ requires
}
function submitFind(event, data) {
that.find(data.value, function(data) {
self.options.statusbar && self.$status.html(data.geoname);
});
}
function focusOnPlace() {
if (self.selected > -1) {
self.map.panTo(self.options.places[self.selected].center);
@ -9029,12 +9115,16 @@ requires
callback(null);
}
} else {
//Ox.print('geocode failed:', status);
Ox.print('geocode failed:', status);
callback(null);
}
});
}
function getMapType() {
return self.options.labels ? 'HYBRID' : 'SATELLITE'
}
function getPositionByName(name) {
var position = -1;
$.each(self.options.places, function(i, place) {
@ -9061,9 +9151,12 @@ requires
self.map.fitBounds(self.bounds);
}
function zoomChanged() {
that.triggerEvent('zoom', {
value: self.map.getZoom()
function toggleLabels() {
self.options.labels = !self.options.labels
self.map.setMapTypeId(google.maps.MapTypeId[getMapType()]);
self.$labelsButton.options({
title: self.$labelsButton.options('title') == 'Show Labels' ?
'Hide Labels' : 'Show Labels'
});
}
@ -9071,6 +9164,14 @@ requires
self.map.setZoom(self.map.getZoom() + z);
}
function zoomChanged() {
var zoom = self.map.getZoom();
self.options.zoombar && self.$zoomInput.options({value: zoom});
that.triggerEvent('zoom', {
value: zoom
});
}
function zoomToPlace() {
if (self.selected > -1) {
self.map.fitBounds(self.options.places[self.selected].bounds);
@ -9263,7 +9364,9 @@ requires
}
self.onChange = function(key, value) {
if (key == 'type') {
if (key == 'places') {
loadPlaces(loadMap);
} else if (key == 'type') {
}
};
@ -10259,7 +10362,7 @@ requires
})
.options($.extend(options, {
keyboard: parseKeyboard(options.keyboard || self.defaults.keyboard),
title: Ox.makeArray(options.title || self.defaults.title)
title: Ox.toArray(options.title || self.defaults.title)
}))
.addClass('OxItem' + (self.options.disabled ? ' OxDisabled' : ''))
/*
@ -10274,6 +10377,7 @@ requires
}
// construct
Ox.print('@@@@', self.options.title[0])
that.append(
that.$status = $('<td>', {
'class': 'OxCell OxStatus',
@ -10328,7 +10432,7 @@ requires
} else if (key == 'disabled') {
that.toggleClass('OxDisabled'); // fixme: this will only work if onChange is only invoked on actual change
} else if (key == 'title') {
self.options.title = Ox.makeArray(value);
self.options.title = Ox.toArray(value);
that.$title.html(self.options.title[0]);
}
}

File diff suppressed because it is too large Load diff

View file

@ -63,6 +63,7 @@
<script src="../../build/js/ox.js"></script>
<script src="../../build/js/ox.data.js"></script>
<script src="../../build/js/ox.geo.js"></script>
<script src="../../build/js/ox.map.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
$(function() {
@ -79,41 +80,31 @@
})
.appendTo($body),
aliases = {
"Ascension Island": "Ascension Island, Saint Helena",
"England": "England, United Kingdom",
'Byelorussian Soviet Socialist Republic': 'Belarus',
"Georgia": "Georgia, Europe",
"Holy See": "Vatican City",
// "Palestine": ["West Bank", "Gaza Strip"],
"Palestine": "West Bank",
"Saint Martin": "Sint Maarten",
"Scotland": "Scotland, United Kingdom",
"Svalbard and Jan Mayen": "Svalbard",
"Wales": "Wales, United Kingdom",
"Yugoslavia": "Serbia"
},
json = {};
///*
$.getJSON("geo.json", function(data) {
json = data;
getPlacemarks($.map(Ox.getCountries(true), function(v) {
return v.code.length == 2 ? v : null;
}));
getPlacemarks(Ox.COUNTRIES);
});
//*/
/*
getPlacemarks($.map(Ox.getCountries(true), function(v) {
return v.code.length == 2 ? v : null;
}));
getPlacemarks(Ox.COUNTRIES);
*/
function getPlacemarks(countries) {
var country = countries.shift();
if (!(country.code in json)) {
console.log(country);
Ox.getPlacemarks(aliases[country.name] || country.name, function(geodata) {
if (!geodata.results) {
if (!geodata.results.length) {
console.log(country.name, geodata.status);
}
} else {
geodata = geodata.results[0];
Ox.print('geodata', geodata)
data = {
address: aliases[country.name] || country.name,
geocode: {
@ -154,6 +145,7 @@
if (country.name != geodata.formatted_address) {
console.log(country.name, geodata.formatted_address, geodata);
}
}
if (countries.length) {
setTimeout(function() {
getPlacemarks(countries);
@ -228,8 +220,8 @@
}
$("<img/>")
.attr({
src: "../../tools/flags/png/16/" + (country.flag.indexOf("-") == 2 ?
country.flag.substr(0, 2) + "/" : "") + country.flag + ".png",
src: '/static/oxjs/build/svg/' + country.code + '.' +
(country.flag == 'png' ? 'png' : 'svg'),
title: country.name + " ((" + bounds.southWest.lat + ", " + bounds.southWest.lng + "), (" + bounds.northEast.lat + ", " + bounds.northEast.lng + "))"
})
.addClass("flag")