')
.addClass('rect')
.css({
left: (width * southWest.x) + 'px',
top: (height * northEast.y) + 'px',
right: '-16px',
bottom: (height - height * southWest.y) + 'px',
})
.hide()
.appendTo(Ox.UI.$body),
];
} else {
$div = [
$('
')
.addClass('rect')
.css({
left: ($map.width() * southWest.x) + 'px',
top: ($map.height() * northEast.y) + 'px',
right: ($map.width() - $map.width() * northEast.x) + 'px',
bottom: ($map.height() - $map.height() * southWest.y) + 'px',
})
.hide()
.appendTo(Ox.UI.$body)
];
}
$('
')
.attr({
src: '../png/icons/16/' + country.code + '.png',
title: country.name + ' ((' + country.south + ", " + country.west + "), (" + country.north + ", " + country.east + "))"
})
.addClass('flag')
.css({
left: (center.x * 100) + '%',
top: (center.y * 100) + '%'
})
.mouseenter(function() {
$(this).css({
zIndex: Ox.uid()
});
$.each($div, function() {
$(this).show();
});
})
.mouseleave(function() {
$.each($div, function() {
$(this).hide();
});
})
.appendTo(Ox.UI.$body);
}
function geocode(address, country, callback) {
var bounds;
if (!Ox.isUndefined(country.north)) {
bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(country.south, country.west),
new google.maps.LatLng(country.north, country.east)
);
callback({
bounds: bounds,
location: bounds.getCenter()
});
} else {
geocoder.geocode({
language: 'en',
address: address
}, function(results, status) {
if (results && results.length) {
var result = results[0];
callback({
bounds: result.geometry.bounds || result.geometry.viewport,
location: result.geometry.location
})
} else {
errors.push([address, status])
callback(null);
}
});
}
}
function getData(country, callback) {
if (country.lat) {
callback(country);
return;
}
var addresses = geo.geocode[country.name] || [country.name],
length = addresses.length,
union;
getImageURLs(country, function(imageURLs) {
// this might be too much data
/*
Ox.extend(country, {
imageURLs: imageURLs
});
*/
callGeocode();
});
function callGeocode() {
geocode(addresses.shift(), country, function(data) {
var center, lat, lng,
northEast, southWest,
east, north, south, west;
if (data) {
union = !union ? data.bounds : union.union(data.bounds);
if (addresses.length == 0) {
if (length == 1) {
lat = data.location.lat();
lng = data.location.lng();
} else {
center = union.getCenter();
lat = center.lat();
lng = center.lng();
}
northEast = union.getNorthEast();
southWest = union.getSouthWest();
east = northEast.lng();
north = northEast.lat();
south = southWest.lat();
west = southWest.lng();
callback($.extend(country, {
area: Ox.getArea(
{lat: south, lng: west},
{lat: north, lng: east}
),
east: toFixed(east),
lat: toFixed(lat),
lng: toFixed(lng),
north: toFixed(north),
south: toFixed(south),
west: toFixed(west)
}));
}
} else {
callback(country);
}
});
if (addresses.length) {
setTimeout(callGeocode, timeout);
}
}
}
function getImageURLs(country, callback) {
var image = new Image();
image.onload = function() {
callback({
icon16: Ox.canvas(image).canvas.toDataURL()
});
};
image.src = '../png/icons/16/' + country.code + '.png';
}
function toFixed(num) {
return parseFloat(num.toFixed(8));
}
});
});