Skip to content

Instantly share code, notes, and snippets.

@mapsense-examples
Last active August 29, 2015 14:26
Show Gist options
  • Save mapsense-examples/d9e66b55aa36af065a66 to your computer and use it in GitHub Desktop.
Save mapsense-examples/d9e66b55aa36af065a66 to your computer and use it in GitHub Desktop.
mapsense + geoprocessing (buffer)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js" charset="utf-8"></script>
<script src="mapsense.js" charset="utf-8"></script>
<!--
<script src="https://developer.mapsense.co/mapsense.js" charset="utf-8"></script>
-->
<link type="text/css" href="https://developer.mapsense.co/mapsense.css" rel="stylesheet"/>
<link type="text/css" href="simple_basemap.css" rel="stylesheet"/>
<link type="text/css" href="local.css" rel="stylesheet"/>
<script src='proj4-src.js'></script>
<script src='http://api.tiles.mapbox.com/mapbox.js/plugins/turf/v1.4.0/turf.min.js'></script>
<script src='reproject.js'></script>
<style>
</style>
</head>
<body>
<div id="myMap"></div>
<div class="wrapper">
<div id="results" class="ui top right">
<div id="coordinates"></div>
<div id="info-A">
</div>
<div id="info-B">
</div>
<div id="info-C">
</div>
</div>
<div class="title">
<div class="title-text">
<div class="h1sim">Buffer by distance</div>
<p class=""></p>
</div>
</div>
<div id="control" class="clickselect">
</div>
<div class="bottom left">
<label>
<input id="labels_control" type="checkbox"> Labels
</label>
</div>
</div>
<script>
var G = {}; // A global object to store variables
G.key = 'key-2d5eacd8b924489c8ed5e8418bd883bc';
G.simplify = '&ringSpan=10&lineSpan=10&s=10';
G.home = [ // we'll set the map extent to these bounds
{lon: -125, lat: -60},
{lon: 160, lat: 75}
];
//G.basemap = {'style': 'sketch', 'blayer': null };
G.basemap = {'style': 'simple', 'blayer': null };
G.params = {};
gj_fc_template = {
"type": "FeatureCollection",
"features": [
]
};
G.layers = {
'base': { 'url': '', 'default': false},
'overlay_a': {
'url': 'https://{S}-api.mapsense.co/universes/mapsense.planet_osm_points/{Z}/{X}/{Y}.topoJson?api-key=' + G.key + '&select=name',
'where': "&where=name=='"+G.input_A+"'",
//'params': '&density=20',
'params': G.simplify,
'class': 'overlay_a',
'default': true
},
'overlay_b': {
'url': 'https://{S}-api.mapsense.co/universes/mapsense.planet_osm_points/{Z}/{X}/{Y}.topoJson?api-key=' + G.key + '&select=name',
'where': "&where=name=='"+G.input_A+"'",
//'params': '&density=20',
'params': G.simplify,
'class': 'overlay_b',
'default': true
},
'labels': { 'url': 'http://stamen-tiles-{S}.a.ssl.fastly.net/toner-labels/{Z}/{X}/{Y}.png', 'default': false }
};
var crss = {
"EPSG:2400": "+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs",
"EPSG:3006": "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs",
"EPSG:4326": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
"world_azimuthal_equidistant": "+proj=aeqd +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs",
"ESRI:54032": "+proj=aeqd +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs",
"EPSG:3857": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"
};
window.onload = function(){
initSelect();
initMap(); // initialize the map
}
// Add a div to display info mouseover info
var mouseinfo = d3.select('body')
.append("div")
.attr("class","mouseinfo");
function initMap() {
map = mapsense.map("#myMap"); // init the map
map.tileSize({x:256,y:256});
//map.extent(G.home);
if (G.basemap) {
G.basemap.blayer = mapsense.basemap().apiKey(G.key).style(G.basemap.style)
G.basemap.blayer.selection();
map.add(G.basemap.blayer);
}
// change map interaction so users can see the map update when they scroll through the selector fields
map.interact(false);
map.add(mapsense.drag());
map.add(mapsense.wheel());
map.add(mapsense.dblclick());
map.add(mapsense.touch());
map.add(mapsense.hash());
mapsense.compass().map(map); //enable shift zoom
d3.select('.compass').attr('style','display: none;') // but hide the compass graphic
/*
G.layers.output.lyr = mapsense.topoJson()
.features(G.layers.output.gj.features)
.selection(function(d){
d.attr("class", "output");
})
;
map.add(G.layers['output'].lyr);
*/
G.layers['overlay_b'].lyr = mapsense.topoJson()
.url(
mapsense.url(
G.layers['overlay_a'].url + G.layers['overlay_a'].where + G.layers['overlay_a'].params
)
.hosts(['a', 'b', 'c', 'd'])
)
.clip(false)
.scale('fixed')
.selection(function(s){
s.attr('class','output');
})
;
map.add(G.layers['overlay_b'].lyr);
G.layers['overlay_a'].lyr = mapsense.topoJson()
.url(
mapsense.url(
G.layers['overlay_a'].url + G.layers['overlay_a'].where + G.layers['overlay_a'].params
)
.hosts(['a', 'b', 'c', 'd'])
)
.clip(false)
.scale('fixed')
.selection(function(s){
s.attr('class','overlay_a');
})
;
map.add(G.layers['overlay_a'].lyr);
G.layers.labels.lyr = mapsense.image()
.url(mapsense.url(G.layers.labels.url)
.hosts(["a", "b", "c", "d"]))
;
map.add(G.layers.labels.lyr.visible(false).id("labels_layer"));
d3.select('#labels_control').on('click',function(){ toggleLabels(); });
}
function returnBuffer(gj, dist, unit) {
var units = d3.select('#units').property('value');
//console.log('!' + units + '!');
//console.log(dist);
// FIXME: projection's miles per lon at this lat
var dist = dist * 69/48;
//console.log(dist);
//dist = +dist;
switch (units) {
//case 'meters': dist = +dist * 1000;
case 'km': {
dist = dist * 1000;
//console.log(dist);
break;
}
case 'miles': {
dist = dist * 1609;
break;
//console.log(dist);
}
}
//console.log(dist);
//var proj_calc = "world_azimuthal_equidistant";
var proj_calc = "EPSG:3857";
var gj_3857 = reproject.reproject(gj, "EPSG:4326", proj_calc, crss);
//var buffered = turf.buffer(gj_3857, +dist, unit);
var buffered = turf.buffer(gj_3857, +dist);
var result_3857 = buffered;
var result = reproject.reproject(result_3857, proj_calc, "EPSG:4326", crss);
return result;
}
function initSelect() {
// add a input element to the page
var inputs = [
{'label':'Query', 'default':"amenity=='library'"},
{'label':'Distance', 'default': 0.5}
];
d3.select('#control')
.selectAll('input')
.data(inputs)
.enter()
.append('label')
.attr('class','input-label')
.append('input')
.attr('class','inputs')
.attr('id',function(d) { return d.label; })
.property('value',function(d) { return d.default; } )
d3.selectAll('.input-label')
.append('text')
.text(function(d) { return d['label']; })
.append('br')
var dropdown = d3.select('#control').append('select')
.attr('id','units')
.attr('class','C inputs')
.selectAll('option')
.data(['miles','km','meters'])
.enter()
.append('option')
.property('value',function(d) { return d; })
.text(function(d) {
return d;
});
;
d3.select('#control').append('br');
d3.select('#control').append('a')
.attr('id','enter')
.attr('class','button')
.text('Search')
;
// When the user selects an option, update the class for those features
//d3.selectAll('.selector').on('change.query', updateQuery);
d3.selectAll('#enter').on('click', updateQuery);
//d3.selectAll('#refresh').on('click', cycleQuery);
//d3.select('#selector_a').node().value = G.input_A;
//d3.select('#selector_b').node().value = G.input_B;
}
function updateQuery() {
// update the query
//var new_where = "&where=amenity=='" + d3.select('#selector_a').node().value + "' OR amenity=='" + d3.select('#selector_b').node().value + "'";
var valu_A = d3.select('#Query').property('value');
var new_where = "&where=" + valu_A; // + "'";
var new_url = G.layers['overlay_a'].url + new_where + G.layers['overlay_a'].params;
// clear the previous results
//G.layers.output.gj.features = []
//G.layers.output.lyr.features([]);
// update the layer
G.layers['overlay_a'].lyr
.url(
mapsense.url(new_url).hosts(['a','b','c','d'])
)
;
G.layers['overlay_b'].lyr
.url(
mapsense.url(new_url).hosts(['a','b','c','d'])
)
.transformData(function(s){
// s is array of objects:
var new_s = s;
var dist = d3.select('#Distance').property('value');
if ( s.length > 0 && s[0].geometry ) {
//console.log(JSON.stringify(s));
var old_gj = {type: "FeatureCollection", features: s };
new_gj = returnBuffer(old_gj, +dist, 'meters');
//new_gj = returnBuffer(old_gj, dist, units);
new_s = new_gj.features;
}
return new_s;
})
;
}
function toggleLabels() {
var checkit = d3.select('#labels_control').property('checked');
if (checkit) {
G.layers.labels.lyr.visible(true);
d3.select("#labels_layer").attr("style","opacity: 0.35;");
var credit = d3.select('.mapsense-attribution').html();
credit += ' <a target="_blank" href="http://stamen.com">©Stamen Design</a>';
d3.select('.mapsense-attribution').html(credit);
} else {
G.layers.labels.lyr.visible(false)
var credit = '<a target="_blank" href="https://developer.mapsense.co/tileViewer/?tileset=mapsense.earth">©Mapsense ©OpenStreetMap</a>';
d3.select('.mapsense-attribution').html(credit);
}
}
function markLatLon(lat,lon,name){
name = name || "";
var feature = {
type: "Feature",
geometry: {type: "Point", "coordinates": [ +lon, +lat ]},
};
return feature;
}
</script>
</body>
</html>
html, body, #myMap {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font: 11px 'Droid Sans', sans-serif;
color: #777;
}
body {font-size: 12px; }
.ui, .mouseinfo {
font: 12px monospace !important;
color: black;
}
.float-left { float: left; }
.float-right { float: right; }
.top { position: absolute; top: 0; }
.right { position: absolute; right: 0; }
.bottom { position: absolute; bottom: 0; }
.left { position: absolute; left: 0; }
.bold { font-weight: bold; }
circle {
vector-effect: non-scaling-stroke;
fill-opacity: 0.35;
}
.wrapper {
position: absolute;
top: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 99;
margin: 0;
clear: both;
}
.ui {
/*position: absolute;
*/
overflow: auto;
max-width: 280px;
max-height: 100%;
background: rgba(255,255,255,1);
}
.outline {
outline: 1px solid #aaa;
}
.title {
text-align: left;
padding: 10px 2px 2px 20px;
background: rgba(255,255,255,0.75);
pointer-events: all;
}
.title-text {
width: calc(100% - 280px);
color: #3c4662;
max-width: 600px;
}
.title-text p {
text-align: left;
vertical-align: top;
}
#control,
.control {
padding: 10px;
/*margin-left: 10px;
*/
font-size: 1.1em;
}
.inputs {
margin: 2px 1px;
}
.h1sim {
font-size: 1.9em;
font-weight: bold;
}
#selector {
font: 20px 'Droid Sans', sans-serif;
}
#info-B, #info-A {
background: rgba(255,255,255,0.8);
overflow: auto;
display: inline-block;
max-height: 100%;
pointer-events: all;
overflow: auto;
}
.mouseinfo {
position: absolute;
bottom: 0;
left: 0;
pointer-events: none;
max-width: 300px;
/*font: 20px 'Droid Sans', sans-serif;*/
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid #eee;
padding: 2px;
padding-left: 10px;
padding-right: 10px
}
.detailKey {
background: #eee;
color: #666;
opacity: .8;
text-transform: uppercase;
font-size: 11px;
font-weight: 400;
}
.detailVal {
background: rgba(255,255,255,0.8);
text-align: left;
}
.point {
fill: rgba(255,0,0, 0.6);
stroke: rgba(255,0,0, 1);
/*stroke: rgba(68, 167, 228, 1); blue
*/
stroke-width: 2;
}
.clickselect {
pointer-events: all;
}
.mapsense-attribution a {
color: #999;
}
.mapsense-attribution {
color: #999;
background: rgba(255,255,255,0.5);
padding: 7px;
}
label {
pointer-events: all;
}
#labels_control {
pointer-events: all;
padding: 3px;
}
.output {
fill: green;
fill-opacity: 0.3;
stroke: green;
}
.overlay_a {
fill: #A14BD0;
fill-opacity: 0.3;
stroke: purple;
}
.land {
stroke: rgba(68, 167, 228, 0.5);
}
.selector {
display: inline-block;
padding: 1px 2px;
border: 1px solid #777;
font: 14px bold 'Droid Sans', sans-serif;
line-height: 1em;
color: #777;
height: 16px;
width: 50px;
}
a.button {
display: inline-block;
padding: 1px 2px;
border: 1px solid #777;
font: 14px bold 'Droid Sans', sans-serif;
line-height: 1em;
color: #777;
height: 16px;
min-width: 50px;
vertical-align: top;
/*margin-left: 4px;
*/text-align: center;
cursor: pointer;
}
a.button:hover {
border: 1px solid #000;
color: #000;
}
(function(){
var mapsense = {version: "1.0.0"},
ms = mapsense;
var zero = {x: 0, y: 0};
ms.ns = {
svg: "http://www.w3.org/2000/svg",
xlink: "http://www.w3.org/1999/xlink"
};
function ns(name) {
var i = name.indexOf(":");
return i < 0 ? name : {
space: ms.ns[name.substring(0, i)],
local: name.substring(i + 1)
};
}
ms.id = (function() {
var id = 0;
return function() {
return ++id;
};
})();
ms.svg = function(type) {
return document.createElementNS(ms.ns.svg, type);
};
ms.transform = function(a, b, c, d, e, f) {
var transform = {},
zoomDelta,
zoomFraction,
k;
if (!arguments.length) {
a = 1; c = 0; e = 0;
b = 0; d = 1; f = 0;
}
transform.zoomFraction = function(x) {
if (!arguments.length) return zoomFraction;
zoomFraction = x;
zoomDelta = Math.floor(zoomFraction + Math.log(Math.sqrt(a * a + b * b + c * c + d * d)) / Math.LN2);
k = Math.pow(2, -zoomDelta);
return transform;
};
transform.apply = function(x) {
var k0 = Math.pow(2, -x.zoom),
k1 = Math.pow(2, x.zoom - zoomDelta);
return {
column: (a * x.column * k0 + c * x.row * k0 + e) * k1,
row: (b * x.column * k0 + d * x.row * k0 + f) * k1,
zoom: x.zoom - zoomDelta
};
};
transform.unapply = function(x) {
var k0 = Math.pow(2, -x.zoom),
k1 = Math.pow(2, x.zoom + zoomDelta);
return {
column: (x.column * k0 * d - x.row * k0 * c - e * d + f * c) / (a * d - b * c) * k1,
row: (x.column * k0 * b - x.row * k0 * a - e * b + f * a) / (c * b - d * a) * k1,
zoom: x.zoom + zoomDelta
};
};
transform.toString = function() {
return "matrix(" + [a * k, b * k, c * k, d * k].join(" ") + " 0 0)";
};
return transform.zoomFraction(0);
};
ms.cache = function(load, unload) {
var cache = {},
locks = {},
map = {},
head = null,
tail = null,
size = 64,
n = 0;
function remove(tile) {
n--;
if (unload) unload(tile);
delete map[tile.key];
if (tile.next) tile.next.prev = tile.prev;
else if (tail = tile.prev) tail.next = null;
if (tile.prev) tile.prev.next = tile.next;
else if (head = tile.next) head.prev = null;
}
function flush() {
for (var tile = tail; n > size; tile = tile.prev) {
if (!tile) break;
if (tile.lock) continue;
remove(tile);
}
}
cache.peek = function(c) {
return map[[c.zoom, c.column, c.row].join("/")];
};
cache.load = function(c, projection) {
var key = [c.zoom, c.column, c.row].join("/"),
tile = map[key];
if (tile) {
if (tile.prev) {
tile.prev.next = tile.next;
if (tile.next) tile.next.prev = tile.prev;
else tail = tile.prev;
tile.prev = null;
tile.next = head;
head.prev = tile;
head = tile;
}
tile.lock = 1;
locks[key] = tile;
return tile;
}
tile = {
key: key,
column: c.column,
row: c.row,
zoom: c.zoom,
next: head,
prev: null,
lock: 1
};
load.call(null, tile, projection);
locks[key] = map[key] = tile;
if (head) head.prev = tile;
else tail = tile;
head = tile;
n++;
return tile;
};
cache.unload = function(key) {
if (!(key in locks)) return false;
var tile = locks[key];
tile.lock = 0;
delete locks[key];
if (tile.request && tile.request.abort(false)) remove(tile);
return tile;
};
cache.locks = function() {
return locks;
};
cache.size = function(x) {
if (!arguments.length) return size;
size = x;
flush();
return cache;
};
cache.flush = function() {
flush();
return cache;
};
cache.clear = function() {
for (var key in map) {
var tile = map[key];
if (tile.request) tile.request.abort(false);
if (unload) unload(map[key]);
if (tile.lock) {
tile.lock = 0;
tile.element.parentNode.removeChild(tile.element);
}
}
locks = {};
map = {};
head = tail = null;
n = 0;
return cache;
};
return cache;
};
ms.url = function(template) {
var hosts = [],
repeat = true;
function format(c) {
var max = c.zoom < 0 ? 1 : 1 << c.zoom,
column = c.column;
if (repeat) {
column = c.column % max;
if (column < 0) column += max;
} else if ((column < 0) || (column >= max)) {
return null;
}
return template.replace(/{(.)}/g, function(s, v) {
switch (v) {
case "S": return hosts[(Math.abs(c.zoom) + c.row + column) % hosts.length];
case "Z": return c.zoom;
case "X": return column;
case "Y": return c.row;
case "B": {
var nw = ms.map.coordinateLocation({row: c.row, column: column, zoom: c.zoom}),
se = ms.map.coordinateLocation({row: c.row + 1, column: column + 1, zoom: c.zoom}),
pn = Math.ceil(Math.log(c.zoom) / Math.LN2);
return se.lat.toFixed(pn) +
"," + nw.lon.toFixed(pn) +
"," + nw.lat.toFixed(pn) +
"," + se.lon.toFixed(pn);
}
}
return v;
});
}
format.template = function(x) {
if (!arguments.length) return template;
template = x;
return format;
};
format.hosts = function(x) {
if (!arguments.length) return hosts;
hosts = x;
return format;
};
format.repeat = function(x) {
if (!arguments.length) return repeat;
repeat = x;
return format;
};
return format;
};
ms.dispatch = function(that) {
var types = {};
that.on = function(type, handler) {
var listeners = types[type] || (types[type] = []);
for (var i = 0; i < listeners.length; i++) {
if (listeners[i].handler == handler) return that; // already registered
}
listeners.push({handler: handler, on: true});
return that;
};
that.off = function(type, handler) {
var listeners = types[type];
if (listeners) for (var i = 0; i < listeners.length; i++) {
var l = listeners[i];
if (l.handler == handler) {
l.on = false;
listeners.splice(i, 1);
break;
}
}
return that;
};
return function(event) {
var listeners = types[event.type];
if (!listeners) return;
listeners = listeners.slice(); // defensive copy
for (var i = 0; i < listeners.length; i++) {
var l = listeners[i];
if (l.on) l.handler.call(that, event);
}
};
};
ms.queue = (function() {
var queued = [], active = 0, size = 6;
function process() {
if ((active >= size) || !queued.length) return;
active++;
queued.pop()();
}
function dequeue(send) {
for (var i = 0; i < queued.length; i++) {
if (queued[i] == send) {
queued.splice(i, 1);
return true;
}
}
return false;
}
function merge(dest, src) {
for (var property in src) {
dest[property] = src[property];
}
return dest;
}
function request(url, callback, options) {
var req;
function send() {
req = new XMLHttpRequest();
req.open("GET", url, true);
if (options) {
if (options.mimeType && req.overrideMimeType)
req.overrideMimeType(options.mimeType);
if (options.responseType)
req.responseType = options.responseType;
if (options.xhrFields) {
for (var f in options.xhrFields) {
req[f] = options.xhrFields[f];
}
}
}
req.onreadystatechange = function(e) {
if (req.readyState == 4) {
active--;
if (req.status < 300) callback(req);
process();
}
};
req.send(null);
}
function abort(hard) {
if (dequeue(send)) return true;
if (hard && req) { req.abort(); return true; }
return false;
}
queued.push(send);
process();
return {abort: abort};
}
function text(url, callback, mimeType) {
return request(url, function(req) {
if (req.responseText) callback(req.responseText);
}, { mimeType: mimeType });
}
/*
* We the override MIME type here so that you can load local files; some
* browsers don't assign a proper MIME type for local files.
*/
function json(url, callback, options) {
return request(url, function(req) {
if (req.responseText) callback(JSON.parse(req.responseText));
}, merge({ mimeType: "application/json" }, options));
}
function xml(url, callback, options) {
return request(url, function(req) {
if (req.responseXML) callback(req.responseXML);
}, merge({ mimeType: "application/xml" }, options));
}
function octetStream(url, callback, options) {
var defaultOptions = {
mimeType: "application/octet-stream",
responseType: "arraybuffer"
};
return request(url, function(req) {
if (req.response) callback(req.response);
}, merge(defaultOptions, options));
}
function image(imageElement, src, callback) {
var img;
function send() {
img = document.createElement("img");
img.onerror = function() {
active--;
process();
};
img.onload = function() {
active--;
callback(img);
process();
};
img.src = src;
imageElement.setAttributeNS(ms.ns.xlink, "href", src);
}
function abort(hard) {
if (dequeue(send)) return true;
if (hard && img) { img.src = "about:"; return true; } // cancels request
return false;
}
queued.push(send);
process();
return {abort: abort};
}
return {
text: text,
xml: xml,
json: json,
octetStream: octetStream,
image: image
};
})();
ms.map = function(mapContainer) {
var map = {},
container,
size,
sizeActual = zero,
sizeRadius = zero, // sizeActual / 2
tileSize = {x: 512, y: 512},
center = {lat: 37.76487, lon: -122.41948},
zoom = 12,
zoomFraction = 0,
zoomFactor = 1, // Math.pow(2, zoomFraction)
zoomRange = [1, 18],
angle = 0,
angleCos = 1, // Math.cos(angle)
angleSin = 0, // Math.sin(angle)
angleCosi = 1, // Math.cos(-angle)
angleSini = 0, // Math.sin(-angle)
ymin = -180, // lat2y(centerRange[0].lat)
ymax = 180; // lat2y(centerRange[1].lat)
var centerRange = [
{lat: y2lat(ymin), lon: -Infinity},
{lat: y2lat(ymax), lon: Infinity}
];
var interact = ms.interact();
if (typeof mapContainer === "string")
container = document.querySelector(mapContainer);
else
container = mapContainer;
if (!container)
throw new Error("Invalid map container.");
map.interact = function(x) {
if (!arguments.length) return interact;
interact.map(x ? map : null);
};
map.locationCoordinate = function(l) {
var c = ms.map.locationCoordinate(l),
k = Math.pow(2, zoom);
c.column *= k;
c.row *= k;
c.zoom += zoom;
return c;
};
map.coordinateLocation = ms.map.coordinateLocation;
map.coordinatePoint = function(tileCenter, c) {
var kc = Math.pow(2, zoom - c.zoom),
kt = Math.pow(2, zoom - tileCenter.zoom),
dx = (c.column * kc - tileCenter.column * kt) * tileSize.x * zoomFactor,
dy = (c.row * kc - tileCenter.row * kt) * tileSize.y * zoomFactor;
return {
x: sizeRadius.x + angleCos * dx - angleSin * dy,
y: sizeRadius.y + angleSin * dx + angleCos * dy
};
};
map.pointCoordinate = function(tileCenter, p) {
var kt = Math.pow(2, zoom - tileCenter.zoom),
dx = (p.x - sizeRadius.x) / zoomFactor,
dy = (p.y - sizeRadius.y) / zoomFactor;
return {
column: tileCenter.column * kt + (angleCosi * dx - angleSini * dy) / tileSize.x,
row: tileCenter.row * kt + (angleSini * dx + angleCosi * dy) / tileSize.y,
zoom: zoom
};
};
map.locationPoint = function(l) {
var k = Math.pow(2, zoom + zoomFraction - 3) / 45,
dx = (l.lon - center.lon) * k * tileSize.x,
dy = (lat2y(center.lat) - lat2y(l.lat)) * k * tileSize.y;
return {
x: sizeRadius.x + angleCos * dx - angleSin * dy,
y: sizeRadius.y + angleSin * dx + angleCos * dy
};
};
map.pointLocation = function(p) {
var k = 45 / Math.pow(2, zoom + zoomFraction - 3),
dx = (p.x - sizeRadius.x) * k,
dy = (p.y - sizeRadius.y) * k;
return {
lon: center.lon + (angleCosi * dx - angleSini * dy) / tileSize.x,
lat: y2lat(lat2y(center.lat) - (angleSini * dx + angleCosi * dy) / tileSize.y)
};
};
function rezoom() {
if (zoomRange) {
if (zoom < zoomRange[0]) zoom = zoomRange[0];
else if (zoom > zoomRange[1]) zoom = zoomRange[1];
}
zoomFraction = zoom - (zoom = Math.round(zoom));
zoomFactor = Math.pow(2, zoomFraction);
}
function recenter() {
if (!centerRange) return;
var k = 45 / Math.pow(2, zoom + zoomFraction - 3);
// constrain latitude
var y = Math.max(Math.abs(angleSin * sizeRadius.x + angleCos * sizeRadius.y),
Math.abs(angleSini * sizeRadius.x + angleCosi * sizeRadius.y)),
lat0 = y2lat(ymin - y * k / tileSize.y),
lat1 = y2lat(ymax + y * k / tileSize.y);
center.lat = Math.max(lat0, Math.min(lat1, center.lat));
// constrain longitude
var x = Math.max(Math.abs(angleSin * sizeRadius.y + angleCos * sizeRadius.x),
Math.abs(angleSini * sizeRadius.y + angleCosi * sizeRadius.x)),
lon0 = centerRange[0].lon - x * k / tileSize.x,
lon1 = centerRange[1].lon + x * k / tileSize.x;
center.lon = Math.max(lon0, Math.min(lon1, center.lon));
}
// a place to capture mouse events if no tiles exist
var rect = ms.svg("rect");
rect.setAttribute("visibility", "hidden");
rect.setAttribute("pointer-events", "all");
var svgContainer = ms.svg("svg");
svgContainer.setAttribute("class", "mapsense-map");
svgContainer.appendChild(rect);
var relativeContainer = document.createElement("div");
relativeContainer.style.setProperty("position", "relative");
relativeContainer.style.setProperty("width", "100%");
relativeContainer.style.setProperty("height", "100%");
relativeContainer.appendChild(svgContainer);
container.appendChild(relativeContainer);
map.container = function() {
return container;
};
map.relativeContainer = function() {
return relativeContainer;
};
map.svgContainer = function() {
return svgContainer;
};
map.focusableParent = function() {
for (var p = container; p; p = p.parentNode) {
if (p.tabIndex >= 0) return p;
}
return window;
};
map.mouse = function(e) {
var point = (svgContainer.ownerSVGElement || svgContainer).createSVGPoint();
if ((bug44083 < 0) && (window.scrollX || window.scrollY)) {
var svg = document.body.appendChild(ms.svg("svg"));
svg.style.position = "absolute";
svg.style.top = svg.style.left = "0px";
var ctm = svg.getScreenCTM();
bug44083 = !(ctm.f || ctm.e);
document.body.removeChild(svg);
}
if (bug44083) {
point.x = e.pageX;
point.y = e.pageY;
} else {
point.x = e.clientX;
point.y = e.clientY;
}
return point.matrixTransform(svgContainer.getScreenCTM().inverse());
};
map.size = function(x) {
if (!arguments.length) return sizeActual;
size = x;
return map.resize(); // size tiles
};
map.resize = function() {
if (!size) {
rect.setAttribute("width", "100%");
rect.setAttribute("height", "100%");
var b = rect.getBBox();
sizeActual = {x: b.width, y: b.height};
resizer.add(map);
} else {
sizeActual = size;
resizer.remove(map);
}
rect.setAttribute("width", sizeActual.x);
rect.setAttribute("height", sizeActual.y);
sizeRadius = {x: sizeActual.x / 2, y: sizeActual.y / 2};
recenter();
map.dispatch({type: "resize"});
return map;
};
map.tileSize = function(x) {
if (!arguments.length) return tileSize;
tileSize = x;
map.dispatch({type: "move"});
return map;
};
map.center = function(x) {
if (!arguments.length) return center;
center = x;
recenter();
map.dispatch({type: "move"});
return map;
};
map.panBy = function(x) {
var k = 45 / Math.pow(2, zoom + zoomFraction - 3),
dx = x.x * k,
dy = x.y * k;
return map.center({
lon: center.lon + (angleSini * dy - angleCosi * dx) / tileSize.x,
lat: y2lat(lat2y(center.lat) + (angleSini * dx + angleCosi * dy) / tileSize.y)
});
};
map.centerRange = function(x) {
if (!arguments.length) return centerRange;
centerRange = x;
if (centerRange) {
ymin = centerRange[0].lat > -90 ? lat2y(centerRange[0].lat) : -Infinity;
ymax = centerRange[0].lat < 90 ? lat2y(centerRange[1].lat) : Infinity;
} else {
ymin = -Infinity;
ymax = Infinity;
}
recenter();
map.dispatch({type: "move"});
return map;
};
map.zoom = function(x) {
if (!arguments.length) return zoom + zoomFraction;
zoom = x;
rezoom();
return map.center(center);
};
map.zoomBy = function(z, x0, l) {
if (arguments.length < 2) return map.zoom(zoom + zoomFraction + z);
// compute the location of x0
if (arguments.length < 3) l = map.pointLocation(x0);
// update the zoom level
zoom = zoom + zoomFraction + z;
rezoom();
// compute the new point of the location
var x1 = map.locationPoint(l);
return map.panBy({x: x0.x - x1.x, y: x0.y - x1.y});
};
map.zoomRange = function(x) {
if (!arguments.length) return zoomRange;
zoomRange = x;
return map.zoom(zoom + zoomFraction);
};
map.extent = function(x) {
if (!arguments.length) return [
map.pointLocation({x: 0, y: sizeActual.y}),
map.pointLocation({x: sizeActual.x, y: 0})
];
// compute the extent in points, scale factor, and center
var bl = map.locationPoint(x[0]),
tr = map.locationPoint(x[1]),
k = Math.max((tr.x - bl.x) / sizeActual.x, (bl.y - tr.y) / sizeActual.y),
l = map.pointLocation({x: (bl.x + tr.x) / 2, y: (bl.y + tr.y) / 2});
// update the zoom level
zoom = zoom + zoomFraction - Math.log(k) / Math.LN2;
rezoom();
// set the new center
return map.center(l);
};
map.angle = function(x) {
if (!arguments.length) return angle;
angle = x;
angleCos = Math.cos(angle);
angleSin = Math.sin(angle);
angleCosi = Math.cos(-angle);
angleSini = Math.sin(-angle);
recenter();
map.dispatch({type: "move"});
return map;
};
map.add = function(x) {
x.map(map);
return map;
};
map.remove = function(x) {
x.map(null);
return map;
};
map.dispatch = ms.dispatch(map);
map.interact(true);
return map.resize(); // infer size
};
function resizer(e) {
for (var i = 0; i < resizer.maps.length; i++) {
resizer.maps[i].resize();
}
}
resizer.maps = [];
resizer.add = function(map) {
for (var i = 0; i < resizer.maps.length; i++) {
if (resizer.maps[i] == map) return;
}
resizer.maps.push(map);
};
resizer.remove = function(map) {
for (var i = 0; i < resizer.maps.length; i++) {
if (resizer.maps[i] == map) {
resizer.maps.splice(i, 1);
return;
}
}
};
// Note: assumes single window (no frames, iframes, etc.)!
if (window.addEventListener) {
window.addEventListener("resize", resizer, false);
window.addEventListener("load", resizer, false);
}
// See http://wiki.openstreetmap.org/wiki/Mercator
function y2lat(y) {
return 360 / Math.PI * Math.atan(Math.exp(y * Math.PI / 180)) - 90;
}
function lat2y(lat) {
return 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360));
}
ms.map.locationCoordinate = function(l) {
var k = 1 / 360;
return {
column: (l.lon + 180) * k,
row: (180 - lat2y(l.lat)) * k,
zoom: 0
};
};
ms.map.coordinateLocation = function(c) {
var k = 45 / Math.pow(2, c.zoom - 3);
return {
lon: k * c.column - 180,
lat: y2lat(180 - k * c.row)
};
};
// https://bugs.webkit.org/show_bug.cgi?id=44083
var bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
ms.layer = function(load, unload) {
var layer = {},
cache = layer.cache = ms.cache(load, unload).size(512),
tile = true,
visible = true,
zoom,
id,
map,
container = ms.svg("g"),
transform,
levelZoom,
levels = {};
container.setAttribute("class", "layer");
for (var i = -4; i <= -1; i++) levels[i] = container.appendChild(ms.svg("g"));
for (var i = 2; i >= 1; i--) levels[i] = container.appendChild(ms.svg("g"));
levels[0] = container.appendChild(ms.svg("g"));
function zoomIn(z) {
var end = levels[0].nextSibling;
for (; levelZoom < z; levelZoom++) {
// -4, -3, -2, -1, +2, +1, =0 // current order
// -3, -2, -1, +2, +1, =0, -4 // insertBefore(-4, end)
// -3, -2, -1, +1, =0, -4, +2 // insertBefore(+2, end)
// -3, -2, -1, =0, -4, +2, +1 // insertBefore(+1, end)
// -4, -3, -2, -1, +2, +1, =0 // relabel
container.insertBefore(levels[-4], end);
container.insertBefore(levels[2], end);
container.insertBefore(levels[1], end);
var t = levels[-4];
for (var dz = -4; dz < 2;) levels[dz] = levels[++dz];
levels[dz] = t;
}
}
function zoomOut(z) {
var end = levels[0].nextSibling;
for (; levelZoom > z; levelZoom--) {
// -4, -3, -2, -1, +2, +1, =0 // current order
// -4, -3, -2, +2, +1, =0, -1 // insertBefore(-1, end)
// +2, -4, -3, -2, +1, =0, -1 // insertBefore(+2, -4)
// -4, -3, -2, -1, +2, +1, =0 // relabel
container.insertBefore(levels[-1], end);
container.insertBefore(levels[2], levels[-4]);
var t = levels[2];
for (var dz = 2; dz > -4;) levels[dz] = levels[--dz];
levels[dz] = t;
}
}
function move() {
var map = layer.map(), // in case the layer is removed
mapZoom = map.zoom(),
mapZoomFraction = mapZoom - (mapZoom = Math.round(mapZoom)),
mapSize = map.size(),
mapAngle = map.angle(),
tileSize = map.tileSize(),
tileCenter = map.locationCoordinate(map.center());
// set the layer zoom levels
if (levelZoom != mapZoom) {
if (levelZoom < mapZoom) zoomIn(mapZoom);
else if (levelZoom > mapZoom) zoomOut(mapZoom);
else levelZoom = mapZoom;
for (var z = -4; z <= 2; z++) {
var l = levels[z];
l.setAttribute("class", "zoom" + (z < 0 ? "" : "+") + z + " zoom" + (mapZoom + z));
l.setAttribute("transform", "scale(" + Math.pow(2, -z) + ")");
}
}
// get the coordinates of the four corners
var c0 = map.pointCoordinate(tileCenter, zero),
c1 = map.pointCoordinate(tileCenter, {x: mapSize.x, y: 0}),
c2 = map.pointCoordinate(tileCenter, mapSize),
c3 = map.pointCoordinate(tileCenter, {x: 0, y: mapSize.y});
var col = tileCenter.column, row = tileCenter.row;
tileCenter.column = Math.round((Math.round(tileSize.x * tileCenter.column) + (mapSize.x & 1) / 2) / tileSize.x);
tileCenter.row = Math.round((Math.round(tileSize.y * tileCenter.row) + (mapSize.y & 1) / 2) / tileSize.y);
col -= tileCenter.column;
row -= tileCenter.row;
// set the layer transform
var roundedZoomFraction = roundZoom(Math.pow(2, mapZoomFraction));
container.setAttribute("transform",
"translate(" +
Math.round(mapSize.x / 2 - col * tileSize.x * roundedZoomFraction) +
"," +
Math.round(mapSize.y / 2 - row * tileSize.y * roundedZoomFraction) +
")" +
(mapAngle ? "rotate(" + mapAngle / Math.PI * 180 + ")" : "") +
(mapZoomFraction ? "scale(" + roundedZoomFraction + ")" : "") +
(transform ? transform.zoomFraction(mapZoomFraction) : ""));
// layer-specific coordinate transform
if (transform) {
c0 = transform.unapply(c0);
c1 = transform.unapply(c1);
c2 = transform.unapply(c2);
c3 = transform.unapply(c3);
tileCenter = transform.unapply(tileCenter);
}
// layer-specific zoom transform
var tileLevel = zoom ? zoom(c0.zoom) - c0.zoom : 0;
if (tileLevel) {
var k = Math.pow(2, tileLevel);
c0.column *= k; c0.row *= k;
c1.column *= k; c1.row *= k;
c2.column *= k; c2.row *= k;
c3.column *= k; c3.row *= k;
c0.zoom = c1.zoom = c2.zoom = c3.zoom += tileLevel;
}
// tile-specific projection
function projection(c) {
var zoom = c.zoom,
max = zoom < 0 ? 1 : 1 << zoom,
column = c.column % max,
row = c.row;
if (column < 0) column += max;
return {
locationPoint: function(l) {
var c = ms.map.locationCoordinate(l),
k = Math.pow(2, zoom - c.zoom);
return {
x: tileSize.x * (k * c.column - column),
y: tileSize.y * (k * c.row - row)
};
}
};
}
// record which tiles are visible
var oldLocks = cache.locks(), newLocks = {};
// reset the proxy counts
for (var key in oldLocks) {
oldLocks[key].proxyCount = 0;
}
// load the tiles!
if (visible && tileLevel > -5 && tileLevel < 3) {
var ymax = c0.zoom < 0 ? 1 : 1 << c0.zoom;
if (tile) {
scanTriangle(c0, c1, c2, 0, ymax, scanLine);
scanTriangle(c2, c3, c0, 0, ymax, scanLine);
} else {
var x = Math.floor((c0.column + c2.column) / 2),
y = Math.max(0, Math.min(ymax - 1, Math.floor((c1.row + c3.row) / 2))),
z = Math.min(4, c0.zoom);
x = x >> z << z;
y = y >> z << z;
scanLine(x, x + 1, y);
}
}
// scan-line conversion
function scanLine(x0, x1, y) {
var z = c0.zoom,
z0 = 2 - tileLevel,
z1 = 4 + tileLevel;
for (var x = x0; x < x1; x++) {
var t = cache.load({column: x, row: y, zoom: z}, projection);
if (!t.ready && !(t.key in newLocks)) {
t.proxyRefs = {};
var c, full, proxy;
// downsample high-resolution tiles
for (var dz = 1; dz <= z0; dz++) {
full = true;
for (var dy = 0, k = 1 << dz; dy <= k; dy++) {
for (var dx = 0; dx <= k; dx++) {
proxy = cache.peek(c = {
column: (x << dz) + dx,
row: (y << dz) + dy,
zoom: z + dz
});
if (proxy && proxy.ready) {
newLocks[proxy.key] = cache.load(c);
proxy.proxyCount++;
t.proxyRefs[proxy.key] = proxy;
} else {
full = false;
}
}
}
if (full) break;
}
// upsample low-resolution tiles
if (!full) {
for (var dz = 1; dz <= z1; dz++) {
proxy = cache.peek(c = {
column: x >> dz,
row: y >> dz,
zoom: z - dz
});
if (proxy && proxy.ready) {
newLocks[proxy.key] = cache.load(c);
proxy.proxyCount++;
t.proxyRefs[proxy.key] = proxy;
break;
}
}
}
}
newLocks[t.key] = t;
}
}
function roundZoom(z) {
return Math.round(z * 256) / 256;
}
// position tiles
for (var key in newLocks) {
var t = newLocks[key],
k = roundZoom(Math.pow(2, t.level = t.zoom - tileCenter.zoom));
var transform = "translate(" +
Math.round(t.x = tileSize.x * (t.column - tileCenter.column * k)) + "px" + "," +
Math.round(t.y = tileSize.y * (t.row - tileCenter.row * k)) + "px" + ")";
d3.select(t.element).style("transform", transform);
d3.select(t.element).style("-webkit-transform", transform);
d3.select(t.element).style("-ms-transform", transform);
}
// remove tiles that are no longer visible
for (var key in oldLocks) {
if (!(key in newLocks)) {
var t = cache.unload(key);
t.element.parentNode.removeChild(t.element);
delete t.proxyRefs;
}
}
// append tiles that are now visible
for (var key in newLocks) {
var t = newLocks[key];
if (t.element.parentNode != levels[t.level]) {
levels[t.level].appendChild(t.element);
if (layer.show) layer.show(t);
}
}
// flush the cache, clearing no-longer-needed tiles
cache.flush();
// dispatch the move event
layer.dispatch({type: "move"});
}
// remove proxy tiles when tiles load
function cleanup(e) {
if (e.tile.proxyRefs) {
for (var proxyKey in e.tile.proxyRefs) {
var proxyTile = e.tile.proxyRefs[proxyKey];
if ((--proxyTile.proxyCount <= 0) && cache.unload(proxyKey)) {
proxyTile.element.parentNode.removeChild(proxyTile.element);
}
}
delete e.tile.proxyRefs;
}
}
layer.map = function(x) {
if (!arguments.length) return map;
if (map) {
if (map == x) {
container.parentNode.appendChild(container); // move to end
return layer;
}
map.off("move", move).off("resize", move);
container.parentNode.removeChild(container);
}
map = x;
if (map) {
map.svgContainer().appendChild(container);
if (layer.init) layer.init(container);
map.on("move", move).on("resize", move);
move();
}
return layer;
};
layer.container = function() {
return container;
};
layer.levels = function() {
return levels;
};
layer.id = function(x) {
if (!arguments.length) return id;
id = x;
container.setAttribute("id", x);
return layer;
};
layer.visible = function(x) {
if (!arguments.length) return visible;
if (visible = x) container.removeAttribute("visibility");
else container.setAttribute("visibility", "hidden");
if (map) move();
return layer;
};
layer.transform = function(x) {
if (!arguments.length) return transform;
transform = x;
if (map) move();
return layer;
};
layer.zoom = function(x) {
if (!arguments.length) return zoom;
zoom = typeof x == "function" || x == null ? x : function() { return x; };
if (map) move();
return layer;
};
layer.tile = function(x) {
if (!arguments.length) return tile;
tile = x;
if (map) move();
return layer;
};
layer.reload = function() {
cache.clear();
if (map) move();
return layer;
};
layer.dispatch = ms.dispatch(layer);
layer.on("load", cleanup);
return layer;
};
// scan-line conversion
function edge(a, b) {
if (a.row > b.row) { var t = a; a = b; b = t; }
return {
x0: a.column,
y0: a.row,
x1: b.column,
y1: b.row,
dx: b.column - a.column,
dy: b.row - a.row
};
}
// scan-line conversion
function scanSpans(e0, e1, ymin, ymax, scanLine) {
var y0 = Math.max(ymin, Math.floor(e1.y0)),
y1 = Math.min(ymax, Math.ceil(e1.y1));
// sort edges by x-coordinate
if ((e0.x0 == e1.x0 && e0.y0 == e1.y0) ?
(e0.x0 + e1.dy / e0.dy * e0.dx < e1.x1) :
(e0.x1 - e1.dy / e0.dy * e0.dx < e1.x0)) {
var t = e0; e0 = e1; e1 = t;
}
// scan lines!
var m0 = e0.dx / e0.dy,
m1 = e1.dx / e1.dy,
d0 = e0.dx > 0, // use y + 1 to compute x0
d1 = e1.dx < 0; // use y + 1 to compute x1
for (var y = y0; y < y1; y++) {
var x0 = m0 * Math.max(0, Math.min(e0.dy, y + d0 - e0.y0)) + e0.x0,
x1 = m1 * Math.max(0, Math.min(e1.dy, y + d1 - e1.y0)) + e1.x0;
scanLine(Math.floor(x1), Math.ceil(x0), y);
}
}
// scan-line conversion
function scanTriangle(a, b, c, ymin, ymax, scanLine) {
var ab = edge(a, b),
bc = edge(b, c),
ca = edge(c, a);
// sort edges by y-length
if (ab.dy > bc.dy) { var t = ab; ab = bc; bc = t; }
if (ab.dy > ca.dy) { var t = ab; ab = ca; ca = t; }
if (bc.dy > ca.dy) { var t = bc; bc = ca; ca = t; }
// scan span! scan span!
if (ab.dy) scanSpans(ca, ab, ymin, ymax, scanLine);
if (bc.dy) scanSpans(ca, bc, ymin, ymax, scanLine);
}
ms.image = function() {
var image = ms.layer(load, unload),
url;
function load(tile) {
var element = tile.element = ms.svg("image"), size = image.map().tileSize();
element.setAttribute("preserveAspectRatio", "none");
element.setAttribute("width", size.x);
element.setAttribute("height", size.y);
if (typeof url == "function") {
element.setAttribute("opacity", 0);
var tileUrl = url(tile);
if (tileUrl != null) {
tile.request = ms.queue.image(element, tileUrl, function(img) {
delete tile.request;
tile.ready = true;
tile.img = img;
element.removeAttribute("opacity");
image.dispatch({type: "load", tile: tile});
});
} else {
tile.ready = true;
image.dispatch({type: "load", tile: tile});
}
} else {
tile.ready = true;
if (url != null) element.setAttributeNS(ms.ns.xlink, "href", url);
image.dispatch({type: "load", tile: tile});
}
}
function unload(tile) {
if (tile.request) tile.request.abort(true);
}
image.url = function(x) {
if (!arguments.length) return url;
url = typeof x == "string" && /{.}/.test(x) ? ms.url(x) : x;
return image.reload();
};
return image;
};
ms.geoJson = function(fetch) {
var geoJson = ms.layer(load, unload),
container = geoJson.container(),
url,
clip = false,
clipId = "org.polymaps." + ms.id(),
clipHref = "url(#" + clipId + ")",
clipPath = container.insertBefore(ms.svg("clipPath"), container.firstChild),
clipRect = clipPath.appendChild(ms.svg("rect")),
scale = "fixed",
zoom = null,
pointRadius = 4.5,
features,
tileBackground = false,
transformData,
key = (function() {
var k = 0;
return function(f) { return k++; };
})(),
selection,
dataVersion = 0,
selectionVersion = 0;
container.setAttribute("fill-rule", "evenodd");
clipPath.setAttribute("id", clipId);
if (!arguments.length) fetch = ms.queue.json;
function projection(proj) {
var l = {lat: 0, lon: 0};
return function(coordinates, c) {
l.lat = coordinates[1];
l.lon = coordinates[0];
var p = proj(l);
c.x = p.x;
c.y = p.y;
return p;
};
}
function rescale(o, e, k) {
var g = o.geometry;
return g.type in rescales && rescales[g.type](o, e, k);
}
var rescales = {
Point: function (o, e, k) {
e.setAttribute("transform", "translate(" + o.x + "," + o.y + ")" + k);
},
MultiPoint: function (o, e, k) {
e.setAttribute("transform", "translate(" + o.x + "," + o.y + ")" + k);
}
};
// Create path projecting WGS84 spherical Mercator coordinates.
function projectSpherical(tileProj) {
return d3.geo.path().projection({
stream: function(stream) {
return {
point: function(x, y) {
// Latitudes at the poles (or beyond!) result in unrenderable NaN's and Infinities.
var epsilon = 1.0e-6;
y = Math.min(90 - epsilon, y);
y = Math.max(-90 + epsilon, y);
var p = tileProj.locationPoint({ lon: x, lat: y });
stream.point(Math.round(2 * p.x) / 2, Math.round(2 * p.y) / 2);
},
sphere: function() { stream.sphere(); },
lineStart: function() { stream.lineStart(); },
lineEnd: function() { stream.lineEnd(); },
polygonStart: function() { stream.polygonStart(); },
polygonEnd: function() { stream.polygonEnd(); }
};
}
});
}
function load(tile, proj) {
var g = tile.element = ms.svg("g");
tile.proj = proj(tile);
tile.fetched = []; // the output of the fetch function
tile.features = []; // { feature, element }
tile.draw = function() {
draw(g, tile);
};
function update(data) {
if (geoJson.tile() && tileBackground) {
var tileSize = geoJson.map().tileSize();
d3.select(g.insertBefore(ms.svg("rect"), g.firstChild))
.attr("width", tileSize.x)
.attr("height", tileSize.x)
.attr("class", "tile-background");
}
Array.prototype.push.apply(tile.fetched, data.features);
tile.draw();
tile.ready = true;
geoJson.dispatch({type: "load", tile: tile, features: tile.features});
}
if (url != null) {
tile.request = fetch(typeof url == "function" ? url(tile) : url, update);
} else {
update({type: "FeatureCollection", features: features || []});
}
}
function copyObject(source) {
var copy = {};
for (var property in source) {
copy[property] = source[property];
}
return copy;
}
function projectPoint(p, proj) {
proj(p.geometry.coordinates, p);
return p;
}
function projectPointsForMultiPoint(mp, proj) {
var length = mp.geometry.coordinates.length;
var points = [];
for (var i = 0; i < length; i++) {
var p = copyObject(mp);
proj(p.geometry.coordinates[i], p);
points.push(p);
}
return points;
}
function draw(g, tile) {
var proj = projection(tile.proj.locationPoint),
path = projectSpherical(tile.proj),
pathFeatures = [],
pointFeatures = [],
features = transformData? transformData(tile.fetched, tile) : tile.fetched,
updated = [];
features.forEach(function(f) {
if (f.geometry.type === "Point")
pointFeatures.push(projectPoint(f, proj));
else if (f.geometry.type === "MultiPoint")
pointFeatures.push.apply(pointFeatures, projectPointsForMultiPoint(f, proj));
else
pathFeatures.push(f);
});
var pathUpdate = d3.select(g)
.selectAll("path")
.data(pathFeatures, key);
pathUpdate
.enter()
.append("path")
.attr("d", function(f) { return path(f); });
pathUpdate.exit().remove();
pathUpdate.each(function(f) { updated.push({ element: this, data: f }); });
var initialScale = "";
if (scale == "fixed") {
initialScale = "scale(" + Math.pow(2, tile.zoom - (tile.scale = geoJson.map().zoom())) + ")";
}
var pointUpdate = d3.select(g)
.selectAll("circle")
.data(pointFeatures, key);
pointUpdate
.enter()
.append("circle")
.attr("transform", function(f) {
return "translate(" + f.x + "," + f.y + ")" + initialScale;
})
.attr("r", pointRadius);
pointUpdate.exit().remove();
pointUpdate.each(function(f) { updated.push({ element: this, data: f }); });
if (selection) {
pathUpdate.push.apply(pathUpdate, pointUpdate);
selection(pathUpdate);
}
tile.features = updated;
tile.dataVersion = dataVersion;
tile.selectionVersion = selectionVersion;
}
function unload(tile) {
if (tile.request) tile.request.abort(true);
}
function move() {
var zoom = geoJson.map().zoom(),
tiles = geoJson.cache.locks(), // visible tiles
key, // key in locks
tile, // locks[key]
features, // tile.features
i, // current feature index
n, // current feature count, features.length
feature, // features[i]
k; // scale transform
if (scale == "fixed") {
for (key in tiles) {
if ((tile = tiles[key]).scale != zoom) {
k = "scale(" + Math.pow(2, tile.zoom - zoom) + ")";
i = -1;
n = (features = tile.features).length;
while (++i < n) rescale((feature = features[i]).data, feature.element, k);
tile.scale = zoom;
}
}
}
}
geoJson.tileBackground = function(x) {
if (!arguments.length) return tileBackground;
tileBackground = x;
return geoJson;
};
geoJson.selection = function(x) {
if (!arguments.length) return selection;
selection = x;
selectionVersion++;
return geoJson.reshow();
};
geoJson.transformData = function(x) {
if (!arguments.length) return transformData;
transformData = x;
dataVersion++;
return geoJson.reshow();
};
geoJson.url = function(x) {
if (!arguments.length) return url;
url = typeof x == "string" && /{.}/.test(x) ? ms.url(x) : x;
if (url != null) features = null;
if (typeof url == "string") geoJson.tile(false);
return geoJson.reload();
};
geoJson.features = function(x) {
if (!arguments.length) return features;
if (features = x) {
url = null;
geoJson.tile(false);
}
return geoJson.reload();
};
geoJson.clip = function(x) {
if (!arguments.length) return clip;
if (clip) container.removeChild(clipPath);
if (clip = x) container.insertBefore(clipPath, container.firstChild);
var locks = geoJson.cache.locks();
for (var key in locks) {
if (clip) locks[key].element.setAttribute("clip-path", clipHref);
else locks[key].element.removeAttribute("clip-path");
}
return geoJson;
};
var __tile__ = geoJson.tile;
geoJson.tile = function(x) {
if (arguments.length && !x) geoJson.clip(x);
return __tile__.apply(geoJson, arguments);
};
var __map__ = geoJson.map;
geoJson.map = function(x) {
if (x && clipRect) {
var size = x.tileSize();
clipRect.setAttribute("width", size.x);
clipRect.setAttribute("height", size.y);
}
return __map__.apply(geoJson, arguments);
};
geoJson.scale = function(x) {
if (!arguments.length) return scale;
if (scale = x) geoJson.on("move", move);
else geoJson.off("move", move);
if (geoJson.map()) move();
return geoJson;
};
geoJson.show = function(tile) {
if (clip) tile.element.setAttribute("clip-path", clipHref);
else tile.element.removeAttribute("clip-path");
if (transformData && tile.dataVersion != dataVersion) {
tile.draw();
} else if (selection && tile.selectionVersion != selectionVersion) {
var s = d3.select(tile.element).selectAll("path");
s.push.apply(s, d3.select(tile.element).selectAll("circle"));
selection(s);
tile.selectionVersion = selectionVersion;
}
geoJson.dispatch({type: "show", tile: tile, features: tile.features});
return geoJson;
};
geoJson.reshow = function() {
var locks = geoJson.cache.locks();
for (var key in locks) geoJson.show(locks[key]);
return geoJson;
};
return geoJson;
};
ms.topoJson = function(fetch) {
if (!arguments.length) fetch = ms.queue.json;
var classify,
staticTopology;
function groupFeatures(features) {
if (!classify)
return features;
var classIndices = {};
var groupedFeatures = [];
features.forEach(function(f) {
var c = classify(f);
var index = classIndices[c];
if (index === undefined) {
index = groupedFeatures.push([]) - 1;
classIndices[c] = index;
}
groupedFeatures[index].push(f);
});
return groupedFeatures.map(function(g) {
return {
type: 'GeometryCollection',
geometries: g
};
});
}
var topologyFeatures = function(topology) {
function convert(topology, object, layer, features) {
var featureOrCollection = topojson.feature(topology, object),
layerFeatures;
if (featureOrCollection.type === "FeatureCollection") {
layerFeatures = featureOrCollection.features;
} else {
layerFeatures = [featureOrCollection];
}
layerFeatures.forEach(function(f) {
f.properties.layer = layer;
});
features.push.apply(features, layerFeatures);
}
var features = [];
for (var o in topology.objects) {
convert(topology, topology.objects[o], o, features);
}
features = groupFeatures(features);
return features;
};
var topoToGeo = function(url, callback) {
return fetch(url, function(topology) {
callback({
type: "FeatureCollection",
features: topologyFeatures(topology)
});
});
};
var topoJson = ms.geoJson(topoToGeo);
topoJson.topologyFeatures = function(x) {
if (!arguments.length) return topologyFeatures;
topologyFeatures = x;
return topoJson;
};
topoJson.classify = function(x) {
if (!arguments.length) return classify;
classify = x;
return topoJson;
};
topoJson.staticTopology = function(x) {
if (!arguments.length) return staticTopology;
staticTopology = x;
return topoJson.features(staticTopology ? topologyFeatures(staticTopology) : null);
};
return topoJson;
};
ms.dblclick = function() {
var dblclick = {},
zoom = "mouse",
map,
container;
function handle(e) {
var z = map.zoom();
if (e.shiftKey) z = Math.ceil(z) - z - 1;
else z = 1 - z + Math.floor(z);
if (zoom === "mouse")
map.zoomBy(z, map.mouse(e));
else
map.zoomBy(z);
}
dblclick.zoom = function(x) {
if (!arguments.length) return zoom;
zoom = x;
return dblclick;
};
dblclick.map = function(x) {
if (!arguments.length) return map;
if (map) {
container.removeEventListener("dblclick", handle, false);
container = null;
}
if (map = x) {
container = map.container();
container.addEventListener("dblclick", handle, false);
}
return dblclick;
};
return dblclick;
};
ms.drag = function() {
var drag = {},
map,
container,
dragging;
function mousedown(e) {
if (e.shiftKey) return;
dragging = {
x: e.clientX,
y: e.clientY
};
map.focusableParent().focus();
e.preventDefault();
document.body.style.setProperty("cursor", "move", null);
}
function mousemove(e) {
if (!dragging) return;
map.panBy({x: e.clientX - dragging.x, y: e.clientY - dragging.y});
dragging.x = e.clientX;
dragging.y = e.clientY;
}
function mouseup(e) {
if (!dragging) return;
mousemove(e);
dragging = null;
document.body.style.removeProperty("cursor");
}
drag.map = function(x) {
if (!arguments.length) return map;
if (map) {
container.removeEventListener("mousedown", mousedown, false);
container = null;
}
if (map = x) {
container = map.container();
container.addEventListener("mousedown", mousedown, false);
}
return drag;
};
window.addEventListener("mousemove", mousemove, false);
window.addEventListener("mouseup", mouseup, false);
return drag;
};
ms.wheel = function() {
var wheel = {},
timePrev = 0,
last = 0,
smooth = true,
zoom = "mouse",
location,
map,
container;
function move(e) {
location = null;
}
// mousewheel events are totally broken!
// https://bugs.webkit.org/show_bug.cgi?id=40441
// not only that, but Chrome and Safari differ in re. to acceleration!
var inner = document.createElement("div"),
outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.top = "0px";
outer.style.height = "0px";
outer.style.width = "0px";
outer.style.overflowY = "scroll";
inner.style.height = "2000px";
outer.appendChild(inner);
document.body.appendChild(outer);
function mousewheel(e) {
var delta = e.wheelDelta || -e.detail,
point;
/* Detect the pixels that would be scrolled by this wheel event. */
if (delta) {
if (smooth) {
try {
outer.scrollTop = 1000;
outer.dispatchEvent(e);
delta = 1000 - outer.scrollTop;
} catch (error) {
// Derp! Hope for the best?
}
delta *= 0.001;
}
/* If smooth zooming is disabled, batch events into unit steps. */
else {
var timeNow = Date.now();
if (timeNow - timePrev > 200) {
delta = delta > 0 ? +1 : -1;
timePrev = timeNow;
} else {
delta = 0;
}
}
}
if (delta) {
switch (zoom) {
case "mouse": {
point = map.mouse(e);
if (!location) location = map.pointLocation(point);
map.off("move", move).zoomBy(delta, point, location).on("move", move);
break;
}
case "location": {
map.zoomBy(delta, map.locationPoint(location), location);
break;
}
default: { // center
map.zoomBy(delta);
break;
}
}
}
e.preventDefault();
return false; // for Firefox
}
wheel.smooth = function(x) {
if (!arguments.length) return smooth;
smooth = x;
return wheel;
};
wheel.zoom = function(x, l) {
if (!arguments.length) return zoom;
zoom = x;
location = l;
if (map) {
if (zoom == "mouse") map.on("move", move);
else map.off("move", move);
}
return wheel;
};
wheel.map = function(x) {
if (!arguments.length) return map;
if (map) {
container.removeEventListener("mousemove", move, false);
container.removeEventListener("mousewheel", mousewheel, false);
container.removeEventListener("MozMousePixelScroll", mousewheel, false);
container = null;
map.off("move", move);
}
if (map = x) {
if (zoom == "mouse") map.on("move", move);
container = map.container();
container.addEventListener("mousemove", move, false);
container.addEventListener("mousewheel", mousewheel, false);
container.addEventListener("MozMousePixelScroll", mousewheel, false);
}
return wheel;
};
return wheel;
};
ms.arrow = function() {
var arrow = {},
key = {left: 0, right: 0, up: 0, down: 0},
last = 0,
repeatTimer,
repeatDelay = 250,
repeatInterval = 50,
speed = 16,
map,
parent;
function keydown(e) {
if (e.ctrlKey || e.altKey || e.metaKey) return;
var now = Date.now(), dx = 0, dy = 0;
switch (e.keyCode) {
case 37: {
if (!key.left) {
last = now;
key.left = 1;
if (!key.right) dx = speed;
}
break;
}
case 39: {
if (!key.right) {
last = now;
key.right = 1;
if (!key.left) dx = -speed;
}
break;
}
case 38: {
if (!key.up) {
last = now;
key.up = 1;
if (!key.down) dy = speed;
}
break;
}
case 40: {
if (!key.down) {
last = now;
key.down = 1;
if (!key.up) dy = -speed;
}
break;
}
default: return;
}
if (dx || dy) map.panBy({x: dx, y: dy});
if (!repeatTimer && (key.left | key.right | key.up | key.down)) {
repeatTimer = setInterval(repeat, repeatInterval);
}
e.preventDefault();
}
function keyup(e) {
last = Date.now();
switch (e.keyCode) {
case 37: key.left = 0; break;
case 39: key.right = 0; break;
case 38: key.up = 0; break;
case 40: key.down = 0; break;
default: return;
}
if (repeatTimer && !(key.left | key.right | key.up | key.down)) {
repeatTimer = clearInterval(repeatTimer);
}
e.preventDefault();
}
function keypress(e) {
switch (e.charCode) {
case 45: case 95: map.zoom(Math.ceil(map.zoom()) - 1); break; // - _
case 43: case 61: map.zoom(Math.floor(map.zoom()) + 1); break; // = +
default: return;
}
e.preventDefault();
}
function repeat() {
if (!map) return;
if (Date.now() < last + repeatDelay) return;
var dx = (key.left - key.right) * speed,
dy = (key.up - key.down) * speed;
if (dx || dy) map.panBy({x: dx, y: dy});
}
arrow.map = function(x) {
if (!arguments.length) return map;
if (map) {
parent.removeEventListener("keypress", keypress, false);
parent.removeEventListener("keydown", keydown, false);
parent.removeEventListener("keyup", keyup, false);
parent = null;
}
if (map = x) {
parent = map.focusableParent();
parent.addEventListener("keypress", keypress, false);
parent.addEventListener("keydown", keydown, false);
parent.addEventListener("keyup", keyup, false);
}
return arrow;
};
arrow.speed = function(x) {
if (!arguments.length) return speed;
speed = x;
return arrow;
};
return arrow;
};
ms.hash = function() {
var hash = {},
s0, // cached location.hash
lat = 90 - 1e-8, // allowable latitude range
map;
var parser = function(map, s) {
var args = s.split("/").map(Number);
if (args.length < 3 || args.some(isNaN)) return true; // replace bogus hash
else {
var size = map.size();
map.zoomBy(args[0] - map.zoom(),
{x: size.x / 2, y: size.y / 2},
{lat: Math.min(lat, Math.max(-lat, args[1])), lon: args[2]});
}
};
var formatter = function(map) {
var center = map.center(),
zoom = map.zoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
return "#" + zoom.toFixed(2) +
"/" + center.lat.toFixed(precision) +
"/" + center.lon.toFixed(precision);
};
function move() {
var s1 = formatter(map);
if (s0 !== s1) location.replace(s0 = s1); // don't recenter the map!
}
function hashchange() {
if (location.hash === s0) return; // ignore spurious hashchange events
if (parser(map, (s0 = location.hash).substring(1)))
move(); // replace bogus hash
}
hash.map = function(x) {
if (!arguments.length) return map;
if (map) {
map.off("move", move);
window.removeEventListener("hashchange", hashchange, false);
}
if (map = x) {
map.on("move", move);
window.addEventListener("hashchange", hashchange, false);
if (location.hash)
hashchange();
else
move();
}
return hash;
};
hash.parser = function(x) {
if (!arguments.length) return parser;
parser = x;
return hash;
};
hash.formatter = function(x) {
if (!arguments.length) return formatter;
formatter = x;
return hash;
};
return hash;
};
ms.touch = function() {
var touch = {},
map,
container,
rotate = false,
last = 0,
zoom,
angle,
locations = {}; // touch identifier -> location
window.addEventListener("touchmove", touchmove, false);
function touchstart(e) {
var i = -1,
n = e.touches.length,
t = Date.now();
// doubletap detection
if ((n == 1) && (t - last < 300)) {
var z = map.zoom();
map.zoomBy(1 - z + Math.floor(z), map.mouse(e.touches[0]));
e.preventDefault();
}
last = t;
// store original zoom & touch locations
zoom = map.zoom();
angle = map.angle();
while (++i < n) {
t = e.touches[i];
locations[t.identifier] = map.pointLocation(map.mouse(t));
}
}
function touchmove(e) {
switch (e.touches.length) {
case 1: { // single-touch pan
var t0 = e.touches[0];
map.zoomBy(0, map.mouse(t0), locations[t0.identifier]);
e.preventDefault();
break;
}
case 2: { // double-touch pan + zoom + rotate
var t0 = e.touches[0],
t1 = e.touches[1],
p0 = map.mouse(t0),
p1 = map.mouse(t1),
p2 = {x: (p0.x + p1.x) / 2, y: (p0.y + p1.y) / 2}, // center point
c0 = ms.map.locationCoordinate(locations[t0.identifier]),
c1 = ms.map.locationCoordinate(locations[t1.identifier]),
c2 = {row: (c0.row + c1.row) / 2, column: (c0.column + c1.column) / 2, zoom: 0},
l2 = ms.map.coordinateLocation(c2); // center location
map.zoomBy(Math.log(e.scale) / Math.LN2 + zoom - map.zoom(), p2, l2);
if (rotate) map.angle(e.rotation / 180 * Math.PI + angle);
e.preventDefault();
break;
}
}
}
touch.rotate = function(x) {
if (!arguments.length) return rotate;
rotate = x;
return touch;
};
touch.map = function(x) {
if (!arguments.length) return map;
if (map) {
container.removeEventListener("touchstart", touchstart, false);
container = null;
}
if (map = x) {
container = map.container();
container.addEventListener("touchstart", touchstart, false);
}
return touch;
};
return touch;
};
// Default map controls.
ms.interact = function() {
var interact = {},
drag = ms.drag(),
wheel = ms.wheel(),
dblclick = ms.dblclick(),
touch = ms.touch(),
arrow = ms.arrow();
interact.map = function(x) {
drag.map(x);
wheel.map(x);
dblclick.map(x);
touch.map(x);
arrow.map(x);
return interact;
};
return interact;
};
ms.compass = function() {
var compass = {},
g = ms.svg("g"),
ticks = {},
r = 30,
speed = 16,
last = 0,
repeatDelay = 250,
repeatInterval = 50,
position = "top-left", // top-left, top-right, bottom-left, bottom-right
zoomStyle = "small", // none, small, big
zoomContainer,
panStyle = "small", // none, small
panTimer,
panDirection,
panContainer,
drag,
dragRect = ms.svg("rect"),
map,
container,
window;
g.setAttribute("class", "compass");
dragRect.setAttribute("class", "back fore");
dragRect.setAttribute("pointer-events", "none");
dragRect.setAttribute("display", "none");
function panStart(e) {
g.setAttribute("class", "compass active");
if (!panTimer) panTimer = setInterval(panRepeat, repeatInterval);
if (panDirection) map.panBy(panDirection);
last = Date.now();
return cancel(e);
}
function panRepeat() {
if (panDirection && (Date.now() > last + repeatDelay)) {
map.panBy(panDirection);
}
}
function mousedown(e) {
if (e.shiftKey) {
drag = {x0: map.mouse(e)};
map.focusableParent().focus();
return cancel(e);
}
}
function mousemove(e) {
if (!drag) return;
drag.x1 = map.mouse(e);
dragRect.setAttribute("x", Math.min(drag.x0.x, drag.x1.x));
dragRect.setAttribute("y", Math.min(drag.x0.y, drag.x1.y));
dragRect.setAttribute("width", Math.abs(drag.x0.x - drag.x1.x));
dragRect.setAttribute("height", Math.abs(drag.x0.y - drag.x1.y));
dragRect.removeAttribute("display");
}
function mouseup(e) {
g.setAttribute("class", "compass");
if (drag) {
if (drag.x1) {
map.extent([
map.pointLocation({
x: Math.min(drag.x0.x, drag.x1.x),
y: Math.max(drag.x0.y, drag.x1.y)
}),
map.pointLocation({
x: Math.max(drag.x0.x, drag.x1.x),
y: Math.min(drag.x0.y, drag.x1.y)
})
]);
dragRect.setAttribute("display", "none");
}
drag = null;
}
if (panTimer) {
clearInterval(panTimer);
panTimer = 0;
}
}
function panBy(x) {
return function() {
if (x)
this.setAttribute("class", "active");
else
this.removeAttribute("class");
panDirection = x;
};
}
function zoomBy(x) {
return function(e) {
g.setAttribute("class", "compass active");
var z = map.zoom();
map.zoom(x < 0 ? Math.ceil(z) - 1 : Math.floor(z) + 1);
return cancel(e);
};
}
function zoomTo(x) {
return function(e) {
map.zoom(x);
return cancel(e);
};
}
function zoomOver() {
this.setAttribute("class", "active");
}
function zoomOut() {
this.removeAttribute("class");
}
function cancel(e) {
e.stopPropagation();
e.preventDefault();
return false;
}
function pan(by) {
var x = Math.SQRT1_2 * r,
y = r * 0.7,
z = r * 0.2,
g = ms.svg("g"),
dir = g.appendChild(ms.svg("path")),
chv = g.appendChild(ms.svg("path"));
dir.setAttribute("class", "direction");
dir.setAttribute("pointer-events", "all");
dir.setAttribute("d", "M0,0L" + x + "," + x + "A" + r + "," + r + " 0 0,1 " + -x + "," + x + "Z");
chv.setAttribute("class", "chevron");
chv.setAttribute("d", "M" + z + "," + (y - z) + "L0," + y + " " + -z + "," + (y - z));
chv.setAttribute("pointer-events", "none");
g.addEventListener("mousedown", panStart, false);
g.addEventListener("mouseover", panBy(by), false);
g.addEventListener("mouseout", panBy(null), false);
g.addEventListener("dblclick", cancel, false);
return g;
}
function zoom(by) {
var x = r * 0.4,
y = x / 2,
g = ms.svg("g"),
back = g.appendChild(ms.svg("path")),
dire = g.appendChild(ms.svg("path")),
chev = g.appendChild(ms.svg("path")),
fore = g.appendChild(ms.svg("path"));
back.setAttribute("class", "back");
back.setAttribute("d", "M" + -x + ",0V" + -x + "A" + x + "," + x + " 0 1,1 " + x + "," + -x + "V0Z");
dire.setAttribute("class", "direction");
dire.setAttribute("d", back.getAttribute("d"));
chev.setAttribute("class", "chevron");
chev.setAttribute("d", "M" + -y + "," + -x + "H" + y + (by > 0 ? "M0," + (-x - y) + "V" + -y : ""));
fore.setAttribute("class", "fore");
fore.setAttribute("fill", "none");
fore.setAttribute("d", back.getAttribute("d"));
g.addEventListener("mousedown", zoomBy(by), false);
g.addEventListener("mouseover", zoomOver, false);
g.addEventListener("mouseout", zoomOut, false);
g.addEventListener("dblclick", cancel, false);
return g;
}
function tick(i) {
var x = r * 0.2,
y = r * 0.4,
g = ms.svg("g"),
back = g.appendChild(ms.svg("rect")),
chev = g.appendChild(ms.svg("path"));
back.setAttribute("pointer-events", "all");
back.setAttribute("fill", "none");
back.setAttribute("x", -y);
back.setAttribute("y", -0.75 * y);
back.setAttribute("width", 2 * y);
back.setAttribute("height", 1.5 * y);
chev.setAttribute("class", "chevron");
chev.setAttribute("d", "M" + -x + ",0H" + x);
g.addEventListener("mousedown", zoomTo(i), false);
g.addEventListener("dblclick", cancel, false);
return g;
}
function move() {
var x = r + 6, y = x, size = map.size();
switch (position) {
case "top-left": break;
case "top-right": x = size.x - x; break;
case "bottom-left": y = size.y - y; break;
case "bottom-right": x = size.x - x; y = size.y - y; break;
}
g.setAttribute("transform", "translate(" + x + "," + y + ")");
dragRect.setAttribute("transform", "translate(" + -x + "," + -y + ")");
for (var i in ticks) {
if (i == map.zoom())
ticks[i].setAttribute("class", "active");
else
ticks[i].removeAttribute("class");
}
}
function draw() {
while (g.lastChild) g.removeChild(g.lastChild);
g.appendChild(dragRect);
if (panStyle != "none") {
panContainer = g.appendChild(ms.svg("g"));
panContainer.setAttribute("class", "pan");
var back = panContainer.appendChild(ms.svg("circle"));
back.setAttribute("class", "back");
back.setAttribute("r", r);
var s = panContainer.appendChild(pan({x: 0, y: -speed}));
s.setAttribute("transform", "rotate(0)");
var w = panContainer.appendChild(pan({x: speed, y: 0}));
w.setAttribute("transform", "rotate(90)");
var n = panContainer.appendChild(pan({x: 0, y: speed}));
n.setAttribute("transform", "rotate(180)");
var e = panContainer.appendChild(pan({x: -speed, y: 0}));
e.setAttribute("transform", "rotate(270)");
var fore = panContainer.appendChild(ms.svg("circle"));
fore.setAttribute("fill", "none");
fore.setAttribute("class", "fore");
fore.setAttribute("r", r);
} else {
panContainer = null;
}
if (zoomStyle != "none") {
zoomContainer = g.appendChild(ms.svg("g"));
zoomContainer.setAttribute("class", "zoom");
var j = -0.5;
if (zoomStyle == "big") {
ticks = {};
for (var i = map.zoomRange()[0], j = 0; i <= map.zoomRange()[1]; i++, j++) {
(ticks[i] = zoomContainer.appendChild(tick(i)))
.setAttribute("transform", "translate(0," + (-(j + 0.75) * r * 0.4) + ")");
}
}
var p = panStyle == "none" ? 0.4 : 2;
zoomContainer.setAttribute("transform", "translate(0," + r * (/^top-/.test(position) ? (p + (j + 0.5) * 0.4) : -p) + ")");
zoomContainer.appendChild(zoom(+1)).setAttribute("transform", "translate(0," + (-(j + 0.5) * r * 0.4) + ")");
zoomContainer.appendChild(zoom(-1)).setAttribute("transform", "scale(-1)");
} else {
zoomContainer = null;
}
move();
}
compass.radius = function(x) {
if (!arguments.length) return r;
r = x;
if (map) draw();
return compass;
};
compass.speed = function(x) {
if (!arguments.length) return r;
speed = x;
return compass;
};
compass.position = function(x) {
if (!arguments.length) return position;
position = x;
if (map) draw();
return compass;
};
compass.pan = function(x) {
if (!arguments.length) return panStyle;
panStyle = x;
if (map) draw();
return compass;
};
compass.zoom = function(x) {
if (!arguments.length) return zoomStyle;
zoomStyle = x;
if (map) draw();
return compass;
};
compass.map = function(x) {
if (!arguments.length) return map;
if (map) {
container.removeEventListener("mousedown", mousedown, false);
container.removeChild(g);
container = null;
window.removeEventListener("mousemove", mousemove, false);
window.removeEventListener("mouseup", mouseup, false);
window = null;
map.off("move", move).off("resize", move);
}
if (map = x) {
container = map.svgContainer();
container.appendChild(g);
container.addEventListener("mousedown", mousedown, false);
window = container.ownerDocument.defaultView;
window.addEventListener("mousemove", mousemove, false);
window.addEventListener("mouseup", mouseup, false);
map.on("move", move).on("resize", move);
draw();
}
return compass;
};
return compass;
};
ms.grid = function() {
var grid = {},
map,
g = ms.svg("g");
g.setAttribute("class", "grid");
function move(e) {
var p,
line = g.firstChild,
size = map.size(),
nw = map.pointLocation(zero),
se = map.pointLocation(size),
step = Math.pow(2, 4 - Math.round(map.zoom()));
// Round to step.
nw.lat = Math.floor(nw.lat / step) * step;
nw.lon = Math.ceil(nw.lon / step) * step;
// Longitude ticks.
for (var x; (x = map.locationPoint(nw).x) <= size.x; nw.lon += step) {
if (!line) line = g.appendChild(ms.svg("line"));
line.setAttribute("x1", x);
line.setAttribute("x2", x);
line.setAttribute("y1", 0);
line.setAttribute("y2", size.y);
line = line.nextSibling;
}
// Latitude ticks.
for (var y; (y = map.locationPoint(nw).y) <= size.y; nw.lat -= step) {
if (!line) line = g.appendChild(ms.svg("line"));
line.setAttribute("y1", y);
line.setAttribute("y2", y);
line.setAttribute("x1", 0);
line.setAttribute("x2", size.x);
line = line.nextSibling;
}
// Remove extra ticks.
while (line) {
var next = line.nextSibling;
g.removeChild(line);
line = next;
}
}
grid.map = function(x) {
if (!arguments.length) return map;
if (map) {
g.parentNode.removeChild(g);
map.off("move", move).off("resize", move);
}
if (map = x) {
map.on("move", move).on("resize", move);
map.svgContainer().appendChild(g);
map.dispatch({type: "move"});
}
return grid;
};
return grid;
};
ms.attribution = function(html) {
var attribution = {},
map,
container = document.createElement("div");
container.setAttribute("class", "mapsense-attribution");
attribution.container = function() {
return container;
};
attribution.html = function(x) {
if (!arguments.length) return container.innerHTML;
container.innerHTML = x;
return attribution;
};
attribution.map = function(x) {
if (!arguments.length) return map;
if (map) {
if (map === x) {
container.parentNode.appendChild(container);
return attribution;
}
container.parentNode.removeChild(container);
}
map = x;
if (map) {
map.relativeContainer().appendChild(container);
}
return attribution;
};
return attribution.html(html);
};
ms.basemap = function() {
var basemap = ms.topoJson();
var attribution = ms.attribution('<a target="_blank" href="https://developer.mapsense.co/tileViewer/?tileset=mapsense.earth">©Mapsense ©OpenStreetMap</a>');
var url = "https://{S}-api.mapsense.co/universes/mapsense.earth/{Z}/{X}/{Y}.topojson?s=10&ringSpan=8";
var apiKey;
var style;
function urlWithKey() {
return ms.url(url + "&api-key=" + apiKey)
.hosts(["a", "b", "c", "d"]);
}
var __map__ = basemap.map;
basemap.map = function(x) {
var result = __map__.apply(basemap, arguments);
if (arguments.length)
attribution.map(x);
return result;
};
var __url__ = basemap.url;
basemap.url = function(x) {
if (!arguments.length) return url;
url = x;
__url__.call(basemap, urlWithKey());
return basemap;
};
basemap.apiKey = function(x) {
if (!arguments.length) return apiKey;
apiKey = x;
__url__.call(basemap, urlWithKey());
return basemap;
};
basemap.style = function(x) {
if (!arguments.length) return style;
if (style)
attribution.container().classList.remove(style);
style = x;
basemap.selection(function(s) {
var styleClass = style ? "mapsense-" + style : "";
var zoomClass = "_" + Math.floor(basemap.map().zoom());
s.attr("class", function(feature) {
var classes = [ styleClass, zoomClass ];
if (feature.properties) {
if (feature.properties.layer)
classes.push(feature.properties.layer);
if (feature.properties.sub_layer)
classes.push(feature.properties.sub_layer);
}
return classes.join(" ");
});
});
if (style)
attribution.container().classList.add(style);
return basemap;
};
basemap.on("load", function(e) {
var g = e.tile.element;
var tileBackground = g.querySelector(".tile-background");
if (tileBackground && style)
tileBackground.classList.add("mapsense-" + style);
});
basemap.style("light");
basemap.tileBackground(true);
basemap.clip(true);
return basemap;
};
ms.stylist = function() {
var attrs = [],
styles = [],
title;
function stylist(e) {
var ne = e.features.length,
na = attrs.length,
ns = styles.length,
f, // feature
d, // data
o, // element
x, // attr or style or title descriptor
v, // attr or style or title value
i,
j;
for (i = 0; i < ne; ++i) {
if (!(o = (f = e.features[i]).element)) continue;
d = f.data;
for (j = 0; j < na; ++j) {
v = (x = attrs[j]).value;
if (typeof v === "function") v = v.call(null, d);
if (v == null) {
if (x.name.local)
o.removeAttributeNS(x.name.space, x.name.local);
else
o.removeAttribute(x.name);
}
else {
if (x.name.local)
o.setAttributeNS(x.name.space, x.name.local, v);
else
o.setAttribute(x.name, v);
}
}
for (j = 0; j < ns; ++j) {
v = (x = styles[j]).value;
if (typeof v === "function") v = v.call(null, d);
if (v == null)
o.style.removeProperty(x.name);
else
o.style.setProperty(x.name, v, x.priority);
}
if (v = title) {
if (typeof v === "function") v = v.call(null, d);
while (o.lastChild) o.removeChild(o.lastChild);
if (v != null) o.appendChild(ms.svg("title")).appendChild(document.createTextNode(v));
}
}
}
stylist.attr = function(n, v) {
attrs.push({name: ns(n), value: v});
return stylist;
};
stylist.style = function(n, v, p) {
styles.push({name: n, value: v, priority: arguments.length < 3 ? null : p});
return stylist;
};
stylist.title = function(v) {
title = v;
return stylist;
};
return stylist;
};
if (typeof define === "function" && define.amd)
define(mapsense);
else if (typeof module === "object" && module.exports)
module.exports = mapsense;
this.mapsense = mapsense;
})();
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.proj4=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
var mgrs = _dereq_('mgrs');
function Point(x, y, z) {
if (!(this instanceof Point)) {
return new Point(x, y, z);
}
if (Array.isArray(x)) {
this.x = x[0];
this.y = x[1];
this.z = x[2] || 0.0;
}else if(typeof x === 'object'){
this.x = x.x;
this.y = x.y;
this.z = x.z || 0.0;
} else if (typeof x === 'string' && typeof y === 'undefined') {
var coords = x.split(',');
this.x = parseFloat(coords[0], 10);
this.y = parseFloat(coords[1], 10);
this.z = parseFloat(coords[2], 10) || 0.0;
}
else {
this.x = x;
this.y = y;
this.z = z || 0.0;
}
console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
}
Point.fromMGRS = function(mgrsStr) {
return new Point(mgrs.toPoint(mgrsStr));
};
Point.prototype.toMGRS = function(accuracy) {
return mgrs.forward([this.x, this.y], accuracy);
};
module.exports = Point;
},{"mgrs":67}],2:[function(_dereq_,module,exports){
var parseCode = _dereq_("./parseCode");
var extend = _dereq_('./extend');
var projections = _dereq_('./projections');
var deriveConstants = _dereq_('./deriveConstants');
function Projection(srsCode,callback) {
if (!(this instanceof Projection)) {
return new Projection(srsCode);
}
callback = callback || function(error){
if(error){
throw error;
}
};
var json = parseCode(srsCode);
if(typeof json !== 'object'){
callback(srsCode);
return;
}
var modifiedJSON = deriveConstants(json);
var ourProj = Projection.projections.get(modifiedJSON.projName);
if(ourProj){
extend(this, modifiedJSON);
extend(this, ourProj);
this.init();
callback(null, this);
}else{
callback(srsCode);
}
}
Projection.projections = projections;
Projection.projections.start();
module.exports = Projection;
},{"./deriveConstants":33,"./extend":34,"./parseCode":37,"./projections":39}],3:[function(_dereq_,module,exports){
module.exports = function(crs, denorm, point) {
var xin = point.x,
yin = point.y,
zin = point.z || 0.0;
var v, t, i;
for (i = 0; i < 3; i++) {
if (denorm && i === 2 && point.z === undefined) {
continue;
}
if (i === 0) {
v = xin;
t = 'x';
}
else if (i === 1) {
v = yin;
t = 'y';
}
else {
v = zin;
t = 'z';
}
switch (crs.axis[i]) {
case 'e':
point[t] = v;
break;
case 'w':
point[t] = -v;
break;
case 'n':
point[t] = v;
break;
case 's':
point[t] = -v;
break;
case 'u':
if (point[t] !== undefined) {
point.z = v;
}
break;
case 'd':
if (point[t] !== undefined) {
point.z = -v;
}
break;
default:
//console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
return null;
}
}
return point;
};
},{}],4:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
var sign = _dereq_('./sign');
module.exports = function(x) {
return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
};
},{"./sign":21}],5:[function(_dereq_,module,exports){
var TWO_PI = Math.PI * 2;
// SPI is slightly greater than Math.PI, so values that exceed the -180..180
// degree range by a tiny amount don't get wrapped. This prevents points that
// have drifted from their original location along the 180th meridian (due to
// floating point error) from changing their sign.
var SPI = 3.14159265359;
var sign = _dereq_('./sign');
module.exports = function(x) {
return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
};
},{"./sign":21}],6:[function(_dereq_,module,exports){
module.exports = function(x) {
if (Math.abs(x) > 1) {
x = (x > 1) ? 1 : -1;
}
return Math.asin(x);
};
},{}],7:[function(_dereq_,module,exports){
module.exports = function(x) {
return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
};
},{}],8:[function(_dereq_,module,exports){
module.exports = function(x) {
return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
};
},{}],9:[function(_dereq_,module,exports){
module.exports = function(x) {
return (0.05859375 * x * x * (1 + 0.75 * x));
};
},{}],10:[function(_dereq_,module,exports){
module.exports = function(x) {
return (x * x * x * (35 / 3072));
};
},{}],11:[function(_dereq_,module,exports){
module.exports = function(a, e, sinphi) {
var temp = e * sinphi;
return a / Math.sqrt(1 - temp * temp);
};
},{}],12:[function(_dereq_,module,exports){
module.exports = function(ml, e0, e1, e2, e3) {
var phi;
var dphi;
phi = ml / e0;
for (var i = 0; i < 15; i++) {
dphi = (ml - (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi))) / (e0 - 2 * e1 * Math.cos(2 * phi) + 4 * e2 * Math.cos(4 * phi) - 6 * e3 * Math.cos(6 * phi));
phi += dphi;
if (Math.abs(dphi) <= 0.0000000001) {
return phi;
}
}
//..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
return NaN;
};
},{}],13:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
module.exports = function(eccent, q) {
var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
if (q < 0) {
return (-1 * HALF_PI);
}
else {
return HALF_PI;
}
}
//var phi = 0.5* q/(1-eccent*eccent);
var phi = Math.asin(0.5 * q);
var dphi;
var sin_phi;
var cos_phi;
var con;
for (var i = 0; i < 30; i++) {
sin_phi = Math.sin(phi);
cos_phi = Math.cos(phi);
con = eccent * sin_phi;
dphi = Math.pow(1 - con * con, 2) / (2 * cos_phi) * (q / (1 - eccent * eccent) - sin_phi / (1 - con * con) + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
phi += dphi;
if (Math.abs(dphi) <= 0.0000000001) {
return phi;
}
}
//console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
return NaN;
};
},{}],14:[function(_dereq_,module,exports){
module.exports = function(e0, e1, e2, e3, phi) {
return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
};
},{}],15:[function(_dereq_,module,exports){
module.exports = function(eccent, sinphi, cosphi) {
var con = eccent * sinphi;
return cosphi / (Math.sqrt(1 - con * con));
};
},{}],16:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
module.exports = function(eccent, ts) {
var eccnth = 0.5 * eccent;
var con, dphi;
var phi = HALF_PI - 2 * Math.atan(ts);
for (var i = 0; i <= 15; i++) {
con = eccent * Math.sin(phi);
dphi = HALF_PI - 2 * Math.atan(ts * (Math.pow(((1 - con) / (1 + con)), eccnth))) - phi;
phi += dphi;
if (Math.abs(dphi) <= 0.0000000001) {
return phi;
}
}
//console.log("phi2z has NoConvergence");
return -9999;
};
},{}],17:[function(_dereq_,module,exports){
var C00 = 1;
var C02 = 0.25;
var C04 = 0.046875;
var C06 = 0.01953125;
var C08 = 0.01068115234375;
var C22 = 0.75;
var C44 = 0.46875;
var C46 = 0.01302083333333333333;
var C48 = 0.00712076822916666666;
var C66 = 0.36458333333333333333;
var C68 = 0.00569661458333333333;
var C88 = 0.3076171875;
module.exports = function(es) {
var en = [];
en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
var t = es * es;
en[2] = t * (C44 - es * (C46 + es * C48));
t *= es;
en[3] = t * (C66 - es * C68);
en[4] = t * es * C88;
return en;
};
},{}],18:[function(_dereq_,module,exports){
var pj_mlfn = _dereq_("./pj_mlfn");
var EPSLN = 1.0e-10;
var MAX_ITER = 20;
module.exports = function(arg, es, en) {
var k = 1 / (1 - es);
var phi = arg;
for (var i = MAX_ITER; i; --i) { /* rarely goes over 2 iterations */
var s = Math.sin(phi);
var t = 1 - es * s * s;
//t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
//phi -= t * (t * Math.sqrt(t)) * k;
t = (pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
phi -= t;
if (Math.abs(t) < EPSLN) {
return phi;
}
}
//..reportError("cass:pj_inv_mlfn: Convergence error");
return phi;
};
},{"./pj_mlfn":19}],19:[function(_dereq_,module,exports){
module.exports = function(phi, sphi, cphi, en) {
cphi *= sphi;
sphi *= sphi;
return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
};
},{}],20:[function(_dereq_,module,exports){
module.exports = function(eccent, sinphi) {
var con;
if (eccent > 1.0e-7) {
con = eccent * sinphi;
return ((1 - eccent * eccent) * (sinphi / (1 - con * con) - (0.5 / eccent) * Math.log((1 - con) / (1 + con))));
}
else {
return (2 * sinphi);
}
};
},{}],21:[function(_dereq_,module,exports){
module.exports = function(x) {
return x<0 ? -1 : 1;
};
},{}],22:[function(_dereq_,module,exports){
module.exports = function(esinp, exp) {
return (Math.pow((1 - esinp) / (1 + esinp), exp));
};
},{}],23:[function(_dereq_,module,exports){
module.exports = function (array){
var out = {
x: array[0],
y: array[1]
};
if (array.length>2) {
out.z = array[2];
}
if (array.length>3) {
out.m = array[3];
}
return out;
};
},{}],24:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
module.exports = function(eccent, phi, sinphi) {
var con = eccent * sinphi;
var com = 0.5 * eccent;
con = Math.pow(((1 - con) / (1 + con)), com);
return (Math.tan(0.5 * (HALF_PI - phi)) / con);
};
},{}],25:[function(_dereq_,module,exports){
exports.wgs84 = {
towgs84: "0,0,0",
ellipse: "WGS84",
datumName: "WGS84"
};
exports.ch1903 = {
towgs84: "674.374,15.056,405.346",
ellipse: "bessel",
datumName: "swiss"
};
exports.ggrs87 = {
towgs84: "-199.87,74.79,246.62",
ellipse: "GRS80",
datumName: "Greek_Geodetic_Reference_System_1987"
};
exports.nad83 = {
towgs84: "0,0,0",
ellipse: "GRS80",
datumName: "North_American_Datum_1983"
};
exports.nad27 = {
nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",
ellipse: "clrk66",
datumName: "North_American_Datum_1927"
};
exports.potsdam = {
towgs84: "606.0,23.0,413.0",
ellipse: "bessel",
datumName: "Potsdam Rauenberg 1950 DHDN"
};
exports.carthage = {
towgs84: "-263.0,6.0,431.0",
ellipse: "clark80",
datumName: "Carthage 1934 Tunisia"
};
exports.hermannskogel = {
towgs84: "653.0,-212.0,449.0",
ellipse: "bessel",
datumName: "Hermannskogel"
};
exports.ire65 = {
towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
ellipse: "mod_airy",
datumName: "Ireland 1965"
};
exports.rassadiran = {
towgs84: "-133.63,-157.5,-158.62",
ellipse: "intl",
datumName: "Rassadiran"
};
exports.nzgd49 = {
towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
ellipse: "intl",
datumName: "New Zealand Geodetic Datum 1949"
};
exports.osgb36 = {
towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
ellipse: "airy",
datumName: "Airy 1830"
};
exports.s_jtsk = {
towgs84: "589,76,480",
ellipse: 'bessel',
datumName: 'S-JTSK (Ferro)'
};
exports.beduaram = {
towgs84: '-106,-87,188',
ellipse: 'clrk80',
datumName: 'Beduaram'
};
exports.gunung_segara = {
towgs84: '-403,684,41',
ellipse: 'bessel',
datumName: 'Gunung Segara Jakarta'
};
exports.rnb72 = {
towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
ellipse: "intl",
datumName: "Reseau National Belge 1972"
};
},{}],26:[function(_dereq_,module,exports){
exports.MERIT = {
a: 6378137.0,
rf: 298.257,
ellipseName: "MERIT 1983"
};
exports.SGS85 = {
a: 6378136.0,
rf: 298.257,
ellipseName: "Soviet Geodetic System 85"
};
exports.GRS80 = {
a: 6378137.0,
rf: 298.257222101,
ellipseName: "GRS 1980(IUGG, 1980)"
};
exports.IAU76 = {
a: 6378140.0,
rf: 298.257,
ellipseName: "IAU 1976"
};
exports.airy = {
a: 6377563.396,
b: 6356256.910,
ellipseName: "Airy 1830"
};
exports.APL4 = {
a: 6378137,
rf: 298.25,
ellipseName: "Appl. Physics. 1965"
};
exports.NWL9D = {
a: 6378145.0,
rf: 298.25,
ellipseName: "Naval Weapons Lab., 1965"
};
exports.mod_airy = {
a: 6377340.189,
b: 6356034.446,
ellipseName: "Modified Airy"
};
exports.andrae = {
a: 6377104.43,
rf: 300.0,
ellipseName: "Andrae 1876 (Den., Iclnd.)"
};
exports.aust_SA = {
a: 6378160.0,
rf: 298.25,
ellipseName: "Australian Natl & S. Amer. 1969"
};
exports.GRS67 = {
a: 6378160.0,
rf: 298.2471674270,
ellipseName: "GRS 67(IUGG 1967)"
};
exports.bessel = {
a: 6377397.155,
rf: 299.1528128,
ellipseName: "Bessel 1841"
};
exports.bess_nam = {
a: 6377483.865,
rf: 299.1528128,
ellipseName: "Bessel 1841 (Namibia)"
};
exports.clrk66 = {
a: 6378206.4,
b: 6356583.8,
ellipseName: "Clarke 1866"
};
exports.clrk80 = {
a: 6378249.145,
rf: 293.4663,
ellipseName: "Clarke 1880 mod."
};
exports.clrk58 = {
a: 6378293.645208759,
rf: 294.2606763692654,
ellipseName: "Clarke 1858"
};
exports.CPM = {
a: 6375738.7,
rf: 334.29,
ellipseName: "Comm. des Poids et Mesures 1799"
};
exports.delmbr = {
a: 6376428.0,
rf: 311.5,
ellipseName: "Delambre 1810 (Belgium)"
};
exports.engelis = {
a: 6378136.05,
rf: 298.2566,
ellipseName: "Engelis 1985"
};
exports.evrst30 = {
a: 6377276.345,
rf: 300.8017,
ellipseName: "Everest 1830"
};
exports.evrst48 = {
a: 6377304.063,
rf: 300.8017,
ellipseName: "Everest 1948"
};
exports.evrst56 = {
a: 6377301.243,
rf: 300.8017,
ellipseName: "Everest 1956"
};
exports.evrst69 = {
a: 6377295.664,
rf: 300.8017,
ellipseName: "Everest 1969"
};
exports.evrstSS = {
a: 6377298.556,
rf: 300.8017,
ellipseName: "Everest (Sabah & Sarawak)"
};
exports.fschr60 = {
a: 6378166.0,
rf: 298.3,
ellipseName: "Fischer (Mercury Datum) 1960"
};
exports.fschr60m = {
a: 6378155.0,
rf: 298.3,
ellipseName: "Fischer 1960"
};
exports.fschr68 = {
a: 6378150.0,
rf: 298.3,
ellipseName: "Fischer 1968"
};
exports.helmert = {
a: 6378200.0,
rf: 298.3,
ellipseName: "Helmert 1906"
};
exports.hough = {
a: 6378270.0,
rf: 297.0,
ellipseName: "Hough"
};
exports.intl = {
a: 6378388.0,
rf: 297.0,
ellipseName: "International 1909 (Hayford)"
};
exports.kaula = {
a: 6378163.0,
rf: 298.24,
ellipseName: "Kaula 1961"
};
exports.lerch = {
a: 6378139.0,
rf: 298.257,
ellipseName: "Lerch 1979"
};
exports.mprts = {
a: 6397300.0,
rf: 191.0,
ellipseName: "Maupertius 1738"
};
exports.new_intl = {
a: 6378157.5,
b: 6356772.2,
ellipseName: "New International 1967"
};
exports.plessis = {
a: 6376523.0,
rf: 6355863.0,
ellipseName: "Plessis 1817 (France)"
};
exports.krass = {
a: 6378245.0,
rf: 298.3,
ellipseName: "Krassovsky, 1942"
};
exports.SEasia = {
a: 6378155.0,
b: 6356773.3205,
ellipseName: "Southeast Asia"
};
exports.walbeck = {
a: 6376896.0,
b: 6355834.8467,
ellipseName: "Walbeck"
};
exports.WGS60 = {
a: 6378165.0,
rf: 298.3,
ellipseName: "WGS 60"
};
exports.WGS66 = {
a: 6378145.0,
rf: 298.25,
ellipseName: "WGS 66"
};
exports.WGS7 = {
a: 6378135.0,
rf: 298.26,
ellipseName: "WGS 72"
};
exports.WGS84 = {
a: 6378137.0,
rf: 298.257223563,
ellipseName: "WGS 84"
};
exports.sphere = {
a: 6370997.0,
b: 6370997.0,
ellipseName: "Normal Sphere (r=6370997)"
};
},{}],27:[function(_dereq_,module,exports){
exports.greenwich = 0.0; //"0dE",
exports.lisbon = -9.131906111111; //"9d07'54.862\"W",
exports.paris = 2.337229166667; //"2d20'14.025\"E",
exports.bogota = -74.080916666667; //"74d04'51.3\"W",
exports.madrid = -3.687938888889; //"3d41'16.58\"W",
exports.rome = 12.452333333333; //"12d27'8.4\"E",
exports.bern = 7.439583333333; //"7d26'22.5\"E",
exports.jakarta = 106.807719444444; //"106d48'27.79\"E",
exports.ferro = -17.666666666667; //"17d40'W",
exports.brussels = 4.367975; //"4d22'4.71\"E",
exports.stockholm = 18.058277777778; //"18d3'29.8\"E",
exports.athens = 23.7163375; //"23d42'58.815\"E",
exports.oslo = 10.722916666667; //"10d43'22.5\"E"
},{}],28:[function(_dereq_,module,exports){
exports.ft = {to_meter: 0.3048};
exports['us-ft'] = {to_meter: 1200 / 3937};
},{}],29:[function(_dereq_,module,exports){
var proj = _dereq_('./Proj');
var transform = _dereq_('./transform');
var wgs84 = proj('WGS84');
function transformer(from, to, coords) {
var transformedArray;
if (Array.isArray(coords)) {
transformedArray = transform(from, to, coords);
if (coords.length === 3) {
return [transformedArray.x, transformedArray.y, transformedArray.z];
}
else {
return [transformedArray.x, transformedArray.y];
}
}
else {
return transform(from, to, coords);
}
}
function checkProj(item) {
if (item instanceof proj) {
return item;
}
if (item.oProj) {
return item.oProj;
}
return proj(item);
}
function proj4(fromProj, toProj, coord) {
fromProj = checkProj(fromProj);
var single = false;
var obj;
if (typeof toProj === 'undefined') {
toProj = fromProj;
fromProj = wgs84;
single = true;
}
else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
coord = toProj;
toProj = fromProj;
fromProj = wgs84;
single = true;
}
toProj = checkProj(toProj);
if (coord) {
return transformer(fromProj, toProj, coord);
}
else {
obj = {
forward: function(coords) {
return transformer(fromProj, toProj, coords);
},
inverse: function(coords) {
return transformer(toProj, fromProj, coords);
}
};
if (single) {
obj.oProj = toProj;
}
return obj;
}
}
module.exports = proj4;
},{"./Proj":2,"./transform":65}],30:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
var PJD_3PARAM = 1;
var PJD_7PARAM = 2;
var PJD_GRIDSHIFT = 3;
var PJD_WGS84 = 4; // WGS84 or equivalent
var PJD_NODATUM = 5; // WGS84 or equivalent
var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
var AD_C = 1.0026000;
var COS_67P5 = 0.38268343236508977;
var datum = function(proj) {
if (!(this instanceof datum)) {
return new datum(proj);
}
this.datum_type = PJD_WGS84; //default setting
if (!proj) {
return;
}
if (proj.datumCode && proj.datumCode === 'none') {
this.datum_type = PJD_NODATUM;
}
if (proj.datum_params) {
for (var i = 0; i < proj.datum_params.length; i++) {
proj.datum_params[i] = parseFloat(proj.datum_params[i]);
}
if (proj.datum_params[0] !== 0 || proj.datum_params[1] !== 0 || proj.datum_params[2] !== 0) {
this.datum_type = PJD_3PARAM;
}
if (proj.datum_params.length > 3) {
if (proj.datum_params[3] !== 0 || proj.datum_params[4] !== 0 || proj.datum_params[5] !== 0 || proj.datum_params[6] !== 0) {
this.datum_type = PJD_7PARAM;
proj.datum_params[3] *= SEC_TO_RAD;
proj.datum_params[4] *= SEC_TO_RAD;
proj.datum_params[5] *= SEC_TO_RAD;
proj.datum_params[6] = (proj.datum_params[6] / 1000000.0) + 1.0;
}
}
}
// DGR 2011-03-21 : nadgrids support
this.datum_type = proj.grids ? PJD_GRIDSHIFT : this.datum_type;
this.a = proj.a; //datum object also uses these values
this.b = proj.b;
this.es = proj.es;
this.ep2 = proj.ep2;
this.datum_params = proj.datum_params;
if (this.datum_type === PJD_GRIDSHIFT) {
this.grids = proj.grids;
}
};
datum.prototype = {
/****************************************************************/
// cs_compare_datums()
// Returns TRUE if the two datums match, otherwise FALSE.
compare_datums: function(dest) {
if (this.datum_type !== dest.datum_type) {
return false; // false, datums are not equal
}
else if (this.a !== dest.a || Math.abs(this.es - dest.es) > 0.000000000050) {
// the tolerence for es is to ensure that GRS80 and WGS84
// are considered identical
return false;
}
else if (this.datum_type === PJD_3PARAM) {
return (this.datum_params[0] === dest.datum_params[0] && this.datum_params[1] === dest.datum_params[1] && this.datum_params[2] === dest.datum_params[2]);
}
else if (this.datum_type === PJD_7PARAM) {
return (this.datum_params[0] === dest.datum_params[0] && this.datum_params[1] === dest.datum_params[1] && this.datum_params[2] === dest.datum_params[2] && this.datum_params[3] === dest.datum_params[3] && this.datum_params[4] === dest.datum_params[4] && this.datum_params[5] === dest.datum_params[5] && this.datum_params[6] === dest.datum_params[6]);
}
else if (this.datum_type === PJD_GRIDSHIFT || dest.datum_type === PJD_GRIDSHIFT) {
//alert("ERROR: Grid shift transformations are not implemented.");
//return false
//DGR 2012-07-29 lazy ...
return this.nadgrids === dest.nadgrids;
}
else {
return true; // datums are equal
}
}, // cs_compare_datums()
/*
* The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
* (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
* according to the current ellipsoid parameters.
*
* Latitude : Geodetic latitude in radians (input)
* Longitude : Geodetic longitude in radians (input)
* Height : Geodetic height, in meters (input)
* X : Calculated Geocentric X coordinate, in meters (output)
* Y : Calculated Geocentric Y coordinate, in meters (output)
* Z : Calculated Geocentric Z coordinate, in meters (output)
*
*/
geodetic_to_geocentric: function(p) {
var Longitude = p.x;
var Latitude = p.y;
var Height = p.z ? p.z : 0; //Z value not always supplied
var X; // output
var Y;
var Z;
var Error_Code = 0; // GEOCENT_NO_ERROR;
var Rn; /* Earth radius at location */
var Sin_Lat; /* Math.sin(Latitude) */
var Sin2_Lat; /* Square of Math.sin(Latitude) */
var Cos_Lat; /* Math.cos(Latitude) */
/*
** Don't blow up if Latitude is just a little out of the value
** range as it may just be a rounding issue. Also removed longitude
** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
*/
if (Latitude < -HALF_PI && Latitude > -1.001 * HALF_PI) {
Latitude = -HALF_PI;
}
else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI) {
Latitude = HALF_PI;
}
else if ((Latitude < -HALF_PI) || (Latitude > HALF_PI)) {
/* Latitude out of range */
//..reportError('geocent:lat out of range:' + Latitude);
return null;
}
if (Longitude > Math.PI) {
Longitude -= (2 * Math.PI);
}
Sin_Lat = Math.sin(Latitude);
Cos_Lat = Math.cos(Latitude);
Sin2_Lat = Sin_Lat * Sin_Lat;
Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
p.x = X;
p.y = Y;
p.z = Z;
return Error_Code;
}, // cs_geodetic_to_geocentric()
geocentric_to_geodetic: function(p) {
/* local defintions and variables */
/* end-criterium of loop, accuracy of sin(Latitude) */
var genau = 1e-12;
var genau2 = (genau * genau);
var maxiter = 30;
var P; /* distance between semi-minor axis and location */
var RR; /* distance between center and location */
var CT; /* sin of geocentric latitude */
var ST; /* cos of geocentric latitude */
var RX;
var RK;
var RN; /* Earth radius at location */
var CPHI0; /* cos of start or old geodetic latitude in iterations */
var SPHI0; /* sin of start or old geodetic latitude in iterations */
var CPHI; /* cos of searched geodetic latitude */
var SPHI; /* sin of searched geodetic latitude */
var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
var At_Pole; /* indicates location is in polar region */
var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
var X = p.x;
var Y = p.y;
var Z = p.z ? p.z : 0.0; //Z value not always supplied
var Longitude;
var Latitude;
var Height;
At_Pole = false;
P = Math.sqrt(X * X + Y * Y);
RR = Math.sqrt(X * X + Y * Y + Z * Z);
/* special cases for latitude and longitude */
if (P / this.a < genau) {
/* special case, if P=0. (X=0., Y=0.) */
At_Pole = true;
Longitude = 0.0;
/* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
* of ellipsoid (=center of mass), Latitude becomes PI/2 */
if (RR / this.a < genau) {
Latitude = HALF_PI;
Height = -this.b;
return;
}
}
else {
/* ellipsoidal (geodetic) longitude
* interval: -PI < Longitude <= +PI */
Longitude = Math.atan2(Y, X);
}
/* --------------------------------------------------------------
* Following iterative algorithm was developped by
* "Institut for Erdmessung", University of Hannover, July 1988.
* Internet: www.ife.uni-hannover.de
* Iterative computation of CPHI,SPHI and Height.
* Iteration of CPHI and SPHI to 10**-12 radian resp.
* 2*10**-7 arcsec.
* --------------------------------------------------------------
*/
CT = Z / RR;
ST = P / RR;
RX = 1.0 / Math.sqrt(1.0 - this.es * (2.0 - this.es) * ST * ST);
CPHI0 = ST * (1.0 - this.es) * RX;
SPHI0 = CT * RX;
iter = 0;
/* loop to find sin(Latitude) resp. Latitude
* until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
do {
iter++;
RN = this.a / Math.sqrt(1.0 - this.es * SPHI0 * SPHI0);
/* ellipsoidal (geodetic) height */
Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - this.es * SPHI0 * SPHI0);
RK = this.es * RN / (RN + Height);
RX = 1.0 / Math.sqrt(1.0 - RK * (2.0 - RK) * ST * ST);
CPHI = ST * (1.0 - RK) * RX;
SPHI = CT * RX;
SDPHI = SPHI * CPHI0 - CPHI * SPHI0;
CPHI0 = CPHI;
SPHI0 = SPHI;
}
while (SDPHI * SDPHI > genau2 && iter < maxiter);
/* ellipsoidal (geodetic) latitude */
Latitude = Math.atan(SPHI / Math.abs(CPHI));
p.x = Longitude;
p.y = Latitude;
p.z = Height;
return p;
}, // cs_geocentric_to_geodetic()
/** Convert_Geocentric_To_Geodetic
* The method used here is derived from 'An Improved Algorithm for
* Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
*/
geocentric_to_geodetic_noniter: function(p) {
var X = p.x;
var Y = p.y;
var Z = p.z ? p.z : 0; //Z value not always supplied
var Longitude;
var Latitude;
var Height;
var W; /* distance from Z axis */
var W2; /* square of distance from Z axis */
var T0; /* initial estimate of vertical component */
var T1; /* corrected estimate of vertical component */
var S0; /* initial estimate of horizontal component */
var S1; /* corrected estimate of horizontal component */
var Sin_B0; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
var Sin3_B0; /* cube of Math.sin(B0) */
var Cos_B0; /* Math.cos(B0) */
var Sin_p1; /* Math.sin(phi1), phi1 is estimated latitude */
var Cos_p1; /* Math.cos(phi1) */
var Rn; /* Earth radius at location */
var Sum; /* numerator of Math.cos(phi1) */
var At_Pole; /* indicates location is in polar region */
X = parseFloat(X); // cast from string to float
Y = parseFloat(Y);
Z = parseFloat(Z);
At_Pole = false;
if (X !== 0.0) {
Longitude = Math.atan2(Y, X);
}
else {
if (Y > 0) {
Longitude = HALF_PI;
}
else if (Y < 0) {
Longitude = -HALF_PI;
}
else {
At_Pole = true;
Longitude = 0.0;
if (Z > 0.0) { /* north pole */
Latitude = HALF_PI;
}
else if (Z < 0.0) { /* south pole */
Latitude = -HALF_PI;
}
else { /* center of earth */
Latitude = HALF_PI;
Height = -this.b;
return;
}
}
}
W2 = X * X + Y * Y;
W = Math.sqrt(W2);
T0 = Z * AD_C;
S0 = Math.sqrt(T0 * T0 + W2);
Sin_B0 = T0 / S0;
Cos_B0 = W / S0;
Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
T1 = Z + this.b * this.ep2 * Sin3_B0;
Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
S1 = Math.sqrt(T1 * T1 + Sum * Sum);
Sin_p1 = T1 / S1;
Cos_p1 = Sum / S1;
Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
if (Cos_p1 >= COS_67P5) {
Height = W / Cos_p1 - Rn;
}
else if (Cos_p1 <= -COS_67P5) {
Height = W / -Cos_p1 - Rn;
}
else {
Height = Z / Sin_p1 + Rn * (this.es - 1.0);
}
if (At_Pole === false) {
Latitude = Math.atan(Sin_p1 / Cos_p1);
}
p.x = Longitude;
p.y = Latitude;
p.z = Height;
return p;
}, // geocentric_to_geodetic_noniter()
/****************************************************************/
// pj_geocentic_to_wgs84( p )
// p = point to transform in geocentric coordinates (x,y,z)
geocentric_to_wgs84: function(p) {
if (this.datum_type === PJD_3PARAM) {
// if( x[io] === HUGE_VAL )
// continue;
p.x += this.datum_params[0];
p.y += this.datum_params[1];
p.z += this.datum_params[2];
}
else if (this.datum_type === PJD_7PARAM) {
var Dx_BF = this.datum_params[0];
var Dy_BF = this.datum_params[1];
var Dz_BF = this.datum_params[2];
var Rx_BF = this.datum_params[3];
var Ry_BF = this.datum_params[4];
var Rz_BF = this.datum_params[5];
var M_BF = this.datum_params[6];
// if( x[io] === HUGE_VAL )
// continue;
var x_out = M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF;
var y_out = M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF;
var z_out = M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF;
p.x = x_out;
p.y = y_out;
p.z = z_out;
}
}, // cs_geocentric_to_wgs84
/****************************************************************/
// pj_geocentic_from_wgs84()
// coordinate system definition,
// point to transform in geocentric coordinates (x,y,z)
geocentric_from_wgs84: function(p) {
if (this.datum_type === PJD_3PARAM) {
//if( x[io] === HUGE_VAL )
// continue;
p.x -= this.datum_params[0];
p.y -= this.datum_params[1];
p.z -= this.datum_params[2];
}
else if (this.datum_type === PJD_7PARAM) {
var Dx_BF = this.datum_params[0];
var Dy_BF = this.datum_params[1];
var Dz_BF = this.datum_params[2];
var Rx_BF = this.datum_params[3];
var Ry_BF = this.datum_params[4];
var Rz_BF = this.datum_params[5];
var M_BF = this.datum_params[6];
var x_tmp = (p.x - Dx_BF) / M_BF;
var y_tmp = (p.y - Dy_BF) / M_BF;
var z_tmp = (p.z - Dz_BF) / M_BF;
//if( x[io] === HUGE_VAL )
// continue;
p.x = x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp;
p.y = -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp;
p.z = Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp;
} //cs_geocentric_from_wgs84()
}
};
/** point object, nothing fancy, just allows values to be
passed back and forth by reference rather than by value.
Other point classes may be used as long as they have
x and y properties, which will get modified in the transform method.
*/
module.exports = datum;
},{}],31:[function(_dereq_,module,exports){
var PJD_3PARAM = 1;
var PJD_7PARAM = 2;
var PJD_GRIDSHIFT = 3;
var PJD_NODATUM = 5; // WGS84 or equivalent
var SRS_WGS84_SEMIMAJOR = 6378137; // only used in grid shift transforms
var SRS_WGS84_ESQUARED = 0.006694379990141316; //DGR: 2012-07-29
module.exports = function(source, dest, point) {
var wp, i, l;
function checkParams(fallback) {
return (fallback === PJD_3PARAM || fallback === PJD_7PARAM);
}
// Short cut if the datums are identical.
if (source.compare_datums(dest)) {
return point; // in this case, zero is sucess,
// whereas cs_compare_datums returns 1 to indicate TRUE
// confusing, should fix this
}
// Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
return point;
}
//DGR: 2012-07-29 : add nadgrids support (begin)
var src_a = source.a;
var src_es = source.es;
var dst_a = dest.a;
var dst_es = dest.es;
var fallback = source.datum_type;
// If this datum requires grid shifts, then apply it to geodetic coordinates.
if (fallback === PJD_GRIDSHIFT) {
if (this.apply_gridshift(source, 0, point) === 0) {
source.a = SRS_WGS84_SEMIMAJOR;
source.es = SRS_WGS84_ESQUARED;
}
else {
// try 3 or 7 params transformation or nothing ?
if (!source.datum_params) {
source.a = src_a;
source.es = source.es;
return point;
}
wp = 1;
for (i = 0, l = source.datum_params.length; i < l; i++) {
wp *= source.datum_params[i];
}
if (wp === 0) {
source.a = src_a;
source.es = source.es;
return point;
}
if (source.datum_params.length > 3) {
fallback = PJD_7PARAM;
}
else {
fallback = PJD_3PARAM;
}
}
}
if (dest.datum_type === PJD_GRIDSHIFT) {
dest.a = SRS_WGS84_SEMIMAJOR;
dest.es = SRS_WGS84_ESQUARED;
}
// Do we need to go through geocentric coordinates?
if (source.es !== dest.es || source.a !== dest.a || checkParams(fallback) || checkParams(dest.datum_type)) {
//DGR: 2012-07-29 : add nadgrids support (end)
// Convert to geocentric coordinates.
source.geodetic_to_geocentric(point);
// CHECK_RETURN;
// Convert between datums
if (checkParams(source.datum_type)) {
source.geocentric_to_wgs84(point);
// CHECK_RETURN;
}
if (checkParams(dest.datum_type)) {
dest.geocentric_from_wgs84(point);
// CHECK_RETURN;
}
// Convert back to geodetic coordinates
dest.geocentric_to_geodetic(point);
// CHECK_RETURN;
}
// Apply grid shift to destination if required
if (dest.datum_type === PJD_GRIDSHIFT) {
this.apply_gridshift(dest, 1, point);
// CHECK_RETURN;
}
source.a = src_a;
source.es = src_es;
dest.a = dst_a;
dest.es = dst_es;
return point;
};
},{}],32:[function(_dereq_,module,exports){
var globals = _dereq_('./global');
var parseProj = _dereq_('./projString');
var wkt = _dereq_('./wkt');
function defs(name) {
/*global console*/
var that = this;
if (arguments.length === 2) {
var def = arguments[1];
if (typeof def === 'string') {
if (def.charAt(0) === '+') {
defs[name] = parseProj(arguments[1]);
}
else {
defs[name] = wkt(arguments[1]);
}
} else {
defs[name] = def;
}
}
else if (arguments.length === 1) {
if (Array.isArray(name)) {
return name.map(function(v) {
if (Array.isArray(v)) {
defs.apply(that, v);
}
else {
defs(v);
}
});
}
else if (typeof name === 'string') {
if (name in defs) {
return defs[name];
}
}
else if ('EPSG' in name) {
defs['EPSG:' + name.EPSG] = name;
}
else if ('ESRI' in name) {
defs['ESRI:' + name.ESRI] = name;
}
else if ('IAU2000' in name) {
defs['IAU2000:' + name.IAU2000] = name;
}
else {
console.log(name);
}
return;
}
}
globals(defs);
module.exports = defs;
},{"./global":35,"./projString":38,"./wkt":66}],33:[function(_dereq_,module,exports){
var Datum = _dereq_('./constants/Datum');
var Ellipsoid = _dereq_('./constants/Ellipsoid');
var extend = _dereq_('./extend');
var datum = _dereq_('./datum');
var EPSLN = 1.0e-10;
// ellipoid pj_set_ell.c
var SIXTH = 0.1666666666666666667;
/* 1/6 */
var RA4 = 0.04722222222222222222;
/* 17/360 */
var RA6 = 0.02215608465608465608;
module.exports = function(json) {
// DGR 2011-03-20 : nagrids -> nadgrids
if (json.datumCode && json.datumCode !== 'none') {
var datumDef = Datum[json.datumCode];
if (datumDef) {
json.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
json.ellps = datumDef.ellipse;
json.datumName = datumDef.datumName ? datumDef.datumName : json.datumCode;
}
}
if (!json.a) { // do we have an ellipsoid?
var ellipse = Ellipsoid[json.ellps] ? Ellipsoid[json.ellps] : Ellipsoid.WGS84;
extend(json, ellipse);
}
if (json.rf && !json.b) {
json.b = (1.0 - 1.0 / json.rf) * json.a;
}
if (json.rf === 0 || Math.abs(json.a - json.b) < EPSLN) {
json.sphere = true;
json.b = json.a;
}
json.a2 = json.a * json.a; // used in geocentric
json.b2 = json.b * json.b; // used in geocentric
json.es = (json.a2 - json.b2) / json.a2; // e ^ 2
json.e = Math.sqrt(json.es); // eccentricity
if (json.R_A) {
json.a *= 1 - json.es * (SIXTH + json.es * (RA4 + json.es * RA6));
json.a2 = json.a * json.a;
json.b2 = json.b * json.b;
json.es = 0;
}
json.ep2 = (json.a2 - json.b2) / json.b2; // used in geocentric
if (!json.k0) {
json.k0 = 1.0; //default value
}
//DGR 2010-11-12: axis
if (!json.axis) {
json.axis = "enu";
}
if (!json.datum) {
json.datum = datum(json);
}
return json;
};
},{"./constants/Datum":25,"./constants/Ellipsoid":26,"./datum":30,"./extend":34}],34:[function(_dereq_,module,exports){
module.exports = function(destination, source) {
destination = destination || {};
var value, property;
if (!source) {
return destination;
}
for (property in source) {
value = source[property];
if (value !== undefined) {
destination[property] = value;
}
}
return destination;
};
},{}],35:[function(_dereq_,module,exports){
module.exports = function(defs) {
defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
defs('world_azimuthal_equidistant', "+proj=aeqd +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs");
defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
defs.WGS84 = defs['EPSG:4326'];
defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
defs.GOOGLE = defs['EPSG:3857'];
defs['EPSG:900913'] = defs['EPSG:3857'];
defs['EPSG:102113'] = defs['EPSG:3857'];
};
},{}],36:[function(_dereq_,module,exports){
var proj4 = _dereq_('./core');
proj4.defaultDatum = 'WGS84'; //default datum
proj4.Proj = _dereq_('./Proj');
proj4.WGS84 = new proj4.Proj('WGS84');
proj4.Point = _dereq_('./Point');
proj4.toPoint = _dereq_("./common/toPoint");
proj4.defs = _dereq_('./defs');
proj4.transform = _dereq_('./transform');
proj4.mgrs = _dereq_('mgrs');
proj4.version = _dereq_('../package.json').version;
_dereq_('./includedProjections')(proj4);
module.exports = proj4;
},{"../package.json":68,"./Point":1,"./Proj":2,"./common/toPoint":23,"./core":29,"./defs":32,"./includedProjections":"hTEDpn","./transform":65,"mgrs":67}],37:[function(_dereq_,module,exports){
var defs = _dereq_('./defs');
var wkt = _dereq_('./wkt');
var projStr = _dereq_('./projString');
function testObj(code){
return typeof code === 'string';
}
function testDef(code){
return code in defs;
}
function testWKT(code){
var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
return codeWords.reduce(function(a,b){
return a+1+code.indexOf(b);
},0);
}
function testProj(code){
return code[0] === '+';
}
function parse(code){
if (testObj(code)) {
//check to see if this is a WKT string
if (testDef(code)) {
return defs[code];
}
else if (testWKT(code)) {
return wkt(code);
}
else if (testProj(code)) {
return projStr(code);
}
}else{
return code;
}
}
module.exports = parse;
},{"./defs":32,"./projString":38,"./wkt":66}],38:[function(_dereq_,module,exports){
var D2R = 0.01745329251994329577;
var PrimeMeridian = _dereq_('./constants/PrimeMeridian');
var units = _dereq_('./constants/units');
module.exports = function(defData) {
var self = {};
var paramObj = {};
defData.split("+").map(function(v) {
return v.trim();
}).filter(function(a) {
return a;
}).forEach(function(a) {
var split = a.split("=");
split.push(true);
paramObj[split[0].toLowerCase()] = split[1];
});
var paramName, paramVal, paramOutname;
var params = {
proj: 'projName',
datum: 'datumCode',
rf: function(v) {
self.rf = parseFloat(v);
},
lat_0: function(v) {
self.lat0 = v * D2R;
},
lat_1: function(v) {
self.lat1 = v * D2R;
},
lat_2: function(v) {
self.lat2 = v * D2R;
},
lat_ts: function(v) {
self.lat_ts = v * D2R;
},
lon_0: function(v) {
self.long0 = v * D2R;
},
lon_1: function(v) {
self.long1 = v * D2R;
},
lon_2: function(v) {
self.long2 = v * D2R;
},
alpha: function(v) {
self.alpha = parseFloat(v) * D2R;
},
lonc: function(v) {
self.longc = v * D2R;
},
x_0: function(v) {
self.x0 = parseFloat(v);
},
y_0: function(v) {
self.y0 = parseFloat(v);
},
k_0: function(v) {
self.k0 = parseFloat(v);
},
k: function(v) {
self.k0 = parseFloat(v);
},
a: function(v) {
self.a = parseFloat(v);
},
b: function(v) {
self.b = parseFloat(v);
},
r_a: function() {
self.R_A = true;
},
zone: function(v) {
self.zone = parseInt(v, 10);
},
south: function() {
self.utmSouth = true;
},
towgs84: function(v) {
self.datum_params = v.split(",").map(function(a) {
return parseFloat(a);
});
},
to_meter: function(v) {
self.to_meter = parseFloat(v);
},
units: function(v) {
self.units = v;
if (units[v]) {
self.to_meter = units[v].to_meter;
}
},
from_greenwich: function(v) {
self.from_greenwich = v * D2R;
},
pm: function(v) {
self.from_greenwich = (PrimeMeridian[v] ? PrimeMeridian[v] : parseFloat(v)) * D2R;
},
nadgrids: function(v) {
if (v === '@null') {
self.datumCode = 'none';
}
else {
self.nadgrids = v;
}
},
axis: function(v) {
var legalAxis = "ewnsud";
if (v.length === 3 && legalAxis.indexOf(v.substr(0, 1)) !== -1 && legalAxis.indexOf(v.substr(1, 1)) !== -1 && legalAxis.indexOf(v.substr(2, 1)) !== -1) {
self.axis = v;
}
}
};
for (paramName in paramObj) {
paramVal = paramObj[paramName];
if (paramName in params) {
paramOutname = params[paramName];
if (typeof paramOutname === 'function') {
paramOutname(paramVal);
}
else {
self[paramOutname] = paramVal;
}
}
else {
self[paramName] = paramVal;
}
}
if(typeof self.datumCode === 'string' && self.datumCode !== "WGS84"){
self.datumCode = self.datumCode.toLowerCase();
}
return self;
};
},{"./constants/PrimeMeridian":27,"./constants/units":28}],39:[function(_dereq_,module,exports){
var projs = [
_dereq_('./projections/merc'),
_dereq_('./projections/longlat')
];
var names = {};
var projStore = [];
function add(proj, i) {
var len = projStore.length;
if (!proj.names) {
console.log(i);
return true;
}
projStore[len] = proj;
proj.names.forEach(function(n) {
names[n.toLowerCase()] = len;
});
return this;
}
exports.add = add;
exports.get = function(name) {
if (!name) {
return false;
}
var n = name.toLowerCase();
if (typeof names[n] !== 'undefined' && projStore[names[n]]) {
return projStore[names[n]];
}
};
exports.start = function() {
projs.forEach(add);
};
},{"./projections/longlat":51,"./projections/merc":52}],40:[function(_dereq_,module,exports){
var EPSLN = 1.0e-10;
var msfnz = _dereq_('../common/msfnz');
var qsfnz = _dereq_('../common/qsfnz');
var adjust_lon = _dereq_('../common/adjust_lon');
var asinz = _dereq_('../common/asinz');
exports.init = function() {
if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
return;
}
this.temp = this.b / this.a;
this.es = 1 - Math.pow(this.temp, 2);
this.e3 = Math.sqrt(this.es);
this.sin_po = Math.sin(this.lat1);
this.cos_po = Math.cos(this.lat1);
this.t1 = this.sin_po;
this.con = this.sin_po;
this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
this.qs1 = qsfnz(this.e3, this.sin_po, this.cos_po);
this.sin_po = Math.sin(this.lat2);
this.cos_po = Math.cos(this.lat2);
this.t2 = this.sin_po;
this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
this.qs2 = qsfnz(this.e3, this.sin_po, this.cos_po);
this.sin_po = Math.sin(this.lat0);
this.cos_po = Math.cos(this.lat0);
this.t3 = this.sin_po;
this.qs0 = qsfnz(this.e3, this.sin_po, this.cos_po);
if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
}
else {
this.ns0 = this.con;
}
this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
};
/* Albers Conical Equal Area forward equations--mapping lat,long to x,y
-------------------------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
this.sin_phi = Math.sin(lat);
this.cos_phi = Math.cos(lat);
var qs = qsfnz(this.e3, this.sin_phi, this.cos_phi);
var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
var theta = this.ns0 * adjust_lon(lon - this.long0);
var x = rh1 * Math.sin(theta) + this.x0;
var y = this.rh - rh1 * Math.cos(theta) + this.y0;
p.x = x;
p.y = y;
return p;
};
exports.inverse = function(p) {
var rh1, qs, con, theta, lon, lat;
p.x -= this.x0;
p.y = this.rh - p.y + this.y0;
if (this.ns0 >= 0) {
rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
con = 1;
}
else {
rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
con = -1;
}
theta = 0;
if (rh1 !== 0) {
theta = Math.atan2(con * p.x, con * p.y);
}
con = rh1 * this.ns0 / this.a;
if (this.sphere) {
lat = Math.asin((this.c - con * con) / (2 * this.ns0));
}
else {
qs = (this.c - con * con) / this.ns0;
lat = this.phi1z(this.e3, qs);
}
lon = adjust_lon(theta / this.ns0 + this.long0);
p.x = lon;
p.y = lat;
return p;
};
/* Function to compute phi1, the latitude for the inverse of the
Albers Conical Equal-Area projection.
-------------------------------------------*/
exports.phi1z = function(eccent, qs) {
var sinphi, cosphi, con, com, dphi;
var phi = asinz(0.5 * qs);
if (eccent < EPSLN) {
return phi;
}
var eccnts = eccent * eccent;
for (var i = 1; i <= 25; i++) {
sinphi = Math.sin(phi);
cosphi = Math.cos(phi);
con = eccent * sinphi;
com = 1 - con * con;
dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
phi = phi + dphi;
if (Math.abs(dphi) <= 1e-7) {
return phi;
}
}
return null;
};
exports.names = ["Albers_Conic_Equal_Area", "Albers", "aea"];
},{"../common/adjust_lon":5,"../common/asinz":6,"../common/msfnz":15,"../common/qsfnz":20}],41:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var mlfn = _dereq_('../common/mlfn');
var e0fn = _dereq_('../common/e0fn');
var e1fn = _dereq_('../common/e1fn');
var e2fn = _dereq_('../common/e2fn');
var e3fn = _dereq_('../common/e3fn');
var gN = _dereq_('../common/gN');
var asinz = _dereq_('../common/asinz');
var imlfn = _dereq_('../common/imlfn');
exports.init = function() {
this.sin_p12 = Math.sin(this.lat0);
this.cos_p12 = Math.cos(this.lat0);
};
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var sinphi = Math.sin(p.y);
var cosphi = Math.cos(p.y);
var dlon = adjust_lon(lon - this.long0);
var e0, e1, e2, e3, Mlp, Ml, tanphi, Nl1, Nl, psi, Az, G, H, GH, Hs, c, kp, cos_c, s, s2, s3, s4, s5;
if (this.sphere) {
if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
//North Pole case
p.x = this.x0 + this.a * (HALF_PI - lat) * Math.sin(dlon);
p.y = this.y0 - this.a * (HALF_PI - lat) * Math.cos(dlon);
return p;
}
else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
//South Pole case
p.x = this.x0 + this.a * (HALF_PI + lat) * Math.sin(dlon);
p.y = this.y0 + this.a * (HALF_PI + lat) * Math.cos(dlon);
return p;
}
else {
//default case
cos_c = this.sin_p12 * sinphi + this.cos_p12 * cosphi * Math.cos(dlon);
c = Math.acos(cos_c);
kp = c / Math.sin(c);
p.x = this.x0 + this.a * kp * cosphi * Math.sin(dlon);
p.y = this.y0 + this.a * kp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * Math.cos(dlon));
return p;
}
}
else {
e0 = e0fn(this.es);
e1 = e1fn(this.es);
e2 = e2fn(this.es);
e3 = e3fn(this.es);
if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
//North Pole case
Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
Ml = this.a * mlfn(e0, e1, e2, e3, lat);
p.x = this.x0 + (Mlp - Ml) * Math.sin(dlon);
p.y = this.y0 - (Mlp - Ml) * Math.cos(dlon);
return p;
}
else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
//South Pole case
Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
Ml = this.a * mlfn(e0, e1, e2, e3, lat);
p.x = this.x0 + (Mlp + Ml) * Math.sin(dlon);
p.y = this.y0 + (Mlp + Ml) * Math.cos(dlon);
return p;
}
else {
//Default case
tanphi = sinphi / cosphi;
Nl1 = gN(this.a, this.e, this.sin_p12);
Nl = gN(this.a, this.e, sinphi);
psi = Math.atan((1 - this.es) * tanphi + this.es * Nl1 * this.sin_p12 / (Nl * cosphi));
Az = Math.atan2(Math.sin(dlon), this.cos_p12 * Math.tan(psi) - this.sin_p12 * Math.cos(dlon));
if (Az === 0) {
s = Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
}
else if (Math.abs(Math.abs(Az) - Math.PI) <= EPSLN) {
s = -Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
}
else {
s = Math.asin(Math.sin(dlon) * Math.cos(psi) / Math.sin(Az));
}
G = this.e * this.sin_p12 / Math.sqrt(1 - this.es);
H = this.e * this.cos_p12 * Math.cos(Az) / Math.sqrt(1 - this.es);
GH = G * H;
Hs = H * H;
s2 = s * s;
s3 = s2 * s;
s4 = s3 * s;
s5 = s4 * s;
c = Nl1 * s * (1 - s2 * Hs * (1 - Hs) / 6 + s3 / 8 * GH * (1 - 2 * Hs) + s4 / 120 * (Hs * (4 - 7 * Hs) - 3 * G * G * (1 - 7 * Hs)) - s5 / 48 * GH);
p.x = this.x0 + c * Math.sin(Az);
p.y = this.y0 + c * Math.cos(Az);
return p;
}
}
};
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var rh, z, sinz, cosz, lon, lat, con, e0, e1, e2, e3, Mlp, M, N1, psi, Az, cosAz, tmp, A, B, D, Ee, F;
if (this.sphere) {
rh = Math.sqrt(p.x * p.x + p.y * p.y);
if (rh > (2 * HALF_PI * this.a)) {
return;
}
z = rh / this.a;
sinz = Math.sin(z);
cosz = Math.cos(z);
lon = this.long0;
if (Math.abs(rh) <= EPSLN) {
lat = this.lat0;
}
else {
lat = asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
con = Math.abs(this.lat0) - HALF_PI;
if (Math.abs(con) <= EPSLN) {
if (this.lat0 >= 0) {
lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
}
else {
lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
}
}
else {
/*con = cosz - this.sin_p12 * Math.sin(lat);
if ((Math.abs(con) < EPSLN) && (Math.abs(p.x) < EPSLN)) {
//no-op, just keep the lon value as is
} else {
var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
}*/
lon = adjust_lon(this.long0 + Math.atan2(p.x * sinz, rh * this.cos_p12 * cosz - p.y * this.sin_p12 * sinz));
}
}
p.x = lon;
p.y = lat;
return p;
}
else {
e0 = e0fn(this.es);
e1 = e1fn(this.es);
e2 = e2fn(this.es);
e3 = e3fn(this.es);
if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
//North pole case
Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
rh = Math.sqrt(p.x * p.x + p.y * p.y);
M = Mlp - rh;
lat = imlfn(M / this.a, e0, e1, e2, e3);
lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
p.x = lon;
p.y = lat;
return p;
}
else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
//South pole case
Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
rh = Math.sqrt(p.x * p.x + p.y * p.y);
M = rh - Mlp;
lat = imlfn(M / this.a, e0, e1, e2, e3);
lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
p.x = lon;
p.y = lat;
return p;
}
else {
//default case
rh = Math.sqrt(p.x * p.x + p.y * p.y);
Az = Math.atan2(p.x, p.y);
N1 = gN(this.a, this.e, this.sin_p12);
cosAz = Math.cos(Az);
tmp = this.e * this.cos_p12 * cosAz;
A = -tmp * tmp / (1 - this.es);
B = 3 * this.es * (1 - A) * this.sin_p12 * this.cos_p12 * cosAz / (1 - this.es);
D = rh / N1;
Ee = D - A * (1 + A) * Math.pow(D, 3) / 6 - B * (1 + 3 * A) * Math.pow(D, 4) / 24;
F = 1 - A * Ee * Ee / 2 - D * Ee * Ee * Ee / 6;
psi = Math.asin(this.sin_p12 * Math.cos(Ee) + this.cos_p12 * Math.sin(Ee) * cosAz);
lon = adjust_lon(this.long0 + Math.asin(Math.sin(Az) * Math.sin(Ee) / Math.cos(psi)));
lat = Math.atan((1 - this.es * F * this.sin_p12 / Math.sin(psi)) * Math.tan(psi) / (1 - this.es));
p.x = lon;
p.y = lat;
return p;
}
}
};
exports.names = ["Azimuthal_Equidistant", "aeqd"];
},{"../common/adjust_lon":5,"../common/asinz":6,"../common/e0fn":7,"../common/e1fn":8,"../common/e2fn":9,"../common/e3fn":10,"../common/gN":11,"../common/imlfn":12,"../common/mlfn":14}],42:[function(_dereq_,module,exports){
var mlfn = _dereq_('../common/mlfn');
var e0fn = _dereq_('../common/e0fn');
var e1fn = _dereq_('../common/e1fn');
var e2fn = _dereq_('../common/e2fn');
var e3fn = _dereq_('../common/e3fn');
var gN = _dereq_('../common/gN');
var adjust_lon = _dereq_('../common/adjust_lon');
var adjust_lat = _dereq_('../common/adjust_lat');
var imlfn = _dereq_('../common/imlfn');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
exports.init = function() {
if (!this.sphere) {
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
this.e2 = e2fn(this.es);
this.e3 = e3fn(this.es);
this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
}
};
/* Cassini forward equations--mapping lat,long to x,y
-----------------------------------------------------------------------*/
exports.forward = function(p) {
/* Forward equations
-----------------*/
var x, y;
var lam = p.x;
var phi = p.y;
lam = adjust_lon(lam - this.long0);
if (this.sphere) {
x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
}
else {
//ellipsoid
var sinphi = Math.sin(phi);
var cosphi = Math.cos(phi);
var nl = gN(this.a, this.e, sinphi);
var tl = Math.tan(phi) * Math.tan(phi);
var al = lam * Math.cos(phi);
var asq = al * al;
var cl = this.es * cosphi * cosphi / (1 - this.es);
var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
}
p.x = x + this.x0;
p.y = y + this.y0;
return p;
};
/* Inverse equations
-----------------*/
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var x = p.x / this.a;
var y = p.y / this.a;
var phi, lam;
if (this.sphere) {
var dd = y + this.lat0;
phi = Math.asin(Math.sin(dd) * Math.cos(x));
lam = Math.atan2(Math.tan(x), Math.cos(dd));
}
else {
/* ellipsoid */
var ml1 = this.ml0 / this.a + y;
var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
p.x = this.long0;
p.y = HALF_PI;
if (y < 0) {
p.y *= -1;
}
return p;
}
var nl1 = gN(this.a, this.e, Math.sin(phi1));
var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
var tl1 = Math.pow(Math.tan(phi1), 2);
var dl = x * this.a / nl1;
var dsq = dl * dl;
phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
}
p.x = adjust_lon(lam + this.long0);
p.y = adjust_lat(phi);
return p;
};
exports.names = ["Cassini", "Cassini_Soldner", "cass"];
},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":7,"../common/e1fn":8,"../common/e2fn":9,"../common/e3fn":10,"../common/gN":11,"../common/imlfn":12,"../common/mlfn":14}],43:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var qsfnz = _dereq_('../common/qsfnz');
var msfnz = _dereq_('../common/msfnz');
var iqsfnz = _dereq_('../common/iqsfnz');
/*
reference:
"Cartographic Projection Procedures for the UNIX Environment-
A User's Manual" by Gerald I. Evenden,
USGS Open File Report 90-284and Release 4 Interim Reports (2003)
*/
exports.init = function() {
//no-op
if (!this.sphere) {
this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
}
};
/* Cylindrical Equal Area forward equations--mapping lat,long to x,y
------------------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var x, y;
/* Forward equations
-----------------*/
var dlon = adjust_lon(lon - this.long0);
if (this.sphere) {
x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
}
else {
var qs = qsfnz(this.e, Math.sin(lat));
x = this.x0 + this.a * this.k0 * dlon;
y = this.y0 + this.a * qs * 0.5 / this.k0;
}
p.x = x;
p.y = y;
return p;
};
/* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
------------------------------------------------------------*/
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var lon, lat;
if (this.sphere) {
lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
}
else {
lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["cea"];
},{"../common/adjust_lon":5,"../common/iqsfnz":13,"../common/msfnz":15,"../common/qsfnz":20}],44:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var adjust_lat = _dereq_('../common/adjust_lat');
exports.init = function() {
this.x0 = this.x0 || 0;
this.y0 = this.y0 || 0;
this.lat0 = this.lat0 || 0;
this.long0 = this.long0 || 0;
this.lat_ts = this.lat_ts || 0;
this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
this.rc = Math.cos(this.lat_ts);
};
// forward equations--mapping lat,long to x,y
// -----------------------------------------------------------------
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var dlon = adjust_lon(lon - this.long0);
var dlat = adjust_lat(lat - this.lat0);
p.x = this.x0 + (this.a * dlon * this.rc);
p.y = this.y0 + (this.a * dlat);
return p;
};
// inverse equations--mapping x,y to lat/long
// -----------------------------------------------------------------
exports.inverse = function(p) {
var x = p.x;
var y = p.y;
p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
return p;
};
exports.names = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
},{"../common/adjust_lat":4,"../common/adjust_lon":5}],45:[function(_dereq_,module,exports){
var e0fn = _dereq_('../common/e0fn');
var e1fn = _dereq_('../common/e1fn');
var e2fn = _dereq_('../common/e2fn');
var e3fn = _dereq_('../common/e3fn');
var msfnz = _dereq_('../common/msfnz');
var mlfn = _dereq_('../common/mlfn');
var adjust_lon = _dereq_('../common/adjust_lon');
var adjust_lat = _dereq_('../common/adjust_lat');
var imlfn = _dereq_('../common/imlfn');
var EPSLN = 1.0e-10;
exports.init = function() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
// Standard Parallels cannot be equal and on opposite sides of the equator
if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
return;
}
this.lat2 = this.lat2 || this.lat1;
this.temp = this.b / this.a;
this.es = 1 - Math.pow(this.temp, 2);
this.e = Math.sqrt(this.es);
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
this.e2 = e2fn(this.es);
this.e3 = e3fn(this.es);
this.sinphi = Math.sin(this.lat1);
this.cosphi = Math.cos(this.lat1);
this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
this.ns = this.sinphi;
}
else {
this.sinphi = Math.sin(this.lat2);
this.cosphi = Math.cos(this.lat2);
this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
}
this.g = this.ml1 + this.ms1 / this.ns;
this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
this.rh = this.a * (this.g - this.ml0);
};
/* Equidistant Conic forward equations--mapping lat,long to x,y
-----------------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var rh1;
/* Forward equations
-----------------*/
if (this.sphere) {
rh1 = this.a * (this.g - lat);
}
else {
var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
rh1 = this.a * (this.g - ml);
}
var theta = this.ns * adjust_lon(lon - this.long0);
var x = this.x0 + rh1 * Math.sin(theta);
var y = this.y0 + this.rh - rh1 * Math.cos(theta);
p.x = x;
p.y = y;
return p;
};
/* Inverse equations
-----------------*/
exports.inverse = function(p) {
p.x -= this.x0;
p.y = this.rh - p.y + this.y0;
var con, rh1, lat, lon;
if (this.ns >= 0) {
rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
con = 1;
}
else {
rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
con = -1;
}
var theta = 0;
if (rh1 !== 0) {
theta = Math.atan2(con * p.x, con * p.y);
}
if (this.sphere) {
lon = adjust_lon(this.long0 + theta / this.ns);
lat = adjust_lat(this.g - rh1 / this.a);
p.x = lon;
p.y = lat;
return p;
}
else {
var ml = this.g - rh1 / this.a;
lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
lon = adjust_lon(this.long0 + theta / this.ns);
p.x = lon;
p.y = lat;
return p;
}
};
exports.names = ["Equidistant_Conic", "eqdc"];
},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":7,"../common/e1fn":8,"../common/e2fn":9,"../common/e3fn":10,"../common/imlfn":12,"../common/mlfn":14,"../common/msfnz":15}],46:[function(_dereq_,module,exports){
var FORTPI = Math.PI/4;
var srat = _dereq_('../common/srat');
var HALF_PI = Math.PI/2;
var MAX_ITER = 20;
exports.init = function() {
var sphi = Math.sin(this.lat0);
var cphi = Math.cos(this.lat0);
cphi *= cphi;
this.rc = Math.sqrt(1 - this.es) / (1 - this.es * sphi * sphi);
this.C = Math.sqrt(1 + this.es * cphi * cphi / (1 - this.es));
this.phic0 = Math.asin(sphi / this.C);
this.ratexp = 0.5 * this.C * this.e;
this.K = Math.tan(0.5 * this.phic0 + FORTPI) / (Math.pow(Math.tan(0.5 * this.lat0 + FORTPI), this.C) * srat(this.e * sphi, this.ratexp));
};
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
p.y = 2 * Math.atan(this.K * Math.pow(Math.tan(0.5 * lat + FORTPI), this.C) * srat(this.e * Math.sin(lat), this.ratexp)) - HALF_PI;
p.x = this.C * lon;
return p;
};
exports.inverse = function(p) {
var DEL_TOL = 1e-14;
var lon = p.x / this.C;
var lat = p.y;
var num = Math.pow(Math.tan(0.5 * lat + FORTPI) / this.K, 1 / this.C);
for (var i = MAX_ITER; i > 0; --i) {
lat = 2 * Math.atan(num * srat(this.e * Math.sin(p.y), - 0.5 * this.e)) - HALF_PI;
if (Math.abs(lat - p.y) < DEL_TOL) {
break;
}
p.y = lat;
}
/* convergence failed */
if (!i) {
return null;
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["gauss"];
},{"../common/srat":22}],47:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var EPSLN = 1.0e-10;
var asinz = _dereq_('../common/asinz');
/*
reference:
Wolfram Mathworld "Gnomonic Projection"
http://mathworld.wolfram.com/GnomonicProjection.html
Accessed: 12th November 2009
*/
exports.init = function() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
this.sin_p14 = Math.sin(this.lat0);
this.cos_p14 = Math.cos(this.lat0);
// Approximation for projecting points to the horizon (infinity)
this.infinity_dist = 1000 * this.a;
this.rc = 1;
};
/* Gnomonic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
exports.forward = function(p) {
var sinphi, cosphi; /* sin and cos value */
var dlon; /* delta longitude value */
var coslon; /* cos of longitude */
var ksp; /* scale factor */
var g;
var x, y;
var lon = p.x;
var lat = p.y;
/* Forward equations
-----------------*/
dlon = adjust_lon(lon - this.long0);
sinphi = Math.sin(lat);
cosphi = Math.cos(lat);
coslon = Math.cos(dlon);
g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
ksp = 1;
if ((g > 0) || (Math.abs(g) <= EPSLN)) {
x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
}
else {
// Point is in the opposing hemisphere and is unprojectable
// We still need to return a reasonable point, so we project
// to infinity, on a bearing
// equivalent to the northern hemisphere equivalent
// This is a reasonable approximation for short shapes and lines that
// straddle the horizon.
x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
}
p.x = x;
p.y = y;
return p;
};
exports.inverse = function(p) {
var rh; /* Rho */
var sinc, cosc;
var c;
var lon, lat;
/* Inverse equations
-----------------*/
p.x = (p.x - this.x0) / this.a;
p.y = (p.y - this.y0) / this.a;
p.x /= this.k0;
p.y /= this.k0;
if ((rh = Math.sqrt(p.x * p.x + p.y * p.y))) {
c = Math.atan2(rh, this.rc);
sinc = Math.sin(c);
cosc = Math.cos(c);
lat = asinz(cosc * this.sin_p14 + (p.y * sinc * this.cos_p14) / rh);
lon = Math.atan2(p.x * sinc, rh * this.cos_p14 * cosc - p.y * this.sin_p14 * sinc);
lon = adjust_lon(this.long0 + lon);
}
else {
lat = this.phic0;
lon = 0;
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["gnom"];
},{"../common/adjust_lon":5,"../common/asinz":6}],48:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
exports.init = function() {
this.a = 6377397.155;
this.es = 0.006674372230614;
this.e = Math.sqrt(this.es);
if (!this.lat0) {
this.lat0 = 0.863937979737193;
}
if (!this.long0) {
this.long0 = 0.7417649320975901 - 0.308341501185665;
}
/* if scale not set default to 0.9999 */
if (!this.k0) {
this.k0 = 0.9999;
}
this.s45 = 0.785398163397448; /* 45 */
this.s90 = 2 * this.s45;
this.fi0 = this.lat0;
this.e2 = this.es;
this.e = Math.sqrt(this.e2);
this.alfa = Math.sqrt(1 + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1 - this.e2));
this.uq = 1.04216856380474;
this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
this.g = Math.pow((1 + this.e * Math.sin(this.fi0)) / (1 - this.e * Math.sin(this.fi0)), this.alfa * this.e / 2);
this.k = Math.tan(this.u0 / 2 + this.s45) / Math.pow(Math.tan(this.fi0 / 2 + this.s45), this.alfa) * this.g;
this.k1 = this.k0;
this.n0 = this.a * Math.sqrt(1 - this.e2) / (1 - this.e2 * Math.pow(Math.sin(this.fi0), 2));
this.s0 = 1.37008346281555;
this.n = Math.sin(this.s0);
this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
this.ad = this.s90 - this.uq;
};
/* ellipsoid */
/* calculate xy from lat/lon */
/* Constants, identical to inverse transform function */
exports.forward = function(p) {
var gfi, u, deltav, s, d, eps, ro;
var lon = p.x;
var lat = p.y;
var delta_lon = adjust_lon(lon - this.long0);
/* Transformation */
gfi = Math.pow(((1 + this.e * Math.sin(lat)) / (1 - this.e * Math.sin(lat))), (this.alfa * this.e / 2));
u = 2 * (Math.atan(this.k * Math.pow(Math.tan(lat / 2 + this.s45), this.alfa) / gfi) - this.s45);
deltav = -delta_lon * this.alfa;
s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
eps = this.n * d;
ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2 + this.s45), this.n) / Math.pow(Math.tan(s / 2 + this.s45), this.n);
p.y = ro * Math.cos(eps) / 1;
p.x = ro * Math.sin(eps) / 1;
if (!this.czech) {
p.y *= -1;
p.x *= -1;
}
return (p);
};
/* calculate lat/lon from xy */
exports.inverse = function(p) {
var u, deltav, s, d, eps, ro, fi1;
var ok;
/* Transformation */
/* revert y, x*/
var tmp = p.x;
p.x = p.y;
p.y = tmp;
if (!this.czech) {
p.y *= -1;
p.x *= -1;
}
ro = Math.sqrt(p.x * p.x + p.y * p.y);
eps = Math.atan2(p.y, p.x);
d = eps / Math.sin(this.s0);
s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
p.x = this.long0 - deltav / this.alfa;
fi1 = u;
ok = 0;
var iter = 0;
do {
p.y = 2 * (Math.atan(Math.pow(this.k, - 1 / this.alfa) * Math.pow(Math.tan(u / 2 + this.s45), 1 / this.alfa) * Math.pow((1 + this.e * Math.sin(fi1)) / (1 - this.e * Math.sin(fi1)), this.e / 2)) - this.s45);
if (Math.abs(fi1 - p.y) < 0.0000000001) {
ok = 1;
}
fi1 = p.y;
iter += 1;
} while (ok === 0 && iter < 15);
if (iter >= 15) {
return null;
}
return (p);
};
exports.names = ["Krovak", "krovak"];
},{"../common/adjust_lon":5}],49:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
var FORTPI = Math.PI/4;
var EPSLN = 1.0e-10;
var qsfnz = _dereq_('../common/qsfnz');
var adjust_lon = _dereq_('../common/adjust_lon');
/*
reference
"New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
*/
exports.S_POLE = 1;
exports.N_POLE = 2;
exports.EQUIT = 3;
exports.OBLIQ = 4;
/* Initialize the Lambert Azimuthal Equal Area projection
------------------------------------------------------*/
exports.init = function() {
var t = Math.abs(this.lat0);
if (Math.abs(t - HALF_PI) < EPSLN) {
this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
}
else if (Math.abs(t) < EPSLN) {
this.mode = this.EQUIT;
}
else {
this.mode = this.OBLIQ;
}
if (this.es > 0) {
var sinphi;
this.qp = qsfnz(this.e, 1);
this.mmf = 0.5 / (1 - this.es);
this.apa = this.authset(this.es);
switch (this.mode) {
case this.N_POLE:
this.dd = 1;
break;
case this.S_POLE:
this.dd = 1;
break;
case this.EQUIT:
this.rq = Math.sqrt(0.5 * this.qp);
this.dd = 1 / this.rq;
this.xmf = 1;
this.ymf = 0.5 * this.qp;
break;
case this.OBLIQ:
this.rq = Math.sqrt(0.5 * this.qp);
sinphi = Math.sin(this.lat0);
this.sinb1 = qsfnz(this.e, sinphi) / this.qp;
this.cosb1 = Math.sqrt(1 - this.sinb1 * this.sinb1);
this.dd = Math.cos(this.lat0) / (Math.sqrt(1 - this.es * sinphi * sinphi) * this.rq * this.cosb1);
this.ymf = (this.xmf = this.rq) / this.dd;
this.xmf *= this.dd;
break;
}
}
else {
if (this.mode === this.OBLIQ) {
this.sinph0 = Math.sin(this.lat0);
this.cosph0 = Math.cos(this.lat0);
}
}
};
/* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
-----------------------------------------------------------------------*/
exports.forward = function(p) {
/* Forward equations
-----------------*/
var x, y, coslam, sinlam, sinphi, q, sinb, cosb, b, cosphi;
var lam = p.x;
var phi = p.y;
lam = adjust_lon(lam - this.long0);
if (this.sphere) {
sinphi = Math.sin(phi);
cosphi = Math.cos(phi);
coslam = Math.cos(lam);
if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
y = (this.mode === this.EQUIT) ? 1 + cosphi * coslam : 1 + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
if (y <= EPSLN) {
return null;
}
y = Math.sqrt(2 / y);
x = y * cosphi * Math.sin(lam);
y *= (this.mode === this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
}
else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
if (this.mode === this.N_POLE) {
coslam = -coslam;
}
if (Math.abs(phi + this.phi0) < EPSLN) {
return null;
}
y = FORTPI - phi * 0.5;
y = 2 * ((this.mode === this.S_POLE) ? Math.cos(y) : Math.sin(y));
x = y * Math.sin(lam);
y *= coslam;
}
}
else {
sinb = 0;
cosb = 0;
b = 0;
coslam = Math.cos(lam);
sinlam = Math.sin(lam);
sinphi = Math.sin(phi);
q = qsfnz(this.e, sinphi);
if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
sinb = q / this.qp;
cosb = Math.sqrt(1 - sinb * sinb);
}
switch (this.mode) {
case this.OBLIQ:
b = 1 + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
break;
case this.EQUIT:
b = 1 + cosb * coslam;
break;
case this.N_POLE:
b = HALF_PI + phi;
q = this.qp - q;
break;
case this.S_POLE:
b = phi - HALF_PI;
q = this.qp + q;
break;
}
if (Math.abs(b) < EPSLN) {
return null;
}
switch (this.mode) {
case this.OBLIQ:
case this.EQUIT:
b = Math.sqrt(2 / b);
if (this.mode === this.OBLIQ) {
y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
}
else {
y = (b = Math.sqrt(2 / (1 + cosb * coslam))) * sinb * this.ymf;
}
x = this.xmf * b * cosb * sinlam;
break;
case this.N_POLE:
case this.S_POLE:
if (q >= 0) {
x = (b = Math.sqrt(q)) * sinlam;
y = coslam * ((this.mode === this.S_POLE) ? b : -b);
}
else {
x = y = 0;
}
break;
}
}
p.x = this.a * x + this.x0;
p.y = this.a * y + this.y0;
return p;
};
/* Inverse equations
-----------------*/
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var x = p.x / this.a;
var y = p.y / this.a;
var lam, phi, cCe, sCe, q, rho, ab;
if (this.sphere) {
var cosz = 0,
rh, sinz = 0;
rh = Math.sqrt(x * x + y * y);
phi = rh * 0.5;
if (phi > 1) {
return null;
}
phi = 2 * Math.asin(phi);
if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
sinz = Math.sin(phi);
cosz = Math.cos(phi);
}
switch (this.mode) {
case this.EQUIT:
phi = (Math.abs(rh) <= EPSLN) ? 0 : Math.asin(y * sinz / rh);
x *= sinz;
y = cosz * rh;
break;
case this.OBLIQ:
phi = (Math.abs(rh) <= EPSLN) ? this.phi0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
x *= sinz * this.cosph0;
y = (cosz - Math.sin(phi) * this.sinph0) * rh;
break;
case this.N_POLE:
y = -y;
phi = HALF_PI - phi;
break;
case this.S_POLE:
phi -= HALF_PI;
break;
}
lam = (y === 0 && (this.mode === this.EQUIT || this.mode === this.OBLIQ)) ? 0 : Math.atan2(x, y);
}
else {
ab = 0;
if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
x /= this.dd;
y *= this.dd;
rho = Math.sqrt(x * x + y * y);
if (rho < EPSLN) {
p.x = 0;
p.y = this.phi0;
return p;
}
sCe = 2 * Math.asin(0.5 * rho / this.rq);
cCe = Math.cos(sCe);
x *= (sCe = Math.sin(sCe));
if (this.mode === this.OBLIQ) {
ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho;
q = this.qp * ab;
y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
}
else {
ab = y * sCe / rho;
q = this.qp * ab;
y = rho * cCe;
}
}
else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
if (this.mode === this.N_POLE) {
y = -y;
}
q = (x * x + y * y);
if (!q) {
p.x = 0;
p.y = this.phi0;
return p;
}
ab = 1 - q / this.qp;
if (this.mode === this.S_POLE) {
ab = -ab;
}
}
lam = Math.atan2(x, y);
phi = this.authlat(Math.asin(ab), this.apa);
}
p.x = adjust_lon(this.long0 + lam);
p.y = phi;
return p;
};
/* determine latitude from authalic latitude */
exports.P00 = 0.33333333333333333333;
exports.P01 = 0.17222222222222222222;
exports.P02 = 0.10257936507936507936;
exports.P10 = 0.06388888888888888888;
exports.P11 = 0.06640211640211640211;
exports.P20 = 0.01641501294219154443;
exports.authset = function(es) {
var t;
var APA = [];
APA[0] = es * this.P00;
t = es * es;
APA[0] += t * this.P01;
APA[1] = t * this.P10;
t *= es;
APA[0] += t * this.P02;
APA[1] += t * this.P11;
APA[2] = t * this.P20;
return APA;
};
exports.authlat = function(beta, APA) {
var t = beta + beta;
return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
};
exports.names = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
},{"../common/adjust_lon":5,"../common/qsfnz":20}],50:[function(_dereq_,module,exports){
var EPSLN = 1.0e-10;
var msfnz = _dereq_('../common/msfnz');
var tsfnz = _dereq_('../common/tsfnz');
var HALF_PI = Math.PI/2;
var sign = _dereq_('../common/sign');
var adjust_lon = _dereq_('../common/adjust_lon');
var phi2z = _dereq_('../common/phi2z');
exports.init = function() {
// array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
//double c_lat; /* center latitude */
//double c_lon; /* center longitude */
//double lat1; /* first standard parallel */
//double lat2; /* second standard parallel */
//double r_maj; /* major axis */
//double r_min; /* minor axis */
//double false_east; /* x offset in meters */
//double false_north; /* y offset in meters */
if (!this.lat2) {
this.lat2 = this.lat1;
} //if lat2 is not defined
if (!this.k0) {
this.k0 = 1;
}
this.x0 = this.x0 || 0;
this.y0 = this.y0 || 0;
// Standard Parallels cannot be equal and on opposite sides of the equator
if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
return;
}
var temp = this.b / this.a;
this.e = Math.sqrt(1 - temp * temp);
var sin1 = Math.sin(this.lat1);
var cos1 = Math.cos(this.lat1);
var ms1 = msfnz(this.e, sin1, cos1);
var ts1 = tsfnz(this.e, this.lat1, sin1);
var sin2 = Math.sin(this.lat2);
var cos2 = Math.cos(this.lat2);
var ms2 = msfnz(this.e, sin2, cos2);
var ts2 = tsfnz(this.e, this.lat2, sin2);
var ts0 = tsfnz(this.e, this.lat0, Math.sin(this.lat0));
if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
this.ns = Math.log(ms1 / ms2) / Math.log(ts1 / ts2);
}
else {
this.ns = sin1;
}
if (isNaN(this.ns)) {
this.ns = sin1;
}
this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
if (!this.title) {
this.title = "Lambert Conformal Conic";
}
};
// Lambert Conformal conic forward equations--mapping lat,long to x,y
// -----------------------------------------------------------------
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
// singular cases :
if (Math.abs(2 * Math.abs(lat) - Math.PI) <= EPSLN) {
lat = sign(lat) * (HALF_PI - 2 * EPSLN);
}
var con = Math.abs(Math.abs(lat) - HALF_PI);
var ts, rh1;
if (con > EPSLN) {
ts = tsfnz(this.e, lat, Math.sin(lat));
rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
}
else {
con = lat * this.ns;
if (con <= 0) {
return null;
}
rh1 = 0;
}
var theta = this.ns * adjust_lon(lon - this.long0);
p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
return p;
};
// Lambert Conformal Conic inverse equations--mapping x,y to lat/long
// -----------------------------------------------------------------
exports.inverse = function(p) {
var rh1, con, ts;
var lat, lon;
var x = (p.x - this.x0) / this.k0;
var y = (this.rh - (p.y - this.y0) / this.k0);
if (this.ns > 0) {
rh1 = Math.sqrt(x * x + y * y);
con = 1;
}
else {
rh1 = -Math.sqrt(x * x + y * y);
con = -1;
}
var theta = 0;
if (rh1 !== 0) {
theta = Math.atan2((con * x), (con * y));
}
if ((rh1 !== 0) || (this.ns > 0)) {
con = 1 / this.ns;
ts = Math.pow((rh1 / (this.a * this.f0)), con);
lat = phi2z(this.e, ts);
if (lat === -9999) {
return null;
}
}
else {
lat = -HALF_PI;
}
lon = adjust_lon(theta / this.ns + this.long0);
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"];
},{"../common/adjust_lon":5,"../common/msfnz":15,"../common/phi2z":16,"../common/sign":21,"../common/tsfnz":24}],51:[function(_dereq_,module,exports){
exports.init = function() {
//no-op for longlat
};
function identity(pt) {
return pt;
}
exports.forward = identity;
exports.inverse = identity;
exports.names = ["longlat", "identity"];
},{}],52:[function(_dereq_,module,exports){
var msfnz = _dereq_('../common/msfnz');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var R2D = 57.29577951308232088;
var adjust_lon = _dereq_('../common/adjust_lon');
var FORTPI = Math.PI/4;
var tsfnz = _dereq_('../common/tsfnz');
var phi2z = _dereq_('../common/phi2z');
exports.init = function() {
var con = this.b / this.a;
this.es = 1 - con * con;
if(!('x0' in this)){
this.x0 = 0;
}
if(!('y0' in this)){
this.y0 = 0;
}
this.e = Math.sqrt(this.es);
if (this.lat_ts) {
if (this.sphere) {
this.k0 = Math.cos(this.lat_ts);
}
else {
this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
}
}
else {
if (!this.k0) {
if (this.k) {
this.k0 = this.k;
}
else {
this.k0 = 1;
}
}
}
};
/* Mercator forward equations--mapping lat,long to x,y
--------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
// convert to radians
if (lat * R2D > 90 && lat * R2D < -90 && lon * R2D > 180 && lon * R2D < -180) {
return null;
}
var x, y;
if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
return null;
}
else {
if (this.sphere) {
x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
y = this.y0 + this.a * this.k0 * Math.log(Math.tan(FORTPI + 0.5 * lat));
}
else {
var sinphi = Math.sin(lat);
var ts = tsfnz(this.e, lat, sinphi);
x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
y = this.y0 - this.a * this.k0 * Math.log(ts);
}
p.x = x;
p.y = y;
return p;
}
};
/* Mercator inverse equations--mapping x,y to lat/long
--------------------------------------------------*/
exports.inverse = function(p) {
var x = p.x - this.x0;
var y = p.y - this.y0;
var lon, lat;
if (this.sphere) {
lat = HALF_PI - 2 * Math.atan(Math.exp(-y / (this.a * this.k0)));
}
else {
var ts = Math.exp(-y / (this.a * this.k0));
lat = phi2z(this.e, ts);
if (lat === -9999) {
return null;
}
}
lon = adjust_lon(this.long0 + x / (this.a * this.k0));
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
},{"../common/adjust_lon":5,"../common/msfnz":15,"../common/phi2z":16,"../common/tsfnz":24}],53:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
/*
reference
"New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
*/
/* Initialize the Miller Cylindrical projection
-------------------------------------------*/
exports.init = function() {
//no-op
};
/* Miller Cylindrical forward equations--mapping lat,long to x,y
------------------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
/* Forward equations
-----------------*/
var dlon = adjust_lon(lon - this.long0);
var x = this.x0 + this.a * dlon;
var y = this.y0 + this.a * Math.log(Math.tan((Math.PI / 4) + (lat / 2.5))) * 1.25;
p.x = x;
p.y = y;
return p;
};
/* Miller Cylindrical inverse equations--mapping x,y to lat/long
------------------------------------------------------------*/
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var lon = adjust_lon(this.long0 + p.x / this.a);
var lat = 2.5 * (Math.atan(Math.exp(0.8 * p.y / this.a)) - Math.PI / 4);
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Miller_Cylindrical", "mill"];
},{"../common/adjust_lon":5}],54:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var EPSLN = 1.0e-10;
exports.init = function() {};
/* Mollweide forward equations--mapping lat,long to x,y
----------------------------------------------------*/
exports.forward = function(p) {
/* Forward equations
-----------------*/
var lon = p.x;
var lat = p.y;
var delta_lon = adjust_lon(lon - this.long0);
var theta = lat;
var con = Math.PI * Math.sin(lat);
/* Iterate using the Newton-Raphson method to find theta
-----------------------------------------------------*/
for (var i = 0; true; i++) {
var delta_theta = -(theta + Math.sin(theta) - con) / (1 + Math.cos(theta));
theta += delta_theta;
if (Math.abs(delta_theta) < EPSLN) {
break;
}
}
theta /= 2;
/* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
this is done here because of precision problems with "cos(theta)"
--------------------------------------------------------------------------*/
if (Math.PI / 2 - Math.abs(lat) < EPSLN) {
delta_lon = 0;
}
var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
p.x = x;
p.y = y;
return p;
};
exports.inverse = function(p) {
var theta;
var arg;
/* Inverse equations
-----------------*/
p.x -= this.x0;
p.y -= this.y0;
arg = p.y / (1.4142135623731 * this.a);
/* Because of division by zero problems, 'arg' can not be 1. Therefore
a number very close to one is used instead.
-------------------------------------------------------------------*/
if (Math.abs(arg) > 0.999999999999) {
arg = 0.999999999999;
}
theta = Math.asin(arg);
var lon = adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
if (lon < (-Math.PI)) {
lon = -Math.PI;
}
if (lon > Math.PI) {
lon = Math.PI;
}
arg = (2 * theta + Math.sin(2 * theta)) / Math.PI;
if (Math.abs(arg) > 1) {
arg = 1;
}
var lat = Math.asin(arg);
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Mollweide", "moll"];
},{"../common/adjust_lon":5}],55:[function(_dereq_,module,exports){
var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
/*
reference
Department of Land and Survey Technical Circular 1973/32
http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
OSG Technical Report 4.1
http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
*/
/**
* iterations: Number of iterations to refine inverse transform.
* 0 -> km accuracy
* 1 -> m accuracy -- suitable for most mapping applications
* 2 -> mm accuracy
*/
exports.iterations = 1;
exports.init = function() {
this.A = [];
this.A[1] = 0.6399175073;
this.A[2] = -0.1358797613;
this.A[3] = 0.063294409;
this.A[4] = -0.02526853;
this.A[5] = 0.0117879;
this.A[6] = -0.0055161;
this.A[7] = 0.0026906;
this.A[8] = -0.001333;
this.A[9] = 0.00067;
this.A[10] = -0.00034;
this.B_re = [];
this.B_im = [];
this.B_re[1] = 0.7557853228;
this.B_im[1] = 0;
this.B_re[2] = 0.249204646;
this.B_im[2] = 0.003371507;
this.B_re[3] = -0.001541739;
this.B_im[3] = 0.041058560;
this.B_re[4] = -0.10162907;
this.B_im[4] = 0.01727609;
this.B_re[5] = -0.26623489;
this.B_im[5] = -0.36249218;
this.B_re[6] = -0.6870983;
this.B_im[6] = -1.1651967;
this.C_re = [];
this.C_im = [];
this.C_re[1] = 1.3231270439;
this.C_im[1] = 0;
this.C_re[2] = -0.577245789;
this.C_im[2] = -0.007809598;
this.C_re[3] = 0.508307513;
this.C_im[3] = -0.112208952;
this.C_re[4] = -0.15094762;
this.C_im[4] = 0.18200602;
this.C_re[5] = 1.01418179;
this.C_im[5] = 1.64497696;
this.C_re[6] = 1.9660549;
this.C_im[6] = 2.5127645;
this.D = [];
this.D[1] = 1.5627014243;
this.D[2] = 0.5185406398;
this.D[3] = -0.03333098;
this.D[4] = -0.1052906;
this.D[5] = -0.0368594;
this.D[6] = 0.007317;
this.D[7] = 0.01220;
this.D[8] = 0.00394;
this.D[9] = -0.0013;
};
/**
New Zealand Map Grid Forward - long/lat to x/y
long/lat in radians
*/
exports.forward = function(p) {
var n;
var lon = p.x;
var lat = p.y;
var delta_lat = lat - this.lat0;
var delta_lon = lon - this.long0;
// 1. Calculate d_phi and d_psi ... // and d_lambda
// For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
var d_phi = delta_lat / SEC_TO_RAD * 1E-5;
var d_lambda = delta_lon;
var d_phi_n = 1; // d_phi^0
var d_psi = 0;
for (n = 1; n <= 10; n++) {
d_phi_n = d_phi_n * d_phi;
d_psi = d_psi + this.A[n] * d_phi_n;
}
// 2. Calculate theta
var th_re = d_psi;
var th_im = d_lambda;
// 3. Calculate z
var th_n_re = 1;
var th_n_im = 0; // theta^0
var th_n_re1;
var th_n_im1;
var z_re = 0;
var z_im = 0;
for (n = 1; n <= 6; n++) {
th_n_re1 = th_n_re * th_re - th_n_im * th_im;
th_n_im1 = th_n_im * th_re + th_n_re * th_im;
th_n_re = th_n_re1;
th_n_im = th_n_im1;
z_re = z_re + this.B_re[n] * th_n_re - this.B_im[n] * th_n_im;
z_im = z_im + this.B_im[n] * th_n_re + this.B_re[n] * th_n_im;
}
// 4. Calculate easting and northing
p.x = (z_im * this.a) + this.x0;
p.y = (z_re * this.a) + this.y0;
return p;
};
/**
New Zealand Map Grid Inverse - x/y to long/lat
*/
exports.inverse = function(p) {
var n;
var x = p.x;
var y = p.y;
var delta_x = x - this.x0;
var delta_y = y - this.y0;
// 1. Calculate z
var z_re = delta_y / this.a;
var z_im = delta_x / this.a;
// 2a. Calculate theta - first approximation gives km accuracy
var z_n_re = 1;
var z_n_im = 0; // z^0
var z_n_re1;
var z_n_im1;
var th_re = 0;
var th_im = 0;
for (n = 1; n <= 6; n++) {
z_n_re1 = z_n_re * z_re - z_n_im * z_im;
z_n_im1 = z_n_im * z_re + z_n_re * z_im;
z_n_re = z_n_re1;
z_n_im = z_n_im1;
th_re = th_re + this.C_re[n] * z_n_re - this.C_im[n] * z_n_im;
th_im = th_im + this.C_im[n] * z_n_re + this.C_re[n] * z_n_im;
}
// 2b. Iterate to refine the accuracy of the calculation
// 0 iterations gives km accuracy
// 1 iteration gives m accuracy -- good enough for most mapping applications
// 2 iterations bives mm accuracy
for (var i = 0; i < this.iterations; i++) {
var th_n_re = th_re;
var th_n_im = th_im;
var th_n_re1;
var th_n_im1;
var num_re = z_re;
var num_im = z_im;
for (n = 2; n <= 6; n++) {
th_n_re1 = th_n_re * th_re - th_n_im * th_im;
th_n_im1 = th_n_im * th_re + th_n_re * th_im;
th_n_re = th_n_re1;
th_n_im = th_n_im1;
num_re = num_re + (n - 1) * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
num_im = num_im + (n - 1) * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
}
th_n_re = 1;
th_n_im = 0;
var den_re = this.B_re[1];
var den_im = this.B_im[1];
for (n = 2; n <= 6; n++) {
th_n_re1 = th_n_re * th_re - th_n_im * th_im;
th_n_im1 = th_n_im * th_re + th_n_re * th_im;
th_n_re = th_n_re1;
th_n_im = th_n_im1;
den_re = den_re + n * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
den_im = den_im + n * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
}
// Complex division
var den2 = den_re * den_re + den_im * den_im;
th_re = (num_re * den_re + num_im * den_im) / den2;
th_im = (num_im * den_re - num_re * den_im) / den2;
}
// 3. Calculate d_phi ... // and d_lambda
var d_psi = th_re;
var d_lambda = th_im;
var d_psi_n = 1; // d_psi^0
var d_phi = 0;
for (n = 1; n <= 9; n++) {
d_psi_n = d_psi_n * d_psi;
d_phi = d_phi + this.D[n] * d_psi_n;
}
// 4. Calculate latitude and longitude
// d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
var lat = this.lat0 + (d_phi * SEC_TO_RAD * 1E5);
var lon = this.long0 + d_lambda;
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["New_Zealand_Map_Grid", "nzmg"];
},{}],56:[function(_dereq_,module,exports){
var tsfnz = _dereq_('../common/tsfnz');
var adjust_lon = _dereq_('../common/adjust_lon');
var phi2z = _dereq_('../common/phi2z');
var HALF_PI = Math.PI/2;
var FORTPI = Math.PI/4;
var EPSLN = 1.0e-10;
/* Initialize the Oblique Mercator projection
------------------------------------------*/
exports.init = function() {
this.no_off = this.no_off || false;
this.no_rot = this.no_rot || false;
if (isNaN(this.k0)) {
this.k0 = 1;
}
var sinlat = Math.sin(this.lat0);
var coslat = Math.cos(this.lat0);
var con = this.e * sinlat;
this.bl = Math.sqrt(1 + this.es / (1 - this.es) * Math.pow(coslat, 4));
this.al = this.a * this.bl * this.k0 * Math.sqrt(1 - this.es) / (1 - con * con);
var t0 = tsfnz(this.e, this.lat0, sinlat);
var dl = this.bl / coslat * Math.sqrt((1 - this.es) / (1 - con * con));
if (dl * dl < 1) {
dl = 1;
}
var fl;
var gl;
if (!isNaN(this.longc)) {
//Central point and azimuth method
if (this.lat0 >= 0) {
fl = dl + Math.sqrt(dl * dl - 1);
}
else {
fl = dl - Math.sqrt(dl * dl - 1);
}
this.el = fl * Math.pow(t0, this.bl);
gl = 0.5 * (fl - 1 / fl);
this.gamma0 = Math.asin(Math.sin(this.alpha) / dl);
this.long0 = this.longc - Math.asin(gl * Math.tan(this.gamma0)) / this.bl;
}
else {
//2 points method
var t1 = tsfnz(this.e, this.lat1, Math.sin(this.lat1));
var t2 = tsfnz(this.e, this.lat2, Math.sin(this.lat2));
if (this.lat0 >= 0) {
this.el = (dl + Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
}
else {
this.el = (dl - Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
}
var hl = Math.pow(t1, this.bl);
var ll = Math.pow(t2, this.bl);
fl = this.el / hl;
gl = 0.5 * (fl - 1 / fl);
var jl = (this.el * this.el - ll * hl) / (this.el * this.el + ll * hl);
var pl = (ll - hl) / (ll + hl);
var dlon12 = adjust_lon(this.long1 - this.long2);
this.long0 = 0.5 * (this.long1 + this.long2) - Math.atan(jl * Math.tan(0.5 * this.bl * (dlon12)) / pl) / this.bl;
this.long0 = adjust_lon(this.long0);
var dlon10 = adjust_lon(this.long1 - this.long0);
this.gamma0 = Math.atan(Math.sin(this.bl * (dlon10)) / gl);
this.alpha = Math.asin(dl * Math.sin(this.gamma0));
}
if (this.no_off) {
this.uc = 0;
}
else {
if (this.lat0 >= 0) {
this.uc = this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
}
else {
this.uc = -1 * this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
}
}
};
/* Oblique Mercator forward equations--mapping lat,long to x,y
----------------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var dlon = adjust_lon(lon - this.long0);
var us, vs;
var con;
if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
if (lat > 0) {
con = -1;
}
else {
con = 1;
}
vs = this.al / this.bl * Math.log(Math.tan(FORTPI + con * this.gamma0 * 0.5));
us = -1 * con * HALF_PI * this.al / this.bl;
}
else {
var t = tsfnz(this.e, lat, Math.sin(lat));
var ql = this.el / Math.pow(t, this.bl);
var sl = 0.5 * (ql - 1 / ql);
var tl = 0.5 * (ql + 1 / ql);
var vl = Math.sin(this.bl * (dlon));
var ul = (sl * Math.sin(this.gamma0) - vl * Math.cos(this.gamma0)) / tl;
if (Math.abs(Math.abs(ul) - 1) <= EPSLN) {
vs = Number.POSITIVE_INFINITY;
}
else {
vs = 0.5 * this.al * Math.log((1 - ul) / (1 + ul)) / this.bl;
}
if (Math.abs(Math.cos(this.bl * (dlon))) <= EPSLN) {
us = this.al * this.bl * (dlon);
}
else {
us = this.al * Math.atan2(sl * Math.cos(this.gamma0) + vl * Math.sin(this.gamma0), Math.cos(this.bl * dlon)) / this.bl;
}
}
if (this.no_rot) {
p.x = this.x0 + us;
p.y = this.y0 + vs;
}
else {
us -= this.uc;
p.x = this.x0 + vs * Math.cos(this.alpha) + us * Math.sin(this.alpha);
p.y = this.y0 + us * Math.cos(this.alpha) - vs * Math.sin(this.alpha);
}
return p;
};
exports.inverse = function(p) {
var us, vs;
if (this.no_rot) {
vs = p.y - this.y0;
us = p.x - this.x0;
}
else {
vs = (p.x - this.x0) * Math.cos(this.alpha) - (p.y - this.y0) * Math.sin(this.alpha);
us = (p.y - this.y0) * Math.cos(this.alpha) + (p.x - this.x0) * Math.sin(this.alpha);
us += this.uc;
}
var qp = Math.exp(-1 * this.bl * vs / this.al);
var sp = 0.5 * (qp - 1 / qp);
var tp = 0.5 * (qp + 1 / qp);
var vp = Math.sin(this.bl * us / this.al);
var up = (vp * Math.cos(this.gamma0) + sp * Math.sin(this.gamma0)) / tp;
var ts = Math.pow(this.el / Math.sqrt((1 + up) / (1 - up)), 1 / this.bl);
if (Math.abs(up - 1) < EPSLN) {
p.x = this.long0;
p.y = HALF_PI;
}
else if (Math.abs(up + 1) < EPSLN) {
p.x = this.long0;
p.y = -1 * HALF_PI;
}
else {
p.y = phi2z(this.e, ts);
p.x = adjust_lon(this.long0 - Math.atan2(sp * Math.cos(this.gamma0) - vp * Math.sin(this.gamma0), Math.cos(this.bl * us / this.al)) / this.bl);
}
return p;
};
exports.names = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"];
},{"../common/adjust_lon":5,"../common/phi2z":16,"../common/tsfnz":24}],57:[function(_dereq_,module,exports){
var e0fn = _dereq_('../common/e0fn');
var e1fn = _dereq_('../common/e1fn');
var e2fn = _dereq_('../common/e2fn');
var e3fn = _dereq_('../common/e3fn');
var adjust_lon = _dereq_('../common/adjust_lon');
var adjust_lat = _dereq_('../common/adjust_lat');
var mlfn = _dereq_('../common/mlfn');
var EPSLN = 1.0e-10;
var gN = _dereq_('../common/gN');
var MAX_ITER = 20;
exports.init = function() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
this.temp = this.b / this.a;
this.es = 1 - Math.pow(this.temp, 2); // devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
this.e = Math.sqrt(this.es);
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
this.e2 = e2fn(this.es);
this.e3 = e3fn(this.es);
this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0); //si que des zeros le calcul ne se fait pas
};
/* Polyconic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var x, y, el;
var dlon = adjust_lon(lon - this.long0);
el = dlon * Math.sin(lat);
if (this.sphere) {
if (Math.abs(lat) <= EPSLN) {
x = this.a * dlon;
y = -1 * this.a * this.lat0;
}
else {
x = this.a * Math.sin(el) / Math.tan(lat);
y = this.a * (adjust_lat(lat - this.lat0) + (1 - Math.cos(el)) / Math.tan(lat));
}
}
else {
if (Math.abs(lat) <= EPSLN) {
x = this.a * dlon;
y = -1 * this.ml0;
}
else {
var nl = gN(this.a, this.e, Math.sin(lat)) / Math.tan(lat);
x = nl * Math.sin(el);
y = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat) - this.ml0 + nl * (1 - Math.cos(el));
}
}
p.x = x + this.x0;
p.y = y + this.y0;
return p;
};
/* Inverse equations
-----------------*/
exports.inverse = function(p) {
var lon, lat, x, y, i;
var al, bl;
var phi, dphi;
x = p.x - this.x0;
y = p.y - this.y0;
if (this.sphere) {
if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
lon = adjust_lon(x / this.a + this.long0);
lat = 0;
}
else {
al = this.lat0 + y / this.a;
bl = x * x / this.a / this.a + al * al;
phi = al;
var tanphi;
for (i = MAX_ITER; i; --i) {
tanphi = Math.tan(phi);
dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
phi += dphi;
if (Math.abs(dphi) <= EPSLN) {
lat = phi;
break;
}
}
lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
}
}
else {
if (Math.abs(y + this.ml0) <= EPSLN) {
lat = 0;
lon = adjust_lon(this.long0 + x / this.a);
}
else {
al = (this.ml0 + y) / this.a;
bl = x * x / this.a / this.a + al * al;
phi = al;
var cl, mln, mlnp, ma;
var con;
for (i = MAX_ITER; i; --i) {
con = this.e * Math.sin(phi);
cl = Math.sqrt(1 - con * con) * Math.tan(phi);
mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
ma = mln / this.a;
dphi = (al * (cl * ma + 1) - ma - 0.5 * cl * (ma * ma + bl)) / (this.es * Math.sin(2 * phi) * (ma * ma + bl - 2 * al * ma) / (4 * cl) + (al - ma) * (cl * mlnp - 2 / Math.sin(2 * phi)) - mlnp);
phi -= dphi;
if (Math.abs(dphi) <= EPSLN) {
lat = phi;
break;
}
}
//lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
}
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Polyconic", "poly"];
},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":7,"../common/e1fn":8,"../common/e2fn":9,"../common/e3fn":10,"../common/gN":11,"../common/mlfn":14}],58:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var adjust_lat = _dereq_('../common/adjust_lat');
var pj_enfn = _dereq_('../common/pj_enfn');
var MAX_ITER = 20;
var pj_mlfn = _dereq_('../common/pj_mlfn');
var pj_inv_mlfn = _dereq_('../common/pj_inv_mlfn');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var asinz = _dereq_('../common/asinz');
exports.init = function() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
if (!this.sphere) {
this.en = pj_enfn(this.es);
}
else {
this.n = 1;
this.m = 0;
this.es = 0;
this.C_y = Math.sqrt((this.m + 1) / this.n);
this.C_x = this.C_y / (this.m + 1);
}
};
/* Sinusoidal forward equations--mapping lat,long to x,y
-----------------------------------------------------*/
exports.forward = function(p) {
var x, y;
var lon = p.x;
var lat = p.y;
/* Forward equations
-----------------*/
lon = adjust_lon(lon - this.long0);
if (this.sphere) {
if (!this.m) {
lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
}
else {
var k = this.n * Math.sin(lat);
for (var i = MAX_ITER; i; --i) {
var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
lat -= V;
if (Math.abs(V) < EPSLN) {
break;
}
}
}
x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
y = this.a * this.C_y * lat;
}
else {
var s = Math.sin(lat);
var c = Math.cos(lat);
y = this.a * pj_mlfn(lat, s, c, this.en);
x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
}
p.x = x;
p.y = y;
return p;
};
exports.inverse = function(p) {
var lat, temp, lon, s;
p.x -= this.x0;
lon = p.x / this.a;
p.y -= this.y0;
lat = p.y / this.a;
if (this.sphere) {
lat /= this.C_y;
lon = lon / (this.C_x * (this.m + Math.cos(lat)));
if (this.m) {
lat = asinz((this.m * lat + Math.sin(lat)) / this.n);
}
else if (this.n !== 1) {
lat = asinz(Math.sin(lat) / this.n);
}
lon = adjust_lon(lon + this.long0);
lat = adjust_lat(lat);
}
else {
lat = pj_inv_mlfn(p.y / this.a, this.es, this.en);
s = Math.abs(lat);
if (s < HALF_PI) {
s = Math.sin(lat);
temp = this.long0 + p.x * Math.sqrt(1 - this.es * s * s) / (this.a * Math.cos(lat));
//temp = this.long0 + p.x / (this.a * Math.cos(lat));
lon = adjust_lon(temp);
}
else if ((s - EPSLN) < HALF_PI) {
lon = this.long0;
}
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Sinusoidal", "sinu"];
},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/asinz":6,"../common/pj_enfn":17,"../common/pj_inv_mlfn":18,"../common/pj_mlfn":19}],59:[function(_dereq_,module,exports){
/*
references:
Formules et constantes pour le Calcul pour la
projection cylindrique conforme à axe oblique et pour la transformation entre
des systèmes de référence.
http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
*/
exports.init = function() {
var phy0 = this.lat0;
this.lambda0 = this.long0;
var sinPhy0 = Math.sin(phy0);
var semiMajorAxis = this.a;
var invF = this.rf;
var flattening = 1 / invF;
var e2 = 2 * flattening - Math.pow(flattening, 2);
var e = this.e = Math.sqrt(e2);
this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2));
this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4));
this.b0 = Math.asin(sinPhy0 / this.alpha);
var k1 = Math.log(Math.tan(Math.PI / 4 + this.b0 / 2));
var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
};
exports.forward = function(p) {
var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
var S = -this.alpha * (Sa1 + Sa2) + this.K;
// spheric latitude
var b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
// spheric longitude
var I = this.alpha * (p.x - this.lambda0);
// psoeudo equatorial rotation
var rotI = Math.atan(Math.sin(I) / (Math.sin(this.b0) * Math.tan(b) + Math.cos(this.b0) * Math.cos(I)));
var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) - Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
p.x = this.R * rotI + this.x0;
return p;
};
exports.inverse = function(p) {
var Y = p.x - this.x0;
var X = p.y - this.y0;
var rotI = Y / this.R;
var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4);
var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB) + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
var I = Math.atan(Math.sin(rotI) / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0) * Math.tan(rotB)));
var lambda = this.lambda0 + I / this.alpha;
var S = 0;
var phy = b;
var prevPhy = -1000;
var iteration = 0;
while (Math.abs(phy - prevPhy) > 0.0000001) {
if (++iteration > 20) {
//...reportError("omercFwdInfinity");
return;
}
//S = Math.log(Math.tan(Math.PI / 4 + phy / 2));
S = 1 / this.alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - this.K) + this.e * Math.log(Math.tan(Math.PI / 4 + Math.asin(this.e * Math.sin(phy)) / 2));
prevPhy = phy;
phy = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
}
p.x = lambda;
p.y = phy;
return p;
};
exports.names = ["somerc"];
},{}],60:[function(_dereq_,module,exports){
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var sign = _dereq_('../common/sign');
var msfnz = _dereq_('../common/msfnz');
var tsfnz = _dereq_('../common/tsfnz');
var phi2z = _dereq_('../common/phi2z');
var adjust_lon = _dereq_('../common/adjust_lon');
exports.ssfn_ = function(phit, sinphi, eccen) {
sinphi *= eccen;
return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
};
exports.init = function() {
this.coslat0 = Math.cos(this.lat0);
this.sinlat0 = Math.sin(this.lat0);
if (this.sphere) {
if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
this.k0 = 0.5 * (1 + sign(this.lat0) * Math.sin(this.lat_ts));
}
}
else {
if (Math.abs(this.coslat0) <= EPSLN) {
if (this.lat0 > 0) {
//North pole
//trace('stere:north pole');
this.con = 1;
}
else {
//South pole
//trace('stere:south pole');
this.con = -1;
}
}
this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e));
if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
this.k0 = 0.5 * this.cons * msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts));
}
this.ms1 = msfnz(this.e, this.sinlat0, this.coslat0);
this.X0 = 2 * Math.atan(this.ssfn_(this.lat0, this.sinlat0, this.e)) - HALF_PI;
this.cosX0 = Math.cos(this.X0);
this.sinX0 = Math.sin(this.X0);
}
};
// Stereographic forward equations--mapping lat,long to x,y
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var sinlat = Math.sin(lat);
var coslat = Math.cos(lat);
var A, X, sinX, cosX, ts, rh;
var dlon = adjust_lon(lon - this.long0);
if (Math.abs(Math.abs(lon - this.long0) - Math.PI) <= EPSLN && Math.abs(lat + this.lat0) <= EPSLN) {
//case of the origine point
//trace('stere:this is the origin point');
p.x = NaN;
p.y = NaN;
return p;
}
if (this.sphere) {
//trace('stere:sphere case');
A = 2 * this.k0 / (1 + this.sinlat0 * sinlat + this.coslat0 * coslat * Math.cos(dlon));
p.x = this.a * A * coslat * Math.sin(dlon) + this.x0;
p.y = this.a * A * (this.coslat0 * sinlat - this.sinlat0 * coslat * Math.cos(dlon)) + this.y0;
return p;
}
else {
X = 2 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - HALF_PI;
cosX = Math.cos(X);
sinX = Math.sin(X);
if (Math.abs(this.coslat0) <= EPSLN) {
ts = tsfnz(this.e, lat * this.con, this.con * sinlat);
rh = 2 * this.a * this.k0 * ts / this.cons;
p.x = this.x0 + rh * Math.sin(lon - this.long0);
p.y = this.y0 - this.con * rh * Math.cos(lon - this.long0);
//trace(p.toString());
return p;
}
else if (Math.abs(this.sinlat0) < EPSLN) {
//Eq
//trace('stere:equateur');
A = 2 * this.a * this.k0 / (1 + cosX * Math.cos(dlon));
p.y = A * sinX;
}
else {
//other case
//trace('stere:normal case');
A = 2 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1 + this.sinX0 * sinX + this.cosX0 * cosX * Math.cos(dlon)));
p.y = A * (this.cosX0 * sinX - this.sinX0 * cosX * Math.cos(dlon)) + this.y0;
}
p.x = A * cosX * Math.sin(dlon) + this.x0;
}
//trace(p.toString());
return p;
};
//* Stereographic inverse equations--mapping x,y to lat/long
exports.inverse = function(p) {
p.x -= this.x0;
p.y -= this.y0;
var lon, lat, ts, ce, Chi;
var rh = Math.sqrt(p.x * p.x + p.y * p.y);
if (this.sphere) {
var c = 2 * Math.atan(rh / (0.5 * this.a * this.k0));
lon = this.long0;
lat = this.lat0;
if (rh <= EPSLN) {
p.x = lon;
p.y = lat;
return p;
}
lat = Math.asin(Math.cos(c) * this.sinlat0 + p.y * Math.sin(c) * this.coslat0 / rh);
if (Math.abs(this.coslat0) < EPSLN) {
if (this.lat0 > 0) {
lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
}
else {
lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
}
}
else {
lon = adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(c), rh * this.coslat0 * Math.cos(c) - p.y * this.sinlat0 * Math.sin(c)));
}
p.x = lon;
p.y = lat;
return p;
}
else {
if (Math.abs(this.coslat0) <= EPSLN) {
if (rh <= EPSLN) {
lat = this.lat0;
lon = this.long0;
p.x = lon;
p.y = lat;
//trace(p.toString());
return p;
}
p.x *= this.con;
p.y *= this.con;
ts = rh * this.cons / (2 * this.a * this.k0);
lat = this.con * phi2z(this.e, ts);
lon = this.con * adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1 * p.y));
}
else {
ce = 2 * Math.atan(rh * this.cosX0 / (2 * this.a * this.k0 * this.ms1));
lon = this.long0;
if (rh <= EPSLN) {
Chi = this.X0;
}
else {
Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh);
lon = adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(ce), rh * this.cosX0 * Math.cos(ce) - p.y * this.sinX0 * Math.sin(ce)));
}
lat = -1 * phi2z(this.e, Math.tan(0.5 * (HALF_PI + Chi)));
}
}
p.x = lon;
p.y = lat;
//trace(p.toString());
return p;
};
exports.names = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
},{"../common/adjust_lon":5,"../common/msfnz":15,"../common/phi2z":16,"../common/sign":21,"../common/tsfnz":24}],61:[function(_dereq_,module,exports){
var gauss = _dereq_('./gauss');
var adjust_lon = _dereq_('../common/adjust_lon');
exports.init = function() {
gauss.init.apply(this);
if (!this.rc) {
return;
}
this.sinc0 = Math.sin(this.phic0);
this.cosc0 = Math.cos(this.phic0);
this.R2 = 2 * this.rc;
if (!this.title) {
this.title = "Oblique Stereographic Alternative";
}
};
exports.forward = function(p) {
var sinc, cosc, cosl, k;
p.x = adjust_lon(p.x - this.long0);
gauss.forward.apply(this, [p]);
sinc = Math.sin(p.y);
cosc = Math.cos(p.y);
cosl = Math.cos(p.x);
k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
p.x = k * cosc * Math.sin(p.x);
p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
p.x = this.a * p.x + this.x0;
p.y = this.a * p.y + this.y0;
return p;
};
exports.inverse = function(p) {
var sinc, cosc, lon, lat, rho;
p.x = (p.x - this.x0) / this.a;
p.y = (p.y - this.y0) / this.a;
p.x /= this.k0;
p.y /= this.k0;
if ((rho = Math.sqrt(p.x * p.x + p.y * p.y))) {
var c = 2 * Math.atan2(rho, this.R2);
sinc = Math.sin(c);
cosc = Math.cos(c);
lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
}
else {
lat = this.phic0;
lon = 0;
}
p.x = lon;
p.y = lat;
gauss.inverse.apply(this, [p]);
p.x = adjust_lon(p.x + this.long0);
return p;
};
exports.names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];
},{"../common/adjust_lon":5,"./gauss":46}],62:[function(_dereq_,module,exports){
var e0fn = _dereq_('../common/e0fn');
var e1fn = _dereq_('../common/e1fn');
var e2fn = _dereq_('../common/e2fn');
var e3fn = _dereq_('../common/e3fn');
var mlfn = _dereq_('../common/mlfn');
var adjust_lon = _dereq_('../common/adjust_lon');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var sign = _dereq_('../common/sign');
var asinz = _dereq_('../common/asinz');
exports.init = function() {
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
this.e2 = e2fn(this.es);
this.e3 = e3fn(this.es);
this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
};
/**
Transverse Mercator Forward - long/lat to x/y
long/lat in radians
*/
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
var delta_lon = adjust_lon(lon - this.long0);
var con;
var x, y;
var sin_phi = Math.sin(lat);
var cos_phi = Math.cos(lat);
if (this.sphere) {
var b = cos_phi * Math.sin(delta_lon);
if ((Math.abs(Math.abs(b) - 1)) < 0.0000000001) {
return (93);
}
else {
x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b));
con = Math.acos(cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - b * b));
if (lat < 0) {
con = -con;
}
y = this.a * this.k0 * (con - this.lat0);
}
}
else {
var al = cos_phi * delta_lon;
var als = Math.pow(al, 2);
var c = this.ep2 * Math.pow(cos_phi, 2);
var tq = Math.tan(lat);
var t = Math.pow(tq, 2);
con = 1 - this.es * Math.pow(sin_phi, 2);
var n = this.a / Math.sqrt(con);
var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat);
x = this.k0 * n * al * (1 + als / 6 * (1 - t + c + als / 20 * (5 - 18 * t + Math.pow(t, 2) + 72 * c - 58 * this.ep2))) + this.x0;
y = this.k0 * (ml - this.ml0 + n * tq * (als * (0.5 + als / 24 * (5 - t + 9 * c + 4 * Math.pow(c, 2) + als / 30 * (61 - 58 * t + Math.pow(t, 2) + 600 * c - 330 * this.ep2))))) + this.y0;
}
p.x = x;
p.y = y;
return p;
};
/**
Transverse Mercator Inverse - x/y to long/lat
*/
exports.inverse = function(p) {
var con, phi;
var delta_phi;
var i;
var max_iter = 6;
var lat, lon;
if (this.sphere) {
var f = Math.exp(p.x / (this.a * this.k0));
var g = 0.5 * (f - 1 / f);
var temp = this.lat0 + p.y / (this.a * this.k0);
var h = Math.cos(temp);
con = Math.sqrt((1 - h * h) / (1 + g * g));
lat = asinz(con);
if (temp < 0) {
lat = -lat;
}
if ((g === 0) && (h === 0)) {
lon = this.long0;
}
else {
lon = adjust_lon(Math.atan2(g, h) + this.long0);
}
}
else { // ellipsoidal form
var x = p.x - this.x0;
var y = p.y - this.y0;
con = (this.ml0 + y / this.k0) / this.a;
phi = con;
for (i = 0; true; i++) {
delta_phi = ((con + this.e1 * Math.sin(2 * phi) - this.e2 * Math.sin(4 * phi) + this.e3 * Math.sin(6 * phi)) / this.e0) - phi;
phi += delta_phi;
if (Math.abs(delta_phi) <= EPSLN) {
break;
}
if (i >= max_iter) {
return (95);
}
} // for()
if (Math.abs(phi) < HALF_PI) {
var sin_phi = Math.sin(phi);
var cos_phi = Math.cos(phi);
var tan_phi = Math.tan(phi);
var c = this.ep2 * Math.pow(cos_phi, 2);
var cs = Math.pow(c, 2);
var t = Math.pow(tan_phi, 2);
var ts = Math.pow(t, 2);
con = 1 - this.es * Math.pow(sin_phi, 2);
var n = this.a / Math.sqrt(con);
var r = n * (1 - this.es) / con;
var d = x / (n * this.k0);
var ds = Math.pow(d, 2);
lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24 * (5 + 3 * t + 10 * c - 4 * cs - 9 * this.ep2 - ds / 30 * (61 + 90 * t + 298 * c + 45 * ts - 252 * this.ep2 - 3 * cs)));
lon = adjust_lon(this.long0 + (d * (1 - ds / 6 * (1 + 2 * t + c - ds / 20 * (5 - 2 * c + 28 * t - 3 * cs + 8 * this.ep2 + 24 * ts))) / cos_phi));
}
else {
lat = HALF_PI * sign(y);
lon = this.long0;
}
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];
},{"../common/adjust_lon":5,"../common/asinz":6,"../common/e0fn":7,"../common/e1fn":8,"../common/e2fn":9,"../common/e3fn":10,"../common/mlfn":14,"../common/sign":21}],63:[function(_dereq_,module,exports){
var D2R = 0.01745329251994329577;
var tmerc = _dereq_('./tmerc');
exports.dependsOn = 'tmerc';
exports.init = function() {
if (!this.zone) {
return;
}
this.lat0 = 0;
this.long0 = ((6 * Math.abs(this.zone)) - 183) * D2R;
this.x0 = 500000;
this.y0 = this.utmSouth ? 10000000 : 0;
this.k0 = 0.9996;
tmerc.init.apply(this);
this.forward = tmerc.forward;
this.inverse = tmerc.inverse;
};
exports.names = ["Universal Transverse Mercator System", "utm"];
},{"./tmerc":62}],64:[function(_dereq_,module,exports){
var adjust_lon = _dereq_('../common/adjust_lon');
var HALF_PI = Math.PI/2;
var EPSLN = 1.0e-10;
var asinz = _dereq_('../common/asinz');
/* Initialize the Van Der Grinten projection
----------------------------------------*/
exports.init = function() {
//this.R = 6370997; //Radius of earth
this.R = this.a;
};
exports.forward = function(p) {
var lon = p.x;
var lat = p.y;
/* Forward equations
-----------------*/
var dlon = adjust_lon(lon - this.long0);
var x, y;
if (Math.abs(lat) <= EPSLN) {
x = this.x0 + this.R * dlon;
y = this.y0;
}
var theta = asinz(2 * Math.abs(lat / Math.PI));
if ((Math.abs(dlon) <= EPSLN) || (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN)) {
x = this.x0;
if (lat >= 0) {
y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
}
else {
y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
}
// return(OK);
}
var al = 0.5 * Math.abs((Math.PI / dlon) - (dlon / Math.PI));
var asq = al * al;
var sinth = Math.sin(theta);
var costh = Math.cos(theta);
var g = costh / (sinth + costh - 1);
var gsq = g * g;
var m = g * (2 / sinth - 1);
var msq = m * m;
var con = Math.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
if (dlon < 0) {
con = -con;
}
x = this.x0 + con;
//con = Math.abs(con / (Math.PI * this.R));
var q = asq + g;
con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
if (lat >= 0) {
//y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
y = this.y0 + con;
}
else {
//y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
y = this.y0 - con;
}
p.x = x;
p.y = y;
return p;
};
/* Van Der Grinten inverse equations--mapping x,y to lat/long
---------------------------------------------------------*/
exports.inverse = function(p) {
var lon, lat;
var xx, yy, xys, c1, c2, c3;
var a1;
var m1;
var con;
var th1;
var d;
/* inverse equations
-----------------*/
p.x -= this.x0;
p.y -= this.y0;
con = Math.PI * this.R;
xx = p.x / con;
yy = p.y / con;
xys = xx * xx + yy * yy;
c1 = -Math.abs(yy) * (1 + xys);
c2 = c1 - 2 * yy * yy + xx * xx;
c3 = -2 * c1 + 1 + 2 * yy * yy + xys * xys;
d = yy * yy / c3 + (2 * c2 * c2 * c2 / c3 / c3 / c3 - 9 * c1 * c2 / c3 / c3) / 27;
a1 = (c1 - c2 * c2 / 3 / c3) / c3;
m1 = 2 * Math.sqrt(-a1 / 3);
con = ((3 * d) / a1) / m1;
if (Math.abs(con) > 1) {
if (con >= 0) {
con = 1;
}
else {
con = -1;
}
}
th1 = Math.acos(con) / 3;
if (p.y >= 0) {
lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
}
else {
lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
}
if (Math.abs(xx) < EPSLN) {
lon = this.long0;
}
else {
lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
},{"../common/adjust_lon":5,"../common/asinz":6}],65:[function(_dereq_,module,exports){
var D2R = 0.01745329251994329577;
var R2D = 57.29577951308232088;
var PJD_3PARAM = 1;
var PJD_7PARAM = 2;
var datum_transform = _dereq_('./datum_transform');
var adjust_axis = _dereq_('./adjust_axis');
var proj = _dereq_('./Proj');
var toPoint = _dereq_('./common/toPoint');
module.exports = function transform(source, dest, point) {
var wgs84;
if (Array.isArray(point)) {
point = toPoint(point);
}
function checkNotWGS(source, dest) {
return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== "WGS84");
}
// Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
if (source.datum && dest.datum && (checkNotWGS(source, dest) || checkNotWGS(dest, source))) {
wgs84 = new proj('WGS84');
transform(source, wgs84, point);
source = wgs84;
}
// DGR, 2010/11/12
if (source.axis !== "enu") {
adjust_axis(source, false, point);
}
// Transform source points to long/lat, if they aren't already.
if (source.projName === "longlat") {
point.x *= D2R; // convert degrees to radians
point.y *= D2R;
}
else {
if (source.to_meter) {
point.x *= source.to_meter;
point.y *= source.to_meter;
}
source.inverse(point); // Convert Cartesian to longlat
}
// Adjust for the prime meridian if necessary
if (source.from_greenwich) {
point.x += source.from_greenwich;
}
// Convert datums if needed, and if possible.
point = datum_transform(source.datum, dest.datum, point);
// Adjust for the prime meridian if necessary
if (dest.from_greenwich) {
point.x -= dest.from_greenwich;
}
if (dest.projName === "longlat") {
// convert radians to decimal degrees
point.x *= R2D;
point.y *= R2D;
}
else { // else project
dest.forward(point);
if (dest.to_meter) {
point.x /= dest.to_meter;
point.y /= dest.to_meter;
}
}
// DGR, 2010/11/12
if (dest.axis !== "enu") {
adjust_axis(dest, true, point);
}
return point;
};
},{"./Proj":2,"./adjust_axis":3,"./common/toPoint":23,"./datum_transform":31}],66:[function(_dereq_,module,exports){
var D2R = 0.01745329251994329577;
var extend = _dereq_('./extend');
function mapit(obj, key, v) {
obj[key] = v.map(function(aa) {
var o = {};
sExpr(aa, o);
return o;
}).reduce(function(a, b) {
return extend(a, b);
}, {});
}
function sExpr(v, obj) {
var key;
if (!Array.isArray(v)) {
obj[v] = true;
return;
}
else {
key = v.shift();
if (key === 'PARAMETER') {
key = v.shift();
}
if (v.length === 1) {
if (Array.isArray(v[0])) {
obj[key] = {};
sExpr(v[0], obj[key]);
}
else {
obj[key] = v[0];
}
}
else if (!v.length) {
obj[key] = true;
}
else if (key === 'TOWGS84') {
obj[key] = v;
}
else {
obj[key] = {};
if (['UNIT', 'PRIMEM', 'VERT_DATUM'].indexOf(key) > -1) {
obj[key] = {
name: v[0].toLowerCase(),
convert: v[1]
};
if (v.length === 3) {
obj[key].auth = v[2];
}
}
else if (key === 'SPHEROID') {
obj[key] = {
name: v[0],
a: v[1],
rf: v[2]
};
if (v.length === 4) {
obj[key].auth = v[3];
}
}
else if (['GEOGCS', 'GEOCCS', 'DATUM', 'VERT_CS', 'COMPD_CS', 'LOCAL_CS', 'FITTED_CS', 'LOCAL_DATUM'].indexOf(key) > -1) {
v[0] = ['name', v[0]];
mapit(obj, key, v);
}
else if (v.every(function(aa) {
return Array.isArray(aa);
})) {
mapit(obj, key, v);
}
else {
sExpr(v, obj[key]);
}
}
}
}
function rename(obj, params) {
var outName = params[0];
var inName = params[1];
if (!(outName in obj) && (inName in obj)) {
obj[outName] = obj[inName];
if (params.length === 3) {
obj[outName] = params[2](obj[outName]);
}
}
}
function d2r(input) {
return input * D2R;
}
function cleanWKT(wkt) {
if (wkt.type === 'GEOGCS') {
wkt.projName = 'longlat';
}
else if (wkt.type === 'LOCAL_CS') {
wkt.projName = 'identity';
wkt.local = true;
}
else {
if (typeof wkt.PROJECTION === "object") {
wkt.projName = Object.keys(wkt.PROJECTION)[0];
}
else {
wkt.projName = wkt.PROJECTION;
}
}
if (wkt.UNIT) {
wkt.units = wkt.UNIT.name.toLowerCase();
if (wkt.units === 'metre') {
wkt.units = 'meter';
}
if (wkt.UNIT.convert) {
wkt.to_meter = parseFloat(wkt.UNIT.convert, 10);
}
}
if (wkt.GEOGCS) {
//if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
// wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
//}
if (wkt.GEOGCS.DATUM) {
wkt.datumCode = wkt.GEOGCS.DATUM.name.toLowerCase();
}
else {
wkt.datumCode = wkt.GEOGCS.name.toLowerCase();
}
if (wkt.datumCode.slice(0, 2) === 'd_') {
wkt.datumCode = wkt.datumCode.slice(2);
}
if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
wkt.datumCode = 'nzgd49';
}
if (wkt.datumCode === "wgs_1984") {
if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
wkt.sphere = true;
}
wkt.datumCode = 'wgs84';
}
if (wkt.datumCode.slice(-6) === '_ferro') {
wkt.datumCode = wkt.datumCode.slice(0, - 6);
}
if (wkt.datumCode.slice(-8) === '_jakarta') {
wkt.datumCode = wkt.datumCode.slice(0, - 8);
}
if (~wkt.datumCode.indexOf('belge')) {
wkt.datumCode = "rnb72";
}
if (wkt.GEOGCS.DATUM && wkt.GEOGCS.DATUM.SPHEROID) {
wkt.ellps = wkt.GEOGCS.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
if (wkt.ellps.toLowerCase().slice(0, 13) === "international") {
wkt.ellps = 'intl';
}
wkt.a = wkt.GEOGCS.DATUM.SPHEROID.a;
wkt.rf = parseFloat(wkt.GEOGCS.DATUM.SPHEROID.rf, 10);
}
if (~wkt.datumCode.indexOf('osgb_1936')) {
wkt.datumCode = "osgb36";
}
}
if (wkt.b && !isFinite(wkt.b)) {
wkt.b = wkt.a;
}
function toMeter(input) {
var ratio = wkt.to_meter || 1;
return parseFloat(input, 10) * ratio;
}
var renamer = function(a) {
return rename(wkt, a);
};
var list = [
['standard_parallel_1', 'Standard_Parallel_1'],
['standard_parallel_2', 'Standard_Parallel_2'],
['false_easting', 'False_Easting'],
['false_northing', 'False_Northing'],
['central_meridian', 'Central_Meridian'],
['latitude_of_origin', 'Latitude_Of_Origin'],
['latitude_of_origin', 'Central_Parallel'],
['scale_factor', 'Scale_Factor'],
['k0', 'scale_factor'],
['latitude_of_center', 'Latitude_of_center'],
['lat0', 'latitude_of_center', d2r],
['longitude_of_center', 'Longitude_Of_Center'],
['longc', 'longitude_of_center', d2r],
['x0', 'false_easting', toMeter],
['y0', 'false_northing', toMeter],
['long0', 'central_meridian', d2r],
['lat0', 'latitude_of_origin', d2r],
['lat0', 'standard_parallel_1', d2r],
['lat1', 'standard_parallel_1', d2r],
['lat2', 'standard_parallel_2', d2r],
['alpha', 'azimuth', d2r],
['srsCode', 'name']
];
list.forEach(renamer);
if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === "Lambert_Azimuthal_Equal_Area")) {
wkt.long0 = wkt.longc;
}
if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
wkt.lat_ts = wkt.lat1;
}
}
module.exports = function(wkt, self) {
var lisp = JSON.parse(("," + wkt).replace(/\s*\,\s*([A-Z_0-9]+?)(\[)/g, ',["$1",').slice(1).replace(/\s*\,\s*([A-Z_0-9]+?)\]/g, ',"$1"]').replace(/,\["VERTCS".+/,''));
var type = lisp.shift();
var name = lisp.shift();
lisp.unshift(['name', name]);
lisp.unshift(['type', type]);
lisp.unshift('output');
var obj = {};
sExpr(lisp, obj);
cleanWKT(obj.output);
return extend(self, obj.output);
};
},{"./extend":34}],67:[function(_dereq_,module,exports){
/**
* UTM zones are grouped, and assigned to one of a group of 6
* sets.
*
* {int} @private
*/
var NUM_100K_SETS = 6;
/**
* The column letters (for easting) of the lower left value, per
* set.
*
* {string} @private
*/
var SET_ORIGIN_COLUMN_LETTERS = 'AJSAJS';
/**
* The row letters (for northing) of the lower left value, per
* set.
*
* {string} @private
*/
var SET_ORIGIN_ROW_LETTERS = 'AFAFAF';
var A = 65; // A
var I = 73; // I
var O = 79; // O
var V = 86; // V
var Z = 90; // Z
/**
* Conversion of lat/lon to MGRS.
*
* @param {object} ll Object literal with lat and lon properties on a
* WGS84 ellipsoid.
* @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
* 100 m, 4 for 1000 m or 5 for 10000 m). Optional, default is 5.
* @return {string} the MGRS string for the given location and accuracy.
*/
exports.forward = function(ll, accuracy) {
accuracy = accuracy || 5; // default accuracy 1m
return encode(LLtoUTM({
lat: ll[1],
lon: ll[0]
}), accuracy);
};
/**
* Conversion of MGRS to lat/lon.
*
* @param {string} mgrs MGRS string.
* @return {array} An array with left (longitude), bottom (latitude), right
* (longitude) and top (latitude) values in WGS84, representing the
* bounding box for the provided MGRS reference.
*/
exports.inverse = function(mgrs) {
var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
return [bbox.left, bbox.bottom, bbox.right, bbox.top];
};
exports.toPoint = function(mgrsStr) {
var llbbox = exports.inverse(mgrsStr);
return [(llbbox[2] + llbbox[0]) / 2, (llbbox[3] + llbbox[1]) / 2];
};
/**
* Conversion from degrees to radians.
*
* @private
* @param {number} deg the angle in degrees.
* @return {number} the angle in radians.
*/
function degToRad(deg) {
return (deg * (Math.PI / 180.0));
}
/**
* Conversion from radians to degrees.
*
* @private
* @param {number} rad the angle in radians.
* @return {number} the angle in degrees.
*/
function radToDeg(rad) {
return (180.0 * (rad / Math.PI));
}
/**
* Converts a set of Longitude and Latitude co-ordinates to UTM
* using the WGS84 ellipsoid.
*
* @private
* @param {object} ll Object literal with lat and lon properties
* representing the WGS84 coordinate to be converted.
* @return {object} Object literal containing the UTM value with easting,
* northing, zoneNumber and zoneLetter properties, and an optional
* accuracy property in digits. Returns null if the conversion failed.
*/
function LLtoUTM(ll) {
var Lat = ll.lat;
var Long = ll.lon;
var a = 6378137.0; //ellip.radius;
var eccSquared = 0.00669438; //ellip.eccsq;
var k0 = 0.9996;
var LongOrigin;
var eccPrimeSquared;
var N, T, C, A, M;
var LatRad = degToRad(Lat);
var LongRad = degToRad(Long);
var LongOriginRad;
var ZoneNumber;
// (int)
ZoneNumber = Math.floor((Long + 180) / 6) + 1;
//Make sure the longitude 180.00 is in Zone 60
if (Long === 180) {
ZoneNumber = 60;
}
// Special zone for Norway
if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) {
ZoneNumber = 32;
}
// Special zones for Svalbard
if (Lat >= 72.0 && Lat < 84.0) {
if (Long >= 0.0 && Long < 9.0) {
ZoneNumber = 31;
}
else if (Long >= 9.0 && Long < 21.0) {
ZoneNumber = 33;
}
else if (Long >= 21.0 && Long < 33.0) {
ZoneNumber = 35;
}
else if (Long >= 33.0 && Long < 42.0) {
ZoneNumber = 37;
}
}
LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin
// in middle of
// zone
LongOriginRad = degToRad(LongOrigin);
eccPrimeSquared = (eccSquared) / (1 - eccSquared);
N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
T = Math.tan(LatRad) * Math.tan(LatRad);
C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
A = Math.cos(LatRad) * (LongRad - LongOriginRad);
M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));
var UTMEasting = (k0 * N * (A + (1 - T + C) * A * A * A / 6.0 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120.0) + 500000.0);
var UTMNorthing = (k0 * (M + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24.0 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720.0)));
if (Lat < 0.0) {
UTMNorthing += 10000000.0; //10000000 meter offset for
// southern hemisphere
}
return {
northing: Math.round(UTMNorthing),
easting: Math.round(UTMEasting),
zoneNumber: ZoneNumber,
zoneLetter: getLetterDesignator(Lat)
};
}
/**
* Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience
* class where the Zone can be specified as a single string eg."60N" which
* is then broken down into the ZoneNumber and ZoneLetter.
*
* @private
* @param {object} utm An object literal with northing, easting, zoneNumber
* and zoneLetter properties. If an optional accuracy property is
* provided (in meters), a bounding box will be returned instead of
* latitude and longitude.
* @return {object} An object literal containing either lat and lon values
* (if no accuracy was provided), or top, right, bottom and left values
* for the bounding box calculated according to the provided accuracy.
* Returns null if the conversion failed.
*/
function UTMtoLL(utm) {
var UTMNorthing = utm.northing;
var UTMEasting = utm.easting;
var zoneLetter = utm.zoneLetter;
var zoneNumber = utm.zoneNumber;
// check the ZoneNummber is valid
if (zoneNumber < 0 || zoneNumber > 60) {
return null;
}
var k0 = 0.9996;
var a = 6378137.0; //ellip.radius;
var eccSquared = 0.00669438; //ellip.eccsq;
var eccPrimeSquared;
var e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
var N1, T1, C1, R1, D, M;
var LongOrigin;
var mu, phi1Rad;
// remove 500,000 meter offset for longitude
var x = UTMEasting - 500000.0;
var y = UTMNorthing;
// We must know somehow if we are in the Northern or Southern
// hemisphere, this is the only time we use the letter So even
// if the Zone letter isn't exactly correct it should indicate
// the hemisphere correctly
if (zoneLetter < 'N') {
y -= 10000000.0; // remove 10,000,000 meter offset used
// for southern hemisphere
}
// There are 60 zones with zone 1 being at West -180 to -174
LongOrigin = (zoneNumber - 1) * 6 - 180 + 3; // +3 puts origin
// in middle of
// zone
eccPrimeSquared = (eccSquared) / (1 - eccSquared);
M = y / k0;
mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
phi1Rad = mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * Math.sin(2 * mu) + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * Math.sin(4 * mu) + (151 * e1 * e1 * e1 / 96) * Math.sin(6 * mu);
// double phi1 = ProjMath.radToDeg(phi1Rad);
N1 = a / Math.sqrt(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad));
T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad);
C1 = eccPrimeSquared * Math.cos(phi1Rad) * Math.cos(phi1Rad);
R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5);
D = x / (N1 * k0);
var lat = phi1Rad - (N1 * Math.tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D * D * D * D * D / 720);
lat = radToDeg(lat);
var lon = (D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * D * D * D * D * D / 120) / Math.cos(phi1Rad);
lon = LongOrigin + radToDeg(lon);
var result;
if (utm.accuracy) {
var topRight = UTMtoLL({
northing: utm.northing + utm.accuracy,
easting: utm.easting + utm.accuracy,
zoneLetter: utm.zoneLetter,
zoneNumber: utm.zoneNumber
});
result = {
top: topRight.lat,
right: topRight.lon,
bottom: lat,
left: lon
};
}
else {
result = {
lat: lat,
lon: lon
};
}
return result;
}
/**
* Calculates the MGRS letter designator for the given latitude.
*
* @private
* @param {number} lat The latitude in WGS84 to get the letter designator
* for.
* @return {char} The letter designator.
*/
function getLetterDesignator(lat) {
//This is here as an error flag to show that the Latitude is
//outside MGRS limits
var LetterDesignator = 'Z';
if ((84 >= lat) && (lat >= 72)) {
LetterDesignator = 'X';
}
else if ((72 > lat) && (lat >= 64)) {
LetterDesignator = 'W';
}
else if ((64 > lat) && (lat >= 56)) {
LetterDesignator = 'V';
}
else if ((56 > lat) && (lat >= 48)) {
LetterDesignator = 'U';
}
else if ((48 > lat) && (lat >= 40)) {
LetterDesignator = 'T';
}
else if ((40 > lat) && (lat >= 32)) {
LetterDesignator = 'S';
}
else if ((32 > lat) && (lat >= 24)) {
LetterDesignator = 'R';
}
else if ((24 > lat) && (lat >= 16)) {
LetterDesignator = 'Q';
}
else if ((16 > lat) && (lat >= 8)) {
LetterDesignator = 'P';
}
else if ((8 > lat) && (lat >= 0)) {
LetterDesignator = 'N';
}
else if ((0 > lat) && (lat >= -8)) {
LetterDesignator = 'M';
}
else if ((-8 > lat) && (lat >= -16)) {
LetterDesignator = 'L';
}
else if ((-16 > lat) && (lat >= -24)) {
LetterDesignator = 'K';
}
else if ((-24 > lat) && (lat >= -32)) {
LetterDesignator = 'J';
}
else if ((-32 > lat) && (lat >= -40)) {
LetterDesignator = 'H';
}
else if ((-40 > lat) && (lat >= -48)) {
LetterDesignator = 'G';
}
else if ((-48 > lat) && (lat >= -56)) {
LetterDesignator = 'F';
}
else if ((-56 > lat) && (lat >= -64)) {
LetterDesignator = 'E';
}
else if ((-64 > lat) && (lat >= -72)) {
LetterDesignator = 'D';
}
else if ((-72 > lat) && (lat >= -80)) {
LetterDesignator = 'C';
}
return LetterDesignator;
}
/**
* Encodes a UTM location as MGRS string.
*
* @private
* @param {object} utm An object literal with easting, northing,
* zoneLetter, zoneNumber
* @param {number} accuracy Accuracy in digits (1-5).
* @return {string} MGRS string for the given UTM location.
*/
function encode(utm, accuracy) {
var seasting = "" + utm.easting,
snorthing = "" + utm.northing;
return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy);
}
/**
* Get the two letter 100k designator for a given UTM easting,
* northing and zone number value.
*
* @private
* @param {number} easting
* @param {number} northing
* @param {number} zoneNumber
* @return the two letter 100k designator for the given UTM location.
*/
function get100kID(easting, northing, zoneNumber) {
var setParm = get100kSetForZone(zoneNumber);
var setColumn = Math.floor(easting / 100000);
var setRow = Math.floor(northing / 100000) % 20;
return getLetter100kID(setColumn, setRow, setParm);
}
/**
* Given a UTM zone number, figure out the MGRS 100K set it is in.
*
* @private
* @param {number} i An UTM zone number.
* @return {number} the 100k set the UTM zone is in.
*/
function get100kSetForZone(i) {
var setParm = i % NUM_100K_SETS;
if (setParm === 0) {
setParm = NUM_100K_SETS;
}
return setParm;
}
/**
* Get the two-letter MGRS 100k designator given information
* translated from the UTM northing, easting and zone number.
*
* @private
* @param {number} column the column index as it relates to the MGRS
* 100k set spreadsheet, created from the UTM easting.
* Values are 1-8.
* @param {number} row the row index as it relates to the MGRS 100k set
* spreadsheet, created from the UTM northing value. Values
* are from 0-19.
* @param {number} parm the set block, as it relates to the MGRS 100k set
* spreadsheet, created from the UTM zone. Values are from
* 1-60.
* @return two letter MGRS 100k code.
*/
function getLetter100kID(column, row, parm) {
// colOrigin and rowOrigin are the letters at the origin of the set
var index = parm - 1;
var colOrigin = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(index);
var rowOrigin = SET_ORIGIN_ROW_LETTERS.charCodeAt(index);
// colInt and rowInt are the letters to build to return
var colInt = colOrigin + column - 1;
var rowInt = rowOrigin + row;
var rollover = false;
if (colInt > Z) {
colInt = colInt - Z + A - 1;
rollover = true;
}
if (colInt === I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) {
colInt++;
}
if (colInt === O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) {
colInt++;
if (colInt === I) {
colInt++;
}
}
if (colInt > Z) {
colInt = colInt - Z + A - 1;
}
if (rowInt > V) {
rowInt = rowInt - V + A - 1;
rollover = true;
}
else {
rollover = false;
}
if (((rowInt === I) || ((rowOrigin < I) && (rowInt > I))) || (((rowInt > I) || (rowOrigin < I)) && rollover)) {
rowInt++;
}
if (((rowInt === O) || ((rowOrigin < O) && (rowInt > O))) || (((rowInt > O) || (rowOrigin < O)) && rollover)) {
rowInt++;
if (rowInt === I) {
rowInt++;
}
}
if (rowInt > V) {
rowInt = rowInt - V + A - 1;
}
var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt);
return twoLetter;
}
/**
* Decode the UTM parameters from a MGRS string.
*
* @private
* @param {string} mgrsString an UPPERCASE coordinate string is expected.
* @return {object} An object literal with easting, northing, zoneLetter,
* zoneNumber and accuracy (in meters) properties.
*/
function decode(mgrsString) {
if (mgrsString && mgrsString.length === 0) {
throw ("MGRSPoint coverting from nothing");
}
var length = mgrsString.length;
var hunK = null;
var sb = "";
var testChar;
var i = 0;
// get Zone number
while (!(/[A-Z]/).test(testChar = mgrsString.charAt(i))) {
if (i >= 2) {
throw ("MGRSPoint bad conversion from: " + mgrsString);
}
sb += testChar;
i++;
}
var zoneNumber = parseInt(sb, 10);
if (i === 0 || i + 3 > length) {
// A good MGRS string has to be 4-5 digits long,
// ##AAA/#AAA at least.
throw ("MGRSPoint bad conversion from: " + mgrsString);
}
var zoneLetter = mgrsString.charAt(i++);
// Should we check the zone letter here? Why not.
if (zoneLetter <= 'A' || zoneLetter === 'B' || zoneLetter === 'Y' || zoneLetter >= 'Z' || zoneLetter === 'I' || zoneLetter === 'O') {
throw ("MGRSPoint zone letter " + zoneLetter + " not handled: " + mgrsString);
}
hunK = mgrsString.substring(i, i += 2);
var set = get100kSetForZone(zoneNumber);
var east100k = getEastingFromChar(hunK.charAt(0), set);
var north100k = getNorthingFromChar(hunK.charAt(1), set);
// We have a bug where the northing may be 2000000 too low.
// How
// do we know when to roll over?
while (north100k < getMinNorthing(zoneLetter)) {
north100k += 2000000;
}
// calculate the char index for easting/northing separator
var remainder = length - i;
if (remainder % 2 !== 0) {
throw ("MGRSPoint has to have an even number \nof digits after the zone letter and two 100km letters - front \nhalf for easting meters, second half for \nnorthing meters" + mgrsString);
}
var sep = remainder / 2;
var sepEasting = 0.0;
var sepNorthing = 0.0;
var accuracyBonus, sepEastingString, sepNorthingString, easting, northing;
if (sep > 0) {
accuracyBonus = 100000.0 / Math.pow(10, sep);
sepEastingString = mgrsString.substring(i, i + sep);
sepEasting = parseFloat(sepEastingString) * accuracyBonus;
sepNorthingString = mgrsString.substring(i + sep);
sepNorthing = parseFloat(sepNorthingString) * accuracyBonus;
}
easting = sepEasting + east100k;
northing = sepNorthing + north100k;
return {
easting: easting,
northing: northing,
zoneLetter: zoneLetter,
zoneNumber: zoneNumber,
accuracy: accuracyBonus
};
}
/**
* Given the first letter from a two-letter MGRS 100k zone, and given the
* MGRS table set for the zone number, figure out the easting value that
* should be added to the other, secondary easting value.
*
* @private
* @param {char} e The first letter from a two-letter MGRS 100´k zone.
* @param {number} set The MGRS table set for the zone number.
* @return {number} The easting value for the given letter and set.
*/
function getEastingFromChar(e, set) {
// colOrigin is the letter at the origin of the set for the
// column
var curCol = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(set - 1);
var eastingValue = 100000.0;
var rewindMarker = false;
while (curCol !== e.charCodeAt(0)) {
curCol++;
if (curCol === I) {
curCol++;
}
if (curCol === O) {
curCol++;
}
if (curCol > Z) {
if (rewindMarker) {
throw ("Bad character: " + e);
}
curCol = A;
rewindMarker = true;
}
eastingValue += 100000.0;
}
return eastingValue;
}
/**
* Given the second letter from a two-letter MGRS 100k zone, and given the
* MGRS table set for the zone number, figure out the northing value that
* should be added to the other, secondary northing value. You have to
* remember that Northings are determined from the equator, and the vertical
* cycle of letters mean a 2000000 additional northing meters. This happens
* approx. every 18 degrees of latitude. This method does *NOT* count any
* additional northings. You have to figure out how many 2000000 meters need
* to be added for the zone letter of the MGRS coordinate.
*
* @private
* @param {char} n Second letter of the MGRS 100k zone
* @param {number} set The MGRS table set number, which is dependent on the
* UTM zone number.
* @return {number} The northing value for the given letter and set.
*/
function getNorthingFromChar(n, set) {
if (n > 'V') {
throw ("MGRSPoint given invalid Northing " + n);
}
// rowOrigin is the letter at the origin of the set for the
// column
var curRow = SET_ORIGIN_ROW_LETTERS.charCodeAt(set - 1);
var northingValue = 0.0;
var rewindMarker = false;
while (curRow !== n.charCodeAt(0)) {
curRow++;
if (curRow === I) {
curRow++;
}
if (curRow === O) {
curRow++;
}
// fixing a bug making whole application hang in this loop
// when 'n' is a wrong character
if (curRow > V) {
if (rewindMarker) { // making sure that this loop ends
throw ("Bad character: " + n);
}
curRow = A;
rewindMarker = true;
}
northingValue += 100000.0;
}
return northingValue;
}
/**
* The function getMinNorthing returns the minimum northing value of a MGRS
* zone.
*
* Ported from Geotrans' c Lattitude_Band_Value structure table.
*
* @private
* @param {char} zoneLetter The MGRS zone to get the min northing for.
* @return {number}
*/
function getMinNorthing(zoneLetter) {
var northing;
switch (zoneLetter) {
case 'C':
northing = 1100000.0;
break;
case 'D':
northing = 2000000.0;
break;
case 'E':
northing = 2800000.0;
break;
case 'F':
northing = 3700000.0;
break;
case 'G':
northing = 4600000.0;
break;
case 'H':
northing = 5500000.0;
break;
case 'J':
northing = 6400000.0;
break;
case 'K':
northing = 7300000.0;
break;
case 'L':
northing = 8200000.0;
break;
case 'M':
northing = 9100000.0;
break;
case 'N':
northing = 0.0;
break;
case 'P':
northing = 800000.0;
break;
case 'Q':
northing = 1700000.0;
break;
case 'R':
northing = 2600000.0;
break;
case 'S':
northing = 3500000.0;
break;
case 'T':
northing = 4400000.0;
break;
case 'U':
northing = 5300000.0;
break;
case 'V':
northing = 6200000.0;
break;
case 'W':
northing = 7000000.0;
break;
case 'X':
northing = 7900000.0;
break;
default:
northing = -1.0;
}
if (northing >= 0.0) {
return northing;
}
else {
throw ("Invalid zone letter: " + zoneLetter);
}
}
},{}],68:[function(_dereq_,module,exports){
module.exports={
"name": "proj4",
"version": "2.3.6",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
"main": "lib/index.js",
"directories": {
"test": "test",
"doc": "docs"
},
"scripts": {
"test": "./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"
},
"repository": {
"type": "git",
"url": "git://github.com/proj4js/proj4js.git"
},
"author": "",
"license": "MIT",
"jam": {
"main": "dist/proj4.js",
"include": [
"dist/proj4.js",
"README.md",
"AUTHORS",
"LICENSE.md"
]
},
"devDependencies": {
"grunt-cli": "~0.1.13",
"grunt": "~0.4.2",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-jshint": "~0.8.0",
"chai": "~1.8.1",
"mocha": "~1.17.1",
"grunt-mocha-phantomjs": "~0.4.0",
"browserify": "~3.24.5",
"grunt-browserify": "~1.3.0",
"grunt-contrib-uglify": "~0.3.2",
"curl": "git://github.com/cujojs/curl.git",
"istanbul": "~0.2.4",
"tin": "~0.4.0"
},
"dependencies": {
"mgrs": "0.0.0"
}
}
},{}],"./includedProjections":[function(_dereq_,module,exports){
module.exports=_dereq_('hTEDpn');
},{}],"hTEDpn":[function(_dereq_,module,exports){
var projs = [
_dereq_('./lib/projections/tmerc'),
_dereq_('./lib/projections/utm'),
_dereq_('./lib/projections/sterea'),
_dereq_('./lib/projections/stere'),
_dereq_('./lib/projections/somerc'),
_dereq_('./lib/projections/omerc'),
_dereq_('./lib/projections/lcc'),
_dereq_('./lib/projections/krovak'),
_dereq_('./lib/projections/cass'),
_dereq_('./lib/projections/laea'),
_dereq_('./lib/projections/aea'),
_dereq_('./lib/projections/gnom'),
_dereq_('./lib/projections/cea'),
_dereq_('./lib/projections/eqc'),
_dereq_('./lib/projections/poly'),
_dereq_('./lib/projections/nzmg'),
_dereq_('./lib/projections/mill'),
_dereq_('./lib/projections/sinu'),
_dereq_('./lib/projections/moll'),
_dereq_('./lib/projections/eqdc'),
_dereq_('./lib/projections/vandg'),
_dereq_('./lib/projections/aeqd')
];
module.exports = function(proj4){
projs.forEach(function(proj){
proj4.Proj.projections.add(proj);
});
}
},{"./lib/projections/aea":40,"./lib/projections/aeqd":41,"./lib/projections/cass":42,"./lib/projections/cea":43,"./lib/projections/eqc":44,"./lib/projections/eqdc":45,"./lib/projections/gnom":47,"./lib/projections/krovak":48,"./lib/projections/laea":49,"./lib/projections/lcc":50,"./lib/projections/mill":53,"./lib/projections/moll":54,"./lib/projections/nzmg":55,"./lib/projections/omerc":56,"./lib/projections/poly":57,"./lib/projections/sinu":58,"./lib/projections/somerc":59,"./lib/projections/stere":60,"./lib/projections/sterea":61,"./lib/projections/tmerc":62,"./lib/projections/utm":63,"./lib/projections/vandg":64}]},{},[36])
(36)
});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.reproject = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
//var proj4 = require('/usr/local/lib/node_modules/proj4');
//var proj4 = require('./proj4');
// Checks if `list` looks like a `[x, y]`.
function isXY(list) {
return list.length === 2 &&
typeof list[0] === 'number' &&
typeof list[1] === 'number';
}
function traverseCoords(coordinates, callback) {
if (isXY(coordinates)) return callback(coordinates);
return coordinates.map(function(coord){return traverseCoords(coord, callback);});
}
// Simplistic shallow clone that will work for a normal GeoJSON object.
function clone(obj) {
if (null == obj || 'object' !== typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}
function traverseGeoJson(geojson, leafCallback, nodeCallback) {
var r = clone(geojson);
if (geojson.type === 'Feature') {
r.geometry = traverseGeoJson(geojson.geometry, leafCallback, nodeCallback);
} else if (geojson.type === 'FeatureCollection') {
r.features = r.features.map(function(gj) { return traverseGeoJson(gj, leafCallback, nodeCallback); });
} else if (geojson.type === 'GeometryCollection') {
r.geometries = r.geometries.map(function(gj) { return traverseGeoJson(gj, leafCallback, nodeCallback); });
} else {
if (leafCallback) leafCallback(r);
}
if (nodeCallback) nodeCallback(r);
return r;
}
function detectCrs(geojson, projs) {
var crsInfo = geojson.crs,
crs;
if (crsInfo === undefined) {
throw new Error('Unable to detect CRS, GeoJSON has no "crs" property.');
}
if (crsInfo.type === 'name') {
crs = projs[crsInfo.properties.name];
} else if (crsInfo.type === 'EPSG') {
crs = projs['EPSG:' + crsInfo.properties.code];
}
if (!crs) {
throw new Error('CRS defined in crs section could not be identified: ' + JSON.stringify(crsInfo));
}
return crs;
}
function determineCrs(crs, projs) {
if (typeof crs === 'string' || crs instanceof String) {
return projs[crs];
}
return crs;
}
function reproject(geojson, from, to, projs) {
if (!from) {
from = detectCrs(geojson, projs);
} else {
from = determineCrs(from, projs);
}
to = determineCrs(to, projs);
var transform = proj4(from, to);
return traverseGeoJson(geojson, function(gj) {
// No easy way to put correct CRS info into the GeoJSON,
// and definitely wrong to keep the old, so delete it.
if (gj.crs) {
delete gj.crs;
}
gj.coordinates = traverseCoords(gj.coordinates, function(xy) {
return transform.forward(xy);
});
}, function(gj) {
if (gj.bbox) {
// A bbox can't easily be reprojected, just reprojecting
// the min/max coords definitely will not work since
// the transform is not linear (in the general case).
// Workaround is to just re-compute the bbox after the
// transform.
gj.bbox = (function() {
var min = [Number.MAX_VALUE, Number.MAX_VALUE],
max = [-Number.MAX_VALUE, -Number.MAX_VALUE];
traverseGeoJson(gj, function(_gj) {
traverseCoords(_gj.coordinates, function(xy) {
min[0] = Math.min(min[0], xy[0]);
min[1] = Math.min(min[1], xy[1]);
max[0] = Math.max(max[0], xy[0]);
max[1] = Math.max(max[1], xy[1]);
});
});
return [min[0], min[1], max[0], max[1]];
})();
}
});
}
module.exports = {
detectCrs: detectCrs,
reproject: reproject,
reverse: function(geojson) {
return traverseGeoJson(geojson, function(gj) {
gj.coordinates = traverseCoords(gj.coordinates, function(xy) {
return [ xy[1], xy[0] ];
});
});
},
toWgs84: function(geojson, from) {
return reproject(geojson, from, proj4.WGS84);
}
};
},{}]},{},[1])(1)
});
.mapsense-simple.labels {
font-size: 16;
fill: #4c83b2;
font-weight: 400;
text-transform: uppercase;
stroke-width: .3;
stroke: grey;
font-stretch: expanded;
letter-spacing: 1.5;
font-family: "Josefin Sans";
}
.mapsense-simple.tile-background {
fill: #CBE6F3;
}
.mapsense-simple.land {
/*fill: #fffaf2;*/
fill: #fcfcfc;
}
.mapsense-simple.water_polygon {
fill: #CBE6F3;
}
.mapsense-simple.country_border,
.mapsense-simple.disputed_border {
stroke: #aaa;
}
.mapsense-simple.state_border {
stroke: #aaa;
}
.mapsense-simple.water_line {
stroke: #CBE6F3;
}
.mapsense-simple.park {
fill: #c6f3bd;
stroke: none;
}
.mapsense-simple.building {
fill: #f9ece2;
stroke: none;
}
.mapsense-simple.school {
fill: #f0eced;
stroke: none;
}
.mapsense-simple.urban {
fill: rgba(243, 210, 191, 0.19);
stroke: none;
}
.mapsense-simple._0.roads,
.mapsense-simple._1.roads,
.mapsense-simple._2.roads,
.mapsense-simple._3.roads,
.mapsense-simple._4.roads,
.mapsense-simple._5.roads,
.mapsense-simple._6.roads,
{
stroke: none;
}
.mapsense-simple.ne_10m_roads {
stroke: #ddd;
}
.mapsense-simple.motorway {
stroke: #ddd;
}
.mapsense-simple.arterial_major {
stroke: #ddd;
}
.mapsense-simple.arterial_minor {
stroke: #cfdddb;
}
.mapsense-simple.road_med {
stroke: #dae9ea;
}
.mapsense-simple.road_minor {
stroke: #ededed;
}
.mapsense-simple.rail_major {
stroke: #c7c4c4;
}
.mapsense-simple.rail_minor {
stroke: #c7c4c4;
}
.mapsense-simple.runway {
stroke: #e1dede;
}
.mapsense-simple.path {
stroke: #e1dede;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment