Lat/lon test
Highmaps demo
HTML
<script src="http://code.highcharts.com/maps/highmaps.js"></script>
<script src="http://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="http://www.highcharts.om/testmaps/us-all.js"></script>
<script src="http://www.highcharts.om/testmaps/no-all.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.2.2/proj4.js"></script>
<div id="container"></div>
CSS
#container {
height: 600px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
JavaScript
$(function () {
// TODO:
// - Put functions on series object
// - Pre-projected maps (e.g. world maps)
// - Should hitZone geometry just be an array, not a GeoJSON geometry object?
// - JSLint weird relation (a > x) != (b > x)
// Test point in polygon, where polygon is defined as an array of points. Each point is an [x,y] array.
function pip(point, polygon) {
var i, j, c = false,
x = point[0],
y = point[1];
for (i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
if (((polygon[i][1] > y) !== (polygon[j][1] > y)) && (x < (polygon[j][0] - polygon[i][0]) * (y - polygon[i][1]) / (polygon[j][1] - polygon[i][1]) + polygon[i][0])) {
c = !c;
}
}
return c;
}
// Get map coordinates for a point specified by lat/lon.
function fromLonLat(x, y, map) {
var transforms = map['hc-transform'],
transform,
coords,
transformFromLonLat = function (x, y, transform) {
if (typeof proj4 === 'undefined') {
return {
x: 0,
y: 0
};
}
var projected = proj4(transform.crs, [x, y]),
rotated = transform.cosAngle ? [
projected[0] * transform.cosAngle + projected[1] * transform.sinAngle, -projected[0] * transform.sinAngle + projected[1] * transform.cosAngle] : projected;
return {
x: ((rotated[0] - transform.xoffset) * transform.scale + (transform.xpan || 0)) * transform.jsonres + transform.jsonmarginX,
y: ((transform.yoffset - rotated[1]) * transform.scale + (transform.ypan || 0)) * transform.jsonres - transform.jsonmarginY
};
};
for (transform in transforms) {
if (transforms.hasOwnProperty(transform) &&...