From 6deb33fb2b4cd5086363b3691e09fe7a56701d31 Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Wed, 22 Mar 2017 14:28:08 +0100 Subject: [PATCH] new textures, degradation of horizon, add/remove free layer, initial hit geodata support --- build/.placeholder | 0 make.sh | 3 +- src/browser/interface.js | 10 + src/core/config.js | 4 +- src/core/core.js | 2 +- src/core/inspector/input.js | 19 +- src/core/inspector/inspector.js | 11 + src/core/map/bound-layer.js | 10 + src/core/map/camera.js | 9 +- src/core/map/draw.js | 17 +- src/core/map/geodata-processor/processor.js | 2 +- src/core/map/geodata.js | 14 +- src/core/map/interface.js | 52 + src/core/map/map.js | 209 +- src/core/map/measure.js | 17 +- src/core/map/metanode.js | 8 +- src/core/map/metatile.js | 10 +- src/core/map/refframe.js | 44 - src/core/map/resource-node.js | 30 +- src/core/map/stylesheet.js | 1 + src/core/map/subtexture.js | 480 +- src/core/map/surface-tile.js | 50 +- src/core/map/surface-tree.js | 4 + src/core/map/surface.js | 27 +- src/core/map/texture.js | 519 +- src/core/renderer/renderer.js | 212 +- src/core/utils/libs/proj4-src.js | 11840 ++++++++++-------- src/core/utils/libs/proj4.js | 6 +- src/core/utils/utils.js | 2 +- 29 files changed, 7375 insertions(+), 6237 deletions(-) create mode 100644 build/.placeholder diff --git a/build/.placeholder b/build/.placeholder new file mode 100644 index 00000000..e69de29b diff --git a/make.sh b/make.sh index c85b1cf7..fcbabfd0 100755 --- a/make.sh +++ b/make.sh @@ -1,4 +1,4 @@ -CLOSURECOMPILER=../build/tools/closure-compiler/compiler.jar +CLOSURECOMPILER=./build/tools/closure-compiler/compiler.jar # create lincense header @@ -74,6 +74,7 @@ cat src/core/utils/matrix.js \ src/core/map/submesh.js \ src/core/map/surface.js \ src/core/map/surface-sequence.js \ + src/core/map/subtexture.js \ src/core/map/texture.js \ src/core/map/virtual-surface.js \ src/core/map/surface-tile.js \ diff --git a/src/browser/interface.js b/src/browser/interface.js index 2f14a144..f73f69bf 100755 --- a/src/browser/interface.js +++ b/src/browser/interface.js @@ -135,6 +135,16 @@ Melown.BrowserInterface.prototype.getBoundLayerInfo = function(layerId_) { return (layer_ != null) ? layer_.getInfo() : null; }; +Melown.BrowserInterface.prototype.addFreeLayer = function(id_, options_) { + if(!this.map_) return; + return this.map_.addFreeLayer(id_, options_); +}; + +Melown.BrowserInterface.prototype.removeFreeLayer = function(id_) { + if(!this.map_) return; + return this.map_.removeFreeLayer(id_); +}; + Melown.BrowserInterface.prototype.getFreeLayers = function() { if(!this.map_) return; return this.map_.getFreeLayers(); diff --git a/src/core/config.js b/src/core/config.js index 13f94223..19925e9b 100755 --- a/src/core/config.js +++ b/src/core/config.js @@ -25,7 +25,7 @@ Melown.Core.prototype.initConfig = function() { mapHeightLodBlend_ : true, mapHeightNodeBlend_ : true, mapBasicTileSequence_ : false, - mapPreciseBBoxTest_ : true, + mapPreciseBBoxTest_ : false, mapPreciseDistanceTest_ : false, mapHeightfiledWhenUnloaded_ : true, mapForceMetatileV3_ : false, @@ -37,6 +37,8 @@ Melown.Core.prototype.initConfig = function() { mapGeodataLoadMode_ : "fit", //"fitonly" mapXhrImageLoad_ : false, mapStoreLoadStats_ : true, + mapDegradeHorizon_ : false, + mapDegradeHorizonParams_ : [1, 1500, 97500, 3500], //[1, 3000, 15000, 7000], mapFog_ : true, rendererAntialiasing_ : true, rendererAllowScreenshots_ : false, diff --git a/src/core/core.js b/src/core/core.js index 2d09b64f..9b967590 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -268,7 +268,7 @@ string getCoreVersion() */ Melown.getCoreVersion = function(full_) { - return (full_ ? "Core: " : "") + "1.89"; + return (full_ ? "Core: " : "") + "1.94"; }; diff --git a/src/core/inspector/input.js b/src/core/inspector/input.js index f40b8738..b2cfce64 100755 --- a/src/core/inspector/input.js +++ b/src/core/inspector/input.js @@ -1,4 +1,11 @@ +//mouse events +/* +Melown.Inspector.prototype.onClick = function(event_) { + if (this.measureMode_) { + var pos_ = this.core_.hitTest(this.mouseX_, this.mouseY_, "all"); + } +};*/ //keyboard events Melown.Inspector.prototype.onKeyDown = function(event_) { @@ -109,10 +116,16 @@ Melown.Inspector.prototype.onKeyUp = function(event_, press_) { switch(keyCode_) { - case 68: - case 100: - break; //key D pressed + case 67: + case 99: + map_.config_.mapDegradeHorizon_ = !map_.config_.mapDegradeHorizon_; + + //this.measureMode_ = !this.measureMode_; + //this.measurePoints_ = []; + //var pos_ = this.core_.hitTest(this.mouseX_, this.mouseY_, "all"); + //console.log("hit pos: " + pos_[0] + " " + pos_[1] + " " + pos_[2] + " " + pos_[3] + " d " + pos_[4]); //key T pressed + break; //key C pressed case 49: /*this.core_.setControlMode("manual"); done_();*/ break; //key 1 pressed case 50: /*this.core_.setControlMode("drone"); done_();*/ break; //key 2 pressed diff --git a/src/core/inspector/inspector.js b/src/core/inspector/inspector.js index 6b068413..a7f1511b 100755 --- a/src/core/inspector/inspector.js +++ b/src/core/inspector/inspector.js @@ -11,6 +11,9 @@ Melown.Inspector = function(core_) { this.initReplayPanel(); this.initStylesheetsPanel(); + //mouse events + //document.addEventListener("click", this.onKeyClick.bind(this), false); + //keyboard events document.addEventListener("keyup", this.onKeyUp.bind(this), false); document.addEventListener("keypress", this.onKeyPress.bind(this), false); @@ -23,6 +26,8 @@ Melown.Inspector = function(core_) { this.drawRadar_ = false; this.radarLod_ = null; this.debugValue_ = 0; + this.measureMode_ = false; + this.measurePoints_ = []; }; Melown.Inspector.prototype.addStyle = function(string_) { @@ -48,6 +53,12 @@ Melown.Inspector.prototype.onMapUpdate = function(string_) { map_.redraw(); } + /*if (this.measureMode_) { + var renderer_ = this.core_.getRenderer(); + var p_ = map_.convertCoordsFromPhysToNav(this.measurePoints_[0]); + map_.convertCoordsFromPhysToCanvas(this.measurePoints_[0]); + }*/ + if (this.drawReplayGlobe_) { var renderer_ = this.core_.getRenderer(); var p_ = map_.convertCoordsFromPhysToCameraSpace([0,0,0]); diff --git a/src/core/map/bound-layer.js b/src/core/map/bound-layer.js index 06e148a7..b909d7f3 100755 --- a/src/core/map/bound-layer.js +++ b/src/core/map/bound-layer.js @@ -111,6 +111,16 @@ Melown.MapBoundLayer.prototype.parseJson = function(json_) { }; +Melown.MapBoundLayer.prototype.kill = function() { +}; + +Melown.MapBoundLayer.prototype.setOptions = function(options_) { +}; + +Melown.MapBoundLayer.prototype.getOptions = function() { + return this.getInfo(); +}; + Melown.MapBoundLayer.prototype.getInfo = function() { return { "type" : this.type_, diff --git a/src/core/map/camera.js b/src/core/map/camera.js index 24f34413..a2af2926 100755 --- a/src/core/map/camera.js +++ b/src/core/map/camera.js @@ -39,6 +39,10 @@ Melown.Map.prototype.updateCamera = function() { this.cameraDistance2_ = this.position_.getViewDistance(); this.cameraDistance_ = Math.max(this.cameraTerrainHeight_, this.cameraDistance2_); this.cameraDistance_ = Melown.clamp(this.cameraDistance_, 0.1, this.camera_.getFar()); + + this.cameraDistanceFactor_ = Math.tan(Melown.radians(this.position_.getFov()*0.5)); + + this.cameraPerceivedDistance_ = Math.max(this.cameraTerrainHeight_, this.cameraDistance2_ * this.cameraDistanceFactor_); //this.renderer_.cameraDistance_ = camInfo_.distance_; //needed for fog this.renderer_.cameraDistance_ = this.cameraDistance_; //needed for fog @@ -50,8 +54,9 @@ Melown.Map.prototype.updateCamera = function() { this.camera_.setViewHeight(this.position_.getViewExtent()); //this.camera_.setOrtho(true); - //convert public coords to physical - var worldPos_ = this.convertCoords([this.position_.getCoords()[0], this.position_.getCoords()[1], height_], "navigation", "physical"); + //convert nav coords to physical + var coords_ = this.position_.getCoords(); + var worldPos_ = this.convertCoords([coords_[0], coords_[1], height_], "navigation", "physical"); this.cameraCenter_ = [worldPos_[0], worldPos_[1], worldPos_[2]]; worldPos_[0] += camInfo_.orbitCoords_[0]; worldPos_[1] += camInfo_.orbitCoords_[1]; diff --git a/src/core/map/draw.js b/src/core/map/draw.js index 7f5f5e15..4203fb12 100755 --- a/src/core/map/draw.js +++ b/src/core/map/draw.js @@ -10,6 +10,10 @@ Melown.Map.prototype.draw = function(skipFreeLayers_, projected_, camInfo_) { this.drawTileCounter_ = 0; var cameraPos_ = this.cameraPosition_; + if (this.freeLayersHaveGeodata_ && this.drawChannel_ == 0) { + this.renderer_.drawGpuJobs(); + } + if (this.drawEarth_) { if (this.replay_.storeNodes_ || this.replay_.storeFreeNodes_) { this.replay_.nodeBuffer_ = []; @@ -96,7 +100,6 @@ Melown.Map.prototype.draw = function(skipFreeLayers_, projected_, camInfo_) { (this.replay_.drawLoaded_ && this.replay_.loaded_)) { if (this.freeLayersHaveGeodata_) { - this.renderer_.drawGpuJobs(); this.renderer_.clearJobBuffer(); } } @@ -301,7 +304,6 @@ Melown.Map.prototype.draw = function(skipFreeLayers_, projected_, camInfo_) { }*/ if (this.freeLayersHaveGeodata_) { - this.renderer_.drawGpuJobs(); this.renderer_.clearJobBuffer(); } } @@ -981,7 +983,7 @@ Melown.Map.prototype.drawGeodataTile = function(tile_, node_, cameraPos_, pixelS }; Melown.Map.prototype.drawMonoliticGeodata = function(surface_) { - if (!surface_) { + if (!surface_ || this.drawChannel_ != 0) { return; } @@ -990,7 +992,12 @@ Melown.Map.prototype.drawMonoliticGeodata = function(surface_) { } if (surface_.monoGeodata_ == null) { - var path_ = surface_.getMonoGeodataUrl(surface_.id_); + if (typeof surface_.geodataUrl_ === "object") { + var path_ = surface_.geodataUrl_; + } else { + var path_ = surface_.getMonoGeodataUrl(surface_.id_); + } + surface_.monoGeodata_ = new Melown.MapGeodata(this, path_, {tile_:null, surface_:surface_}); } @@ -1124,7 +1131,7 @@ Melown.Map.prototype.updateTileSurfaceBounds = function(tile_, submesh_, surface var texture_ = tile_.boundTextures_[layer_.id_]; - if (!texture_) { + if (!texture_) { //TODO: make sure that we load only textures which we need var path_ = layer_.getUrl(tile_.id_); texture_ = tile_.resources_.getTexture(path_, null, extraBound_, {tile_: tile_, layer_: layer_}, tile_, false); texture_.isReady(true); //check for mask but do not load diff --git a/src/core/map/geodata-processor/processor.js b/src/core/map/geodata-processor/processor.js index 48b064d2..ffc7674e 100755 --- a/src/core/map/geodata-processor/processor.js +++ b/src/core/map/geodata-processor/processor.js @@ -28,7 +28,7 @@ Melown.MapGeodataProcessor = function(surface_, listener_) { } else { //debug worker - this.processWorker_ = new Worker("../melown-core-api/melown-core/map/geodata-processor/worker-debug.js"); + this.processWorker_ = new Worker("../src/core/map/geodata-processor/worker-debug.js"); this.processWorker_.onerror = function(event){ throw new Error(event.message + " (" + event.filename + ":" + event.lineno + ")"); diff --git a/src/core/map/geodata.js b/src/core/map/geodata.js index 36ebd16e..9aea9bbf 100755 --- a/src/core/map/geodata.js +++ b/src/core/map/geodata.js @@ -17,6 +17,8 @@ Melown.MapGeodata = function(map_, url_, extraInfo_) { this.loadState_ = 0; this.loadErrorTime_ = null; this.loadErrorCounter_ = 0; + + this.map_.markDirty(); }; Melown.MapGeodata.prototype.kill = function() { @@ -59,7 +61,17 @@ Melown.MapGeodata.prototype.isReady = function(doNotLoad_, priority_, doNotCheck } else { //not loaded //add to loading queue or top position in queue - this.scheduleLoad(priority_); + + + if (typeof this.mapLoaderUrl_ === "object") { //use geodata directly + this.geodata_ = JSON.stringify(this.mapLoaderUrl_); + this.loadState_ = 2; + this.cacheItem_ = this.map_.resourcesCache_.insert(this.killGeodata.bind(this, true), this.geodata_.length); + this.map_.resourcesCache_.updateItem(this.cacheItem_); + return true; + } else { + this.scheduleLoad(priority_); + } } } else if (this.loadState_ == 3) { //loadError if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_ && diff --git a/src/core/map/interface.js b/src/core/map/interface.js index bcf430a5..138c63d8 100755 --- a/src/core/map/interface.js +++ b/src/core/map/interface.js @@ -85,6 +85,40 @@ Melown.MapInterface.prototype.getReferenceFrame = function() { return this.map_.referenceFrame_.getInfo(); }; +Melown.MapInterface.prototype.addFreeLayer = function(id_, options_) { + var layer_ = new Melown.MapSurface(this.map_, options_, "free"); + this.map_.addFreeLayer(id_, layer_); +}; + +Melown.MapInterface.prototype.removeFreeLayer = function(id_) { + this.map_.removeFreeLayer(id_); +}; + +/* Melown.MapInterface.prototype.setFreeLayerOptions = function(id_, options_) { + this.map_.setFreeLayerOptions(id_, options_); +}; + +Melown.MapInterface.prototype.getFreeLayerOptions = function(id_) { + return this.map_.getFreeLayerOptions(id_); +}; */ + +Melown.MapInterface.prototype.addBoundLayer = function(id_, options_) { + var layer_ = new Melown.MapBoundLayer(this.map_, options_, id_); + this.map_.addBoundLayer(id_, layer_); +}; + +Melown.MapInterface.prototype.removeBoundLayer = function(id_) { + this.map_.removeBoundLayer(id_); +}; + +/* Melown.MapInterface.prototype.setBoundLayerOptions = function(id_, options_) { + this.map_.setBoundLayerOptions(id_, options_); +}; + +Melown.MapInterface.prototype.getBoundLayerOptions = function(id_) { + return this.map_.setBoundLayerOptions(id_); +};*/ + Melown.MapInterface.prototype.convertPositionViewMode = function(position_, mode_) { var pos_ = (new Melown.MapPosition(this.map_, position_)).convertViewMode(mode_); return (pos_ != null) ? pos_.pos_ : pos_; @@ -341,6 +375,14 @@ Melown.MapInterface.prototype.getStats = function() { }; }; +Melown.MapInterface.prototype.click = function(screenX_, screenY_, state_) { + map_.click(screenX_, screenY_, state_); +}; + +Melown.MapInterface.prototype.hover = function(screenX_, screenY_, persistent_, state_) { + map_.hover(screenX_, screenY_, persistent_, state_); +}; + Melown.MapPositionInterface = Melown.MapPosition; Melown.MapInterface.prototype["setPosition"] = Melown.MapInterface.prototype.setPosition; @@ -361,6 +403,14 @@ Melown.MapInterface.prototype["getSurfaceInfo"] = Melown.MapInterface.prototype. Melown.MapInterface.prototype["getSrses"] = Melown.MapInterface.prototype.getSrses; Melown.MapInterface.prototype["getSrsInfo"] = Melown.MapInterface.prototype.getSrsInfo; Melown.MapInterface.prototype["getReferenceFrame"] = Melown.MapInterface.prototype.getReferenceFrame; +Melown.MapInterface.prototype["addFreeLayer"] = Melown.MapInterface.prototype.addFreeLayer; +Melown.MapInterface.prototype["removeFreeLayer"] = Melown.MapInterface.prototype.removeFreeLayer; +//Melown.MapInterface.prototype["setFreeLayerOptions"] = Melown.MapInterface.prototype.setFreeLayerOptions; +//Melown.MapInterface.prototype["getFreeLayerOptions"] = Melown.MapInterface.prototype.getFreeLayerOptions; +Melown.MapInterface.prototype["addBoundLayer"] = Melown.MapInterface.prototype.addBoundLayer; +Melown.MapInterface.prototype["removeBoundLayer"] = Melown.MapInterface.prototype.removeBoundLayer; +//Melown.MapInterface.prototype["setBoundLayerOptions"] = Melown.MapInterface.prototype.setBoundLayerOptions; +//Melown.MapInterface.prototype["getBoundLayerOptions"] = Melown.MapInterface.prototype.getBoundLayerOptions; Melown.MapInterface.prototype["convertPositionViewMode"] = Melown.MapInterface.prototype.convertPositionViewMode; Melown.MapInterface.prototype["convertPositionHeightMode"] = Melown.MapInterface.prototype.convertPositionHeightMode; Melown.MapInterface.prototype["convertCoords"] = Melown.MapInterface.prototype.convertCoords; @@ -406,4 +456,6 @@ Melown.MapInterface.prototype["getGpuCache"] = Melown.MapInterface.prototype.get Melown.MapInterface.prototype["getHitCoords"] = Melown.MapInterface.prototype.getHitCoords; Melown.MapInterface.prototype["getScreenRay"] = Melown.MapInterface.prototype.getScreenRay; Melown.MapInterface.prototype["getStats"] = Melown.MapInterface.prototype.getStats; +Melown.MapInterface.prototype["click"] = Melown.MapInterface.prototype.click; +Melown.MapInterface.prototype["hover"] = Melown.MapInterface.prototype.hover; diff --git a/src/core/map/map.js b/src/core/map/map.js index 24b311dd..a6561bc0 100755 --- a/src/core/map/map.js +++ b/src/core/map/map.js @@ -128,7 +128,10 @@ Melown.Map = function(core_, mapConfig_, path_, config_) { this.tmpVec3_ = new Array(3); this.tmpVec5_ = new Array(5); - this.maxDivisionNodeDepth_ = this.getMaxSpatialDivisionNodeDepth(); + var res_ = this.getSpatialDivisionNodeDepths(); + + this.minDivisionNodeDepth_ = res_[0]; + this.maxDivisionNodeDepth_ = res_[1]; this.tree_ = new Melown.MapSurfaceTree(this, false); this.afterConfigParsed(); @@ -171,6 +174,19 @@ Melown.Map = function(core_, mapConfig_, path_, config_) { this.log8_ = Math.log(8); this.log2_ = Math.log(2); + this.dirty_ = true; + this.hitMapDirty_ = true; + this.geoHitMapDirty_ = true; + + this.clickEvent_ = null; + this.hoverEvent_ = null; + this.hoverFeature_ = null; + this.hoverFeatureId_ = null; + this.lastHoverFeature_ = null; + this.lastHoverFeatureId_ = null; + this.hoverFeatureCounter_ = 0; + this.hoverFeatureList_ = []; + this.drawTileState_ = this.renderer_.gpu_.createState({}); this.drawStardomeState_ = this.renderer_.gpu_.createState({zwrite_:false, ztest_:false}); this.drawBlendedTileState_ = this.renderer_.gpu_.createState({zequal_:true, blend_:true}); @@ -386,6 +402,27 @@ Melown.Map.prototype.addBoundLayer = function(id_, layer_) { this.boundLayers_[id_] = layer_; }; +Melown.Map.prototype.setBoundLayerOptions = function(id_, options_) { + if (this.boundLayers_[id_]) { + this.boundLayers_[id_].setOptions(options_); + } +}; + +Melown.Map.prototype.getBoundLayerOptions = function(id_) { + if (this.boundLayers_[id_]) { + return this.boundLayers_[id_].getOptions(); + } + + return null; +}; + +Melown.Map.prototype.removeBoundLayer = function(id_, layer_) { + if (this.boundLayers_[id_]) { + this.boundLayers_[id_].kill(); + this.boundLayers_[id_] = null; + } +}; + Melown.Map.prototype.getBoundLayerByNumber = function(number_) { var layers_ = this.boundLayers_; for (var key_ in layers_) { @@ -407,6 +444,31 @@ Melown.Map.prototype.getBoundLayers = function() { Melown.Map.prototype.addFreeLayer = function(id_, layer_) { this.freeLayers_[id_] = layer_; + this.setView(this.getView()); + this.markDirty(); +}; + +Melown.Map.prototype.removeFreeLayer = function(id_) { + if (this.freeLayers_[id_]) { + this.freeLayers_[id_].kill(); + this.freeLayers_[id_] = null; + this.setView(this.getView()); + this.markDirty(); + } +}; + +Melown.Map.prototype.setFreeLayerOptions = function(id_, options_) { + if (this.freeLayers_[id_]) { + this.freeLayers_[id_].setOptions(options_); + } +}; + +Melown.Map.prototype.getFreeLayerOptions = function(id_) { + if (this.freeLayers_[id_]) { + return this.freeLayers_[id_].getOptions(); + } + + return null; }; Melown.Map.prototype.getFreeLayer = function(id_) { @@ -722,6 +784,8 @@ Melown.Map.prototype.setConfigParam = function(key_, value_) { case "mapHeightfiledWhenUnloaded": this.config_.mapHeightfiledWhenUnloaded_= Melown.validateBool(value_, false); break; case "mapForceMetatileV3": this.config_.mapForceMetatileV3_= Melown.validateBool(value_, false); break; case "mapVirtualSurfaces": this.config_.mapVirtualSurfaces_ = Melown.validateBool(value_, true); break; + case "mapDegradeHorizon": this.config_.mapDegradeHorizon_ = Melown.validateBool(value_, true); break; + case "mapDegradeHorizonParams": this.config_.mapDegradeHorizonParams_ = Melown.validateNumberArray(value_, 4, [0,1,1,1], [Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE], [1, 3000, 15000, 7000]); break; case "mario": this.config_.mario_ = Melown.validateBool(value_, true); break; } }; @@ -760,13 +824,24 @@ Melown.Map.prototype.getConfigParam = function(key_) { case "mapHeightfiledWhenUnloaded": return this.config_.mapHeightfiledWhenUnloaded_; case "mapForceMetatileV3": return this.config_.mapForceMetatileV3_; case "mapVirtualSurfaces": return this.config_.mapVirtualSurfaces_; + case "mapDegradeHorizon": return this.config_.mapDegradeHorizon_; + case "mapDegradeHorizonParams": return this.config_.mapDegradeHorizonParams_; case "mario": return this.config_.mario_; } }; +Melown.Map.prototype.click = function(screenX_, screenY_, state_) { + this.clickEvent_ = [screenX_, screenY_, state_]; +}; + +Melown.Map.prototype.hover = function(screenX_, screenY_, persistent_, state_) { + this.hoverEvent_ = [screenX_, screenY_, persistent_, state_]; +}; + Melown.Map.prototype.markDirty = function() { this.dirty_ = true; this.hitMapDirty_ = true; + this.geoHitMapDirty_ = true; }; Melown.Map.prototype.getScreenRay = function(screenX_, screenY_) { @@ -858,6 +933,83 @@ Melown.Map.prototype.getHitCoords = function(screenX_, screenY_, mode_, lod_) { return navCoords_; }; +Melown.Map.prototype.hitTestGeoLayers = function(screenX_, screenY_, mode_) { + if (this.geoHitMapDirty_) { + if (this.freeLayersHaveGeodata_) { + this.renderer_.switchToFramebuffer("geo"); + this.renderer_.drawGpuJobs(); + this.renderer_.switchToFramebuffer("base"); + this.geoHitMapDirty_ = false; + } + } + + var res_ = this.renderer_.hitTestGeoLayers(screenX_, screenY_, mode_); + + if (res_[0]) { //do we hit something? + //console.log(JSON.stringify([id_, JSON.stringify(this.hoverFeatureList_[id_])])); + + if (mode_ == "hover") { + this.lastHoverFeature_ = this.hoverFeature_; + this.lastHoverFeatureId_ = this.hoverFeatureId_; + this.hoverFeature_ = null; + this.hoverFeatureId_ = null; + this.hoverFeature_ = this.hoverFeatureList_[id_]; + this.hoverFeatureId_ = (this.hoverFeature_ != null) ? this.hoverFeature_[0]["id"] : null; + + var relatedEvents_ = []; + + if (this.hoverFeatureId_ != this.lastHoverFeatureId_) { + if (this.lastHoverFeatureId_ != null) { + relatedEvents_.push(["leave", this.lastHoverFeature_, this.lastHoverFeatureId_]); + } + + if (this.hoverFeatureId_ != null) { + relatedEvents_.push(["enter", this.hoverFeature_, this.hoverFeatureId_]); + } + + this.dirty_ = true; + } + + if (this.hoverFeature_ != null && this.hoverFeature_[3] == true) { + return [this.hoverFeature_, surfaceHit_, relatedEvents_]; + } else { + return [null, false, relatedEvents_]; + } + } + + if (mode_ == "click") { + var feature_ = this.hoverFeatureList_[id_]; + //this.hoverFeatureId_ = (this.hoverFeature_ != null) ? this.hoverFeature_["id"] : null; + + if (feature_ != null && this.hoverFeature_ != null && this.hoverFeature_[2] == true) { + return [feature_, surfaceHit_, []]; + } else { + return [null, false, []]; + } + } + } else { + var relatedEvents_ = []; + + if (mode_ == "hover") { + this.lastHoverFeature_ = this.hoverFeature_; + this.lastHoverFeatureId_ = this.hoverFeatureId_; + this.hoverFeature_ = null; + this.hoverFeatureId_ = null; + + if (this.lastHoverFeatureId_ != null) { + if (this.lastHoverFeatureId_ != null) { + relatedEvents_.push(["leave", this.lastHoverFeature_, this.lastHoverFeatureId_]); + } + + this.dirty_ = true; + } + } + + return [null, false, relatedEvents_]; + } +}; + + Melown.Map.prototype.drawMap = function() { if (this.drawChannel_ != 1) { this.renderer_.gpu_.setViewport(); @@ -901,6 +1053,9 @@ Melown.Map.prototype.drawMap = function() { this.renderer_.distanceFactor_ = 1 / Math.max(1,Math.log(this.cameraDistance_) / Math.log(1.04)); this.renderer_.tiltFactor_ = (Math.abs(this.renderer_.cameraOrientation_[1]/-90)); + + this.degradeHorizonFactor_ = 200.0 * this.config_.mapDegradeHorizonParams_[0]; + this.degradeHorizonTiltFactor_ = 0.5*(1.0+Math.cos(Melown.radians(Math.min(180,Math.abs(this.renderer_.cameraOrientation_[1]*2*3))))); if (this.drawChannel_ != 1) { this.renderer_.gpu_.clear(true, false); @@ -1017,6 +1172,58 @@ Melown.Map.prototype.update = function() { //console.log("" + this.stats_.gpuRenderUsed_); } + //hover and click events + if (this.clickEvent_ != null || this.hoverEvent_ != null) { + //this.updateGeoHitmap_ = this.dirty_; + + if (this.hoverEvent_ != null) { + var result_ = this.hitTestGeoLayers(this.hoverEvent_[0], this.hoverEvent_[1], "hover"); + + if (result_[1] == true && result_[0] != null) { + this.core_.callListener("geo-feature-hover", {"feature": result_[0][0], "screen-pos":this.project(result_[0][1]), + "scene-pos":result_[0][1], "state": this.hoverEvent_[3] }); + } + + var relatedEvents_ = result_[2]; + + if (relatedEvents_ != null) { + for(var i = 0, li = relatedEvents_.length; i < li; i++) { + var event_ = relatedEvents_[i]; + + switch(event_[0]) { + case "enter": + this.core_.callListener("geo-feature-enter", {"feature": event_[0], "screen-pos":this.project(event_[1]), + "scene-pos":event_[1], "state": this.hoverEvent_[3] }); + break; + + case "leave": + this.core_.callListener("geo-feature-leave", {"feature":event_[0], "screen-pos":this.project(event_[1]), + "scene-pos":event_[1], "state": this.hoverEvent_[3] }); + break; + } + } + } + + //is it persistent event? + if (this.hoverEvent_[2] != true) { + this.hoverEvent_ = null; + } + } + + if (this.clickEvent_ != null) { + var result_ = this.hitTestGeoLayers(this.clickEvent_[0], this.clickEvent_[1], "click"); + + if (result_[1] == true && result_[0] != null) { + this.core_.callListener("geo-feature-click", {"feature": result_[0][0], "screen-pos":this.project(result_[0][1]), + "scene-pos":result_[0][1], "state": this.hoverEvent_[3] }); + } + + this.clickEvent_ = null; + } + + } + + this.stats_.end(dirty_); }; diff --git a/src/core/map/measure.js b/src/core/map/measure.js index 7ec91779..aa89e040 100755 --- a/src/core/map/measure.js +++ b/src/core/map/measure.js @@ -246,8 +246,8 @@ Melown.Map.prototype.getSurfaceHeightNodeOnly = function(coords_, lod_, storeSta Melown.Map.prototype.getHeightmapValue = function(coords_, node_, params_) { var heightMap_ = params_.heightMap_; - var data_ = heightMap_.imageData_; - var dataExtents_ = heightMap_.imageExtents_; + var data_ = heightMap_.getImageData(); + var dataExtents_ = heightMap_.getImageExtents(); var mapExtents_ = params_.heightMapExtents_; //relative tile coords @@ -342,6 +342,10 @@ Melown.Map.prototype.getSpatialDivisionNodeAndExtents = function(id_) { } } + if (!bestNode_) { + return null; + } + var shift_ = id_[0] - bestNode_.id_[0]; var factor_ = 1.0 / Math.pow(2, shift_); @@ -395,19 +399,24 @@ Melown.Map.prototype.getSpatialDivisionNodeAndExtents2 = function(id_, res_, div }; -Melown.Map.prototype.getMaxSpatialDivisionNodeDepth = function() { +Melown.Map.prototype.getSpatialDivisionNodeDepths = function() { var nodes_ = this.referenceFrame_.getSpatialDivisionNodes(); var maxLod_ = -1; + var minLod_ = Number.MAX_VALUE; for (var i = 0, li = nodes_.length; i < li; i++) { var node_ = nodes_[i]; + + if (node_.id_[0] < minLod_) { + minLod_ = node_.id_[0]; + } if (node_.id_[0] > maxLod_) { maxLod_ = node_.id_[0]; } } - return maxLod_; + return [minLod_, maxLod_]; }; Melown.Map.prototype.getOptimalHeightLodBySampleSize = function(coords_, desiredSamplesSize_) { diff --git a/src/core/map/metanode.js b/src/core/map/metanode.js index 905ccf40..36c2e3ae 100755 --- a/src/core/map/metanode.js +++ b/src/core/map/metanode.js @@ -256,7 +256,7 @@ Melown.MapMetanode.prototype.generateCullingHelpers = function(virtual_) { var geocent_ = map_.geocent_; var version_ = this.metatile_.useVersion_; - if (!geocent_ && version_ < 4) { + if (this.id_[0] < map_.minDivisionNodeDepth_ || (!geocent_ && version_ < 4)) { return; } @@ -322,10 +322,14 @@ Melown.MapMetanode.prototype.generateCullingHelpers = function(virtual_) { // var res_ = this.map_.getSpatialDivisionNodeAndExtents(this.id_); // node_ = node_; //} - + pos_[0] = urx_; pos_[1] = ury_; pos_[2] = h; + + /*if (this.id_[0] == 17 && this.id_[1] == 53306 && this.id_[2] == 30754) { + normal_ = normal_; + }*/ var bbox_ = this.bbox2_; diff --git a/src/core/map/metatile.js b/src/core/map/metatile.js index 0fe7bd46..18a73038 100755 --- a/src/core/map/metatile.js +++ b/src/core/map/metatile.js @@ -427,7 +427,15 @@ Melown.MapMetatile.prototype.parseMetatatileNodes = function(stream_) { } } - this.divisionNode_ = this.map_.getSpatialDivisionNodeAndExtents([this.lod_, this.metatileIdx_ + this.offsetx_, this.metatileIdy_ + this.offsety_])[0]; + if (this.lod_ >= this.map_.minDivisionNodeDepth_) { + this.divisionNode_ = this.map_.getSpatialDivisionNodeAndExtents([this.lod_, this.metatileIdx_ + this.offsetx_, this.metatileIdy_ + this.offsety_]); + if (this.divisionNode_) { + this.divisionNode_ = this.divisionNode_[0]; + } + } else { + this.divisionNode_ = null; + } + this.nodes_ = new Array(this.sizex_*this.sizey_); /* diff --git a/src/core/map/refframe.js b/src/core/map/refframe.js index e875eff3..1101c3e1 100755 --- a/src/core/map/refframe.js +++ b/src/core/map/refframe.js @@ -97,9 +97,6 @@ Melown.MapRefFrame.prototype.parseNode = function(nodeData_) { position_ : nodeId_["position"] || [0,0] }; - //node_.divisionNode_ = - //node_.refFrame_.loadResources(); - return new Melown.MapDivisionNode(this.map_, [node_.id_.lod_, node_.id_.position_[0], node_.id_.position_[1]], node_.srs_, node_.extents_, this.heightRange_, node_.partitioning_); }; @@ -130,47 +127,6 @@ Melown.MapRefFrame.prototype.getSpatialDivisionNodes = function() { return this.division_.nodes_; }; -/* -Melown.MapRefFrame.prototype.getRefFrame = function(id_) { - var lod_ = id_[0]; - - var refFrame_ = null; - var nodes_ = this.division_.nodes_; - var rootLod_ = this.division_.rootLod_; - - if (lod_ < rootLod_) { - return null; - } - - //find root node - for (var i = 0, li = nodes_.length_; i < li; i++) { - var nodeId_ = nodes_[i].id_; - - if (rootLod_ == nodeId_.lod_) { - refFrame_ = nodes_[i].refFrame_; - } - } - - //find nearest node - for (var i = 0, li = nodes_.length_; i < li; i++) { - var nodeId_ = nodes_[i].id_; - - if (lod_ >= nodeId_.lod_) { - //TODO: reduce nodeId_ to id_ - var shift_ = (nodeId_.lod_ - lod_); - var x = id_[1] >> shift_; - var y = id_[2] >> shift_; - - if (nodeId_.position_[0] == x && nodeId_.position_[1] == y) { - return nodes_[i].refFrame_; - } - } - } - - return refFrame_; -}; -*/ - Melown.MapRefFrame.prototype.convertCoords = function(coords_, source_, destination_) { var sourceSrs_, destinationSrs_; diff --git a/src/core/map/resource-node.js b/src/core/map/resource-node.js index 964d221e..83994af4 100755 --- a/src/core/map/resource-node.js +++ b/src/core/map/resource-node.js @@ -9,6 +9,7 @@ Melown.MapResourceNode = function(map_, parent_, id_) { this.metatiles_ = {}; this.meshes_ = {}; this.textures_ = {}; + this.subtextures_ = {}; this.geodata_ = {}; this.credits_ = {}; @@ -97,11 +98,34 @@ Melown.MapResourceNode.prototype.getGeodata = function(path_, extraInfo_) { // Textures --------------------------------- Melown.MapResourceNode.prototype.getTexture = function(path_, heightMap_, extraBound_, extraInfo_, tile_, internal_) { - var texture_ = this.textures_[path_]; + if (extraInfo_ && extraInfo_.layer_) { + var id_ = path_ + extraInfo_.layer_.id_; + var texture_ = this.textures_[id_]; + + if (!texture_) { + texture_ = new Melown.MapTexture(this.map_, path_, heightMap_, extraBound_, extraInfo_, tile_, internal_); + this.textures_[id_] = texture_; + } + } else { + var texture_ = this.textures_[path_]; + + if (!texture_) { + texture_ = new Melown.MapTexture(this.map_, path_, heightMap_, extraBound_, extraInfo_, tile_, internal_); + this.textures_[path_] = texture_; + } + } + + return texture_; +}; + +// SubTextures --------------------------------- + +Melown.MapResourceNode.prototype.getSubtexture = function(texture_, path_, heightMap_, extraBound_, extraInfo_, tile_, internal_) { + var texture_ = this.subtextures_[path_]; if (!texture_) { - texture_ = new Melown.MapTexture(this.map_, path_, heightMap_, extraBound_, extraInfo_, tile_, internal_); - this.textures_[path_] = texture_; + texture_ = new Melown.MapSubtexture(this.map_, path_, heightMap_, extraBound_, extraInfo_, tile_, internal_); + this.subtextures_[path_] = texture_; } return texture_; diff --git a/src/core/map/stylesheet.js b/src/core/map/stylesheet.js index 883acd4f..fc3ed8a5 100755 --- a/src/core/map/stylesheet.js +++ b/src/core/map/stylesheet.js @@ -83,6 +83,7 @@ Melown.MapStylesheet.prototype.onLoaded = function(data_) { //this.mapLoaderCallLoaded_(); this.loadState_ = 2; + this.map_.markDirty(); }; //! Returns RAM usage in bytes. diff --git a/src/core/map/subtexture.js b/src/core/map/subtexture.js index 688929fb..b060178a 100755 --- a/src/core/map/subtexture.js +++ b/src/core/map/subtexture.js @@ -1 +1,479 @@ -// exist in newtextures brunch \ No newline at end of file +/** + * @constructor + */ +Melown.MapSubtexture = function(map_, path_, heightMap_, tile_, internal_) { + this.map_ = map_; + this.stats_ = map_.stats_; + this.tile_ = tile_; // used only for stats + this.internal_ = internal_; // used only for stats + this.image_ = null; + this.imageData_ = null; + this.imageExtents_ = null; + this.gpuTexture_ = null; + this.loadState_ = 0; + this.loadErrorTime_ = null; + this.loadErrorCounter_ = 0; + this.neverReady_ = false; + this.mapLoaderUrl_ = path_; + this.heightMap_ = heightMap_ || false; + this.statsCounter_ = 0; + this.checkStatus_ = 0; + this.checkType_ = null; + this.checkValue_ = null; + this.fastHeaderCheck_ = false; + this.fileSize_ = 0; + this.cacheItem_ = null; //store killImage + this.gpuCacheItem_ = null; //store killGpuTexture +}; + +Melown.MapSubtexture.prototype.kill = function() { + this.killImage(); + this.killGpuTexture(); + + if (this.mask_) { + this.mask_.killImage(); + this.mask_.killGpuTexture(); + } + + //this.tile_.validate(); +}; + +Melown.MapSubtexture.prototype.killImage = function(killedByCache_) { + this.image_ = null; + this.imageData_ = null; + + if (killedByCache_ != true && this.cacheItem_) { + this.map_.resourcesCache_.remove(this.cacheItem_); + //this.tile_.validate(); + } + + if (this.mask_) { + this.mask_.killImage(); + } + + if (!this.gpuTexture_) { + this.loadState_ = 0; + } //else { + //this.loadState_ = this.loadState_; + //} + + this.cacheItem_ = null; +}; + +Melown.MapSubtexture.prototype.killGpuTexture = function(killedByCache_) { +/* + //debug only + if (!this.map_.lastRemoved_) { + this.map_.lastRemoved_ = []; + } + + //debug only + if (this.map_.lastRemoved_.indexOf(this.mapLoaderUrl_) != -1) { + console.log("tex: " + this.mapLoaderUrl_); + } + + //debug only + this.map_.lastRemoved_.unshift(this.mapLoaderUrl_); + this.map_.lastRemoved_ = this.map_.lastRemoved_.slice(0,20); +*/ + + if (this.gpuTexture_ != null) { + this.stats_.gpuTextures_ -= this.gpuTexture_.size_; + this.gpuTexture_.kill(); + + this.stats_.graphsFluxTexture_[1][0]++; + this.stats_.graphsFluxTexture_[1][1] += this.gpuTexture_.size_; + + if (this.mask_) { + this.mask_.killGpuTexture(); + } + } + + this.gpuTexture_ = null; + + if (killedByCache_ != true && this.gpuCacheItem_) { + this.map_.gpuCache_.remove(this.gpuCacheItem_); + //this.tile_.validate(); + } + + if (!this.image_ && !this.imageData_) { + this.loadState_ = 0; + } + + this.gpuCacheItem_ = null; +}; + +Melown.MapSubtexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheckGpu_, texture_) { + var doNotUseGpu_ = (this.map_.stats_.gpuRenderUsed_ >= this.map_.maxGpuUsed_); + doNotLoad_ = doNotLoad_ || doNotUseGpu_; + + if (this.neverReady_) { + return false; + } + + switch (texture_.checkType_) { + case "negative-type": + case "negative-code": + case "negative-size": + + if (this.checkStatus_ != 2) { + this.checkType_ = texture_.checkType_; + this.checkValue_ = texture_.checkValue_; + + if (this.checkStatus_ == 0) { + this.scheduleHeadRequest(priority_, (this.checkType_ == "negative-size")); + } else if (this.checkStatus_ == 3) { //loadError + if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_ && + performance.now() > this.loadErrorTime_ + this.map_.config_.mapLoadErrorRetryTime_) { + this.scheduleHeadRequest(priority_, (this.checkType_ == "negative-size")); + } + } else if (this.checkStatus_ == -1) { + + if (texture_.extraInfo_) { //find at least texture with lower resolution + /* + if (this.extraInfo_.tile_.id_[0] == Melown.debugId_[0] && + this.extraInfo_.tile_.id_[1] == Melown.debugId_[1] && + this.extraInfo_.tile_.id_[2] == Melown.debugId_[2]) { + this.extraInfo_ = this.extraInfo_; + }*/ + + if (!texture_.extraBound_) { + texture_.extraBound_ = { tile_: texture_.extraInfo_.tile_, layer_: texture_.extraInfo_.layer_}; + texture_.setBoundTexture(texture_.extraBound_.tile_.parent_, texture_.extraBound_.layer_); + } + + while (texture_.extraBound_.texture_.extraBound_ || texture_.extraBound_.texture_.checkStatus_ == -1) { + //while (texture_.extraBound_.texture_.checkStatus_ == -1) { + texture_.setBoundTexture(texture_.extraBound_.sourceTile_.parent_, texture_.extraBound_.layer_); + } + } + } + + return false; + } + + break; + } + + if (this.loadState_ == 2) { //loaded + if (!doNotLoad_ && this.cacheItem_) { + this.map_.resourcesCache_.updateItem(this.cacheItem_); + } + + if (((this.heightMap_ && !this.imageData_) || (!this.heightMap_ && !this.gpuTexture_)) && + this.stats_.renderBuild_ > this.map_.config_.mapMaxProcessingTime_) { + //console.log("testure resource build overflow"); + this.map_.markDirty(); + return false; + } + + if (doNotCheckGpu_) { + if (this.heightMap_) { + if (!this.imageData_) { + var t = performance.now(); + this.buildHeightMap(); + this.stats_.renderBuild_ += performance.now() - t; + } + } + + return true; + } + + if (this.heightMap_) { + if (!this.imageData_) { + var t = performance.now(); + this.buildHeightMap(); + this.stats_.renderBuild_ += performance.now() - t; + } + } else { + if (!this.gpuTexture_) { + if (this.map_.stats_.gpuRenderUsed_ >= this.map_.maxGpuUsed_) { + return false; + } + + if (doNotUseGpu_) { + return false; + } + + //if (this.stats_.graphsFluxTexture_ [0][0] > 2) { + // return false; + //} + + var t = performance.now(); + this.buildGpuTexture(); + this.stats_.renderBuild_ += performance.now() - t; + } + + if (!doNotLoad_ && this.gpuCacheItem_) { + this.map_.gpuCache_.updateItem(this.gpuCacheItem_); + } + } + + + return true; + } else { + if (this.loadState_ == 0) { + if (doNotLoad_) { + //remove from queue + //if (this.mapLoaderUrl_) { + //this.map_.loader_.remove(this.mapLoaderUrl_); + //} + } else { + //not loaded + //add to loading queue or top position in queue + this.scheduleLoad(priority_); + } + } else if (this.loadState_ == 3) { //loadError + if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_ && + performance.now() > this.loadErrorTime_ + this.map_.config_.mapLoadErrorRetryTime_) { + + this.scheduleLoad(priority_); + } + } //else load in progress + } + + return false; +}; + +Melown.MapSubtexture.prototype.scheduleLoad = function(priority_, header_) { + this.map_.loader_.load(this.mapLoaderUrl_, this.onLoad.bind(this, header_), priority_, this.tile_, this.internal_ ? "texture-in" : "texture-ex"); +}; + +Melown.MapSubtexture.prototype.onLoad = function(header_, url_, onLoaded_, onError_) { + this.mapLoaderCallLoaded_ = onLoaded_; + this.mapLoaderCallError_ = onError_; + + var onerror_ = this.onLoadError.bind(this); + var onload_ = this.onLoaded.bind(this); + + if (header_) { + this.checkStatus_ = 1; + } else { + this.loadState_ = 1; + } + + if (this.map_.config_.mapXhrImageLoad_) { + Melown.loadBinary(url_, this.onBinaryLoaded.bind(this), onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); + } else { + this.image_ = Melown.Http.imageFactory(url_, onload_, onerror_, (this.map_.core_.tokenCookieHost_ ? (url_.indexOf(this.map_.core_.tokenCookieHost_) != -1) : false)); + } + //mapXhrImageLoad_ +}; + +Melown.MapSubtexture.prototype.onLoadError = function(killBlob_) { + if (this.map_.killed_ == true){ + return; + } + + if (killBlob_) { + window.URL.revokeObjectURL(this.image_.src); + } + + this.loadState_ = 3; + this.loadErrorTime_ = performance.now(); + this.loadErrorCounter_ ++; + + //make sure we try to load it again + if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_) { + setTimeout((function(){ if (!this.map_.killed_) { this.map_.markDirty(); } }).bind(this), this.map_.config_.mapLoadErrorRetryTime_); + } + + this.mapLoaderCallError_(); +}; + +Melown.MapSubtexture.prototype.onBinaryLoaded = function(data_) { + if (this.fastHeaderCheck_ && this.checkType_ && this.checkType_ != "metatile") { + this.onHeadLoaded(null, data_, null /*status_*/); + + if (this.checkStatus_ == -1) { + this.mapLoaderCallLoaded_(); + return; + } + } + + var image_ = new Image(); + image_.onerror = this.onLoadError.bind(this, true); + image_.onload = this.onLoaded.bind(this, true); + this.image_ = image_; + image_.src = window.URL.createObjectURL(data_); + this.fileSize_ = data_.size; +}; + +Melown.MapSubtexture.prototype.onLoaded = function(killBlob_) { + if (this.map_.killed_){ + return; + } + + if (killBlob_) { + window.URL.revokeObjectURL(this.image_.src); + } + + var size_ = this.image_.naturalWidth * this.image_.naturalHeight * (this.heightMap_ ? 3 : 3); + + if (!this.image_.complete_) { + size_ = size_; + } + + //console.log(size_); + + this.cacheItem_ = this.map_.resourcesCache_.insert(this.killImage.bind(this, true), size_); + + this.map_.markDirty(); + this.loadState_ = 2; + this.loadErrorTime_ = null; + this.loadErrorCounter_ = 0; + this.mapLoaderCallLoaded_(); +}; + +Melown.MapSubtexture.prototype.scheduleHeadRequest = function(priority_, downloadAll_) { + if (this.map_.config_.mapXhrImageLoad_ && this.fastHeaderCheck_) { + this.scheduleLoad(priority_, true); + } else { + this.map_.loader_.load(this.mapLoaderUrl_, this.onLoadHead.bind(this, downloadAll_), priority_, this.tile_, this.internal_, this.internal_ ? "texture-in" : "texture-ex"); + } +}; + +//Melown.onlyOneHead_ = false; + +Melown.MapSubtexture.prototype.onLoadHead = function(downloadAll_, url_, onLoaded_, onError_) { + this.mapLoaderCallLoaded_ = onLoaded_; + this.mapLoaderCallError_ = onError_; + + var onerror_ = this.onLoadHeadError.bind(this, downloadAll_); + var onload_ = this.onHeadLoaded.bind(this, downloadAll_); + + this.checkStatus_ = 1; + + if (downloadAll_) { + Melown.loadBinary(url_, onload_, onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); + } else { + Melown.Http.headRequest(url_, onload_, onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); + } + +}; + +Melown.MapSubtexture.prototype.onLoadHeadError = function(downloadAll_) { + if (this.map_.killed_){ + return; + } + + this.checkStatus_ = 3; + this.loadErrorTime_ = performance.now(); + this.loadErrorCounter_ ++; + + //make sure we try to load it again + if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_) { + setTimeout((function(){ if (!this.map_.killed_) { this.map_.markDirty(); } }).bind(this), this.map_.config_.mapLoadErrorRetryTime_); + } + + this.mapLoaderCallError_(); +}; + +Melown.MapSubtexture.prototype.onHeadLoaded = function(downloadAll_, data_, status_) { + if (this.map_.killed_){ + return; + } + + this.checkStatus_ = 2; + this.loadErrorTime_ = null; + this.loadErrorCounter_ = 0; + + if (this.map_.config_.mapXhrImageLoad_ && this.fastHeaderCheck_) { + + switch (this.checkType_) { + case "negative-size": + if (data_) { + if (data_.size == this.checkValue_) { + this.checkStatus_ = -1; + } + } + break; + + case "negative-type": + if (data_) { + if (data_.type == this.checkValue_) { + this.checkStatus_ = -1; + } + } + break; + + case "negative-code": + if (status_) { + if (this.checkValue_.indexOf(status_) != -1) { + this.checkStatus_ = -1; + } + } + break; + } + + } else { + + switch (this.checkType_) { + case "negative-size": + if (data_) { + if (data_.byteLength == this.checkValue_) { + this.checkStatus_ = -1; + } + } + break; + + case "negative-type": + if (data_) { + if (!data_.indexOf) { + data_ = data_; + } + + if (data_.indexOf(this.checkValue_) != -1) { + this.checkStatus_ = -1; + } + } + break; + + case "negative-code": + if (status_) { + if (this.checkValue_.indexOf(status_) != -1) { + this.checkStatus_ = -1; + } + } + break; + } + + this.mapLoaderCallLoaded_(); + } +}; + + +Melown.MapSubtexture.prototype.buildGpuTexture = function () { + this.gpuTexture_ = new Melown.GpuTexture(this.map_.renderer_.gpu_, null, this.map_.core_); + this.gpuTexture_.createFromImage(this.image_, "linear", false); + this.stats_.gpuTextures_ += this.gpuTexture_.size_; + + this.stats_.graphsFluxTexture_[0][0]++; + this.stats_.graphsFluxTexture_[0][1] += this.gpuTexture_.size_; + + this.gpuCacheItem_ = this.map_.gpuCache_.insert(this.killGpuTexture.bind(this, true), this.gpuTexture_.size_); +}; + +Melown.MapSubtexture.prototype.buildHeightMap = function () { + var canvas_ = document.createElement("canvas"); + canvas_.width = this.image_.naturalWidth; + canvas_.height = this.image_.naturalHeight; + var ctx_ = canvas_.getContext("2d"); + ctx_.drawImage(this.image_, 0, 0); + this.imageData_ = ctx_.getImageData(0, 0, this.image_.naturalWidth, this.image_.naturalHeight).data; + this.imageExtents_ = [this.image_.naturalWidth, this.image_.naturalHeight]; + this.image_ = null; +}; + +Melown.MapSubtexture.prototype.getGpuTexture = function() { + return this.gpuTexture_; +}; + +Melown.MapSubtexture.prototype.getHeightMapValue = function(x, y) { + if (this.imageData_) { + return this.imageData_[(y * this.imageExtents_[0] + x)*4]; + } + + return 0; +}; + diff --git a/src/core/map/surface-tile.js b/src/core/map/surface-tile.js index 9bd822ef..bc1dd556 100755 --- a/src/core/map/surface-tile.js +++ b/src/core/map/surface-tile.js @@ -595,16 +595,11 @@ Melown.MapSurfaceTile.prototype.createVirtualMetanode = function(tree_, priority Melown.MapSurfaceTile.prototype.bboxVisible = function(id_, bbox_, cameraPos_, node_) { var map_ = this.map_; + if (id_[0] < map_.minDivisionNodeDepth_) { + return true; + } + var skipGeoTest_ = map_.config_.mapDisableCulling_; - /* - if (!skipGeoTest_ && id_[0] >= 6 && this.geocent_) { - id_ = id_; - - if (!node_.hasGeometry()) { - return false; - } - }*/ - if (!skipGeoTest_ && map_.geocent_) { if (node_) { if (true) { //version with perspektive @@ -803,7 +798,6 @@ Melown.MapSurfaceTile.prototype.getPixelSize22 = function(bbox_, screenPixelSize }; */ - Melown.MapSurfaceTile.prototype.updateTexelSize = function() { var pixelSize_; var pixelSize2_; @@ -876,6 +870,42 @@ Melown.MapSurfaceTile.prototype.updateTexelSize = function() { this.texelSize_ = pixelSize_[0]; this.distance_ = pixelSize_[1]; + + //degrade horizont + if (!map_.config_.mapDegradeHorizon_ || map_.degradeHorizonFactor_ < 1.0) { + return; + } + + var degradeHorizon_ = map_.config_.mapDegradeHorizonParams_; + var degradeFadeStart_ = degradeHorizon_[1]; + var degradeFadeEnd_ = degradeHorizon_[2]; + + //reduce degrade factor by tilt + var degradeFactor_ = map_.degradeHorizonFactor_ * map_.degradeHorizonTiltFactor_; + var distance_ = this.distance_ * map_.cameraDistanceFactor_; + + //apply degrade factor smoothly from specified tile distance + if (distance_ < degradeFadeStart_) { + degradeFactor_ = 1.0; + } else if (distance_ > degradeFadeStart_ && distance_ < degradeFadeEnd_) { + degradeFactor_ = 1.0 + (degradeFactor_-1.0) * ((distance_ - degradeFadeStart_) / (degradeFadeEnd_ - degradeFadeStart_)); + } + + degradeFactor_ = Math.max(degradeFactor_, 1.0); + + //reduce degrade factor by observed distance + var observerDistance_ = map_.cameraPerceivedDistance_; + var distanceFade_ = degradeHorizon_[3]; + + if (observerDistance_ > distanceFade_) { + degradeFactor_ = 1.0; + } else if (observerDistance_ < distanceFade_ && degradeFactor_ > 1.0) { + degradeFactor_ = 1.0 + ((degradeFactor_ - 1.0) * (1.0-(observerDistance_ / distanceFade_))); + } + + //console.log("degrade: " + degradeFactor_); + + this.texelSize_ /= degradeFactor_; }; Melown.MapSurfaceTile.prototype.drawGrid = function(cameraPos_, divNode_, angle_) { diff --git a/src/core/map/surface-tree.js b/src/core/map/surface-tree.js index 9fecd458..cd2edc8f 100755 --- a/src/core/map/surface-tree.js +++ b/src/core/map/surface-tree.js @@ -130,6 +130,10 @@ Melown.MapSurfaceTree.prototype.draw = function() { //if (this.map_.config_.mapBasicTileSequence_) { //this.surfaceTracer_ = this.surfaceTracerBasic_; //} + + if (this.freeLayerSurface_ && this.freeLayerSurface_.geodata_ && this.map_.drawChannel_ != 0) { + return; + } if (periodicity_ != null) { this.drawSurface([0,0,0]); diff --git a/src/core/map/surface.js b/src/core/map/surface.js index 02d3df36..e0a90761 100755 --- a/src/core/map/surface.js +++ b/src/core/map/surface.js @@ -122,7 +122,7 @@ Melown.MapSurface.prototype.parseJson = function(json_) { } - if (this.geodataUrl_ && this.geodataUrl_.indexOf("{geonavtile}") != -1) { + if (this.geodataUrl_ && (typeof this.geodataUrl_ === "string") && this.geodataUrl_.indexOf("{geonavtile}") != -1) { //this.geodataNavtileInfo_ = true; this.geodataNavtileInfo_ = false; } @@ -146,6 +146,26 @@ Melown.MapSurface.prototype.parseJson = function(json_) { } }; +Melown.MapSurface.prototype.kill = function() { + if (this.geodataProcessor_) { + this.geodataProcessor_.kill(); + this.geodataProcessor_ = null; + } + + this.geodataUrl_ = null; + this.style_ = null; + this.stylesheet_ = null; + this.originalStyle_ = null; + this.originalStylesheet_ = null; +}; + +Melown.MapSurface.prototype.setOptions = function(options_) { +}; + +Melown.MapSurface.prototype.getOptions = function() { + return this.getInfo(); +}; + Melown.MapSurface.prototype.getInfo = function() { if (this.geodata_) { return { @@ -175,6 +195,10 @@ Melown.MapSurface.prototype.processUrl = function(url_, fallback_) { return fallback_; } + if (typeof json_ !== "string") { + return url_; + } + url_ = url_.trim(); if (url_.indexOf("://") != -1) { //absolute @@ -253,7 +277,6 @@ Melown.MapSurface.prototype.hasMetatile = function(id_) { y < this.tileRange_[0][1] || y > this.tileRange_[1][1] ) { return false; } - } else { shift_ = -shift_; diff --git a/src/core/map/texture.js b/src/core/map/texture.js index a6558525..be40533f 100755 --- a/src/core/map/texture.js +++ b/src/core/map/texture.js @@ -6,15 +6,20 @@ Melown.MapTexture = function(map_, path_, heightMap_, extraBound_, extraInfo_, t this.stats_ = map_.stats_; this.tile_ = tile_; // used only for stats this.internal_ = internal_; // used only for stats - this.image_ = null; - this.imageData_ = null; - this.imageExtents_ = null; - this.gpuTexture_ = null; + + if (tile_) { + this.mainTexture_ = tile_.resources_.getSubtexture(this, path_, heightMap_, tile_, internal_); + } else { + this.mainTexture_ = new Melown.MapSubtexture(map_, path_, heightMap_, tile_, internal_); + } + + this.maskTexture_ = null; + this.loadState_ = 0; this.loadErrorTime_ = null; this.loadErrorCounter_ = 0; this.neverReady_ = false; - this.mask_ = null; + this.maskTexture_ = null; this.mapLoaderUrl_ = path_; this.heightMap_ = heightMap_ || false; this.extraBound_ = extraBound_; @@ -38,91 +43,33 @@ Melown.MapTexture = function(map_, path_, heightMap_, extraBound_, extraInfo_, t } } } - - this.cacheItem_ = null; //store killImage - this.gpuCacheItem_ = null; //store killGpuTexture - - //if (path_ == "http://t0.tiles.virtualearth.net/tiles/a12021212330200.jpeg?g=854&mkt=en-US&token=Ahu6LJpWaKRj0Fzngk4d58AQFI9jKLsnvovS3ReEVcfOf6rBDCxiLDq-ycxakgOi") { - //path_ = path_; - //} }; Melown.MapTexture.prototype.kill = function() { - this.texture_ = null; - this.killImage(); - this.killGpuTexture(); + this.mainTexture_.killImage(); + this.mainTexture_.killGpuTexture(); + this.mainTexture_ = null; - if (this.mask_) { - this.mask_.killImage(); - this.mask_.killGpuTexture(); + if (this.maskTexture_) { + this.maskTexture_.killImage(); + this.maskTexture_.killGpuTexture(); } - - //this.tile_.validate(); }; Melown.MapTexture.prototype.killImage = function(killedByCache_) { - this.image_ = null; - this.imageData_ = null; - - if (killedByCache_ != true && this.cacheItem_) { - this.map_.resourcesCache_.remove(this.cacheItem_); - //this.tile_.validate(); - } + this.mainTexture_.killImage(); - if (this.mask_) { - this.mask_.killImage(); + if (this.maskTexture_) { + this.maskTexture_.killImage(); } - - if (!this.gpuTexture_) { - this.loadState_ = 0; - } //else { - //this.loadState_ = this.loadState_; - //} - - this.cacheItem_ = null; }; Melown.MapTexture.prototype.killGpuTexture = function(killedByCache_) { -/* - //debug only - if (!this.map_.lastRemoved_) { - this.map_.lastRemoved_ = []; - } - - //debug only - if (this.map_.lastRemoved_.indexOf(this.mapLoaderUrl_) != -1) { - console.log("tex: " + this.mapLoaderUrl_); - } - - //debug only - this.map_.lastRemoved_.unshift(this.mapLoaderUrl_); - this.map_.lastRemoved_ = this.map_.lastRemoved_.slice(0,20); -*/ - - if (this.gpuTexture_ != null) { - this.stats_.gpuTextures_ -= this.gpuTexture_.size_; - this.gpuTexture_.kill(); + this.mainTexture_.killGpuTexture(); - this.stats_.graphsFluxTexture_[1][0]++; - this.stats_.graphsFluxTexture_[1][1] += this.gpuTexture_.size_; - - if (this.mask_) { - this.mask_.killGpuTexture(); - } - } - - this.gpuTexture_ = null; - - if (killedByCache_ != true && this.gpuCacheItem_) { - this.map_.gpuCache_.remove(this.gpuCacheItem_); - //this.tile_.validate(); + if (this.maskTexture_) { + this.maskTexture_.killGpuTexture(); } - - if (!this.image_ && !this.imageData_) { - this.loadState_ = 0; - } - - this.gpuCacheItem_ = null; }; Melown.MapTexture.prototype.setBoundTexture = function(tile_, layer_) { @@ -159,18 +106,28 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck if (this.mapLoaderUrl_ == "https://cdn.melown.com/mario/proxy//melown2015/tms/melown/mapycz-ophoto-cz/10-277-172.mask") { this.mapLoaderUrl_ = this.mapLoaderUrl_; } - - if (this.mapLoaderUrl_ == "https://cdn.melown.com/mario/proxy//melown2015/tms/melown/mapycz-ophoto-cz/10-274-176.mask") { +*/ +/* + if (this.mapLoaderUrl_ == "https://ecn.t3.tiles.virtualearth.net/tiles/a1202310323212333.jpeg?g=5549") { this.mapLoaderUrl_ = this.mapLoaderUrl_; } */ - if (this.neverReady_) { - return false; + if (this.mapLoaderUrl_ == "https://ecn.t1.tiles.virtualearth.net/tiles/a120231032333003.jpeg?g=5594" || + this.mapLoaderUrl_ == "https://ecn.t2.tiles.virtualearth.net/tiles/a120231032333003.jpeg?g=5594" || + this.mapLoaderUrl_ == "https://ecn.t3.tiles.virtualearth.net/tiles/a120231032333003.jpeg?g=5594" || + this.mapLoaderUrl_ == "https://ecn.t4.tiles.virtualearth.net/tiles/a120231032333003.jpeg?g=5594" || + this.mapLoaderUrl_ == "https://ecn.t5.tiles.virtualearth.net/tiles/a120231032333003.jpeg?g=5594") { + this.mapLoaderUrl_ = this.mapLoaderUrl_; } + + if (this.neverReady_) { + return false; + } if (this.extraBound_) { if (this.extraBound_.texture_) { - while (this.extraBound_.texture_.checkStatus_ == -1) { + while (this.extraBound_.texture_.extraBound_ || this.extraBound_.texture_.checkStatus_ == -1) { +// while (this.extraBound_.texture_.checkStatus_ == -1) { var parent_ = this.extraBound_.sourceTile_.parent_; if (parent_.id_[0] < this.extraBound_.layer_.lodRange_[0]) { this.neverReady_ = true; @@ -199,12 +156,12 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck } /* - if (!this.extraBound_ && this.extraInfo_ && !this.mask_) { + if (!this.extraBound_ && this.extraInfo_ && !this.maskTexture_) { var layer_ = this.extraInfo_.layer_; if (layer_ && layer_.maskUrl_ && this.checkType_ != "metatile") { var path_ = layer_.getMaskUrl(this.tile_.id_); - this.mask_ = this.tile_.resources_.getTexture(path_, null, null, null, this.tile_, this.internal_); + this.maskTexture_ = this.tile_.resources_.getTexture(path_, null, null, null, this.tile_, this.internal_); } }*/ @@ -230,8 +187,8 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck var texture_ = metaresources_.getTexture(path_, true, null, null, this.tile_, this.internal_); - if (this.mask_) { - if (this.mask_.isReady(doNotLoad_, priority_, doNotCheckGpu_)) { + if (this.maskTexture_) { + if (this.maskTexture_.isReady(doNotLoad_, priority_, doNotCheckGpu_, this)) { this.checkStatus_ = 2; } } else { @@ -244,7 +201,7 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck if (this.checkStatus_ == 2) { if (!(value_ & 64)) { //load mask var path_ = layer_.getMaskUrl(tile_.id_); - this.mask_ = tile_.resources_.getTexture(path_, null, null, null, this.tile_, this.internal_); + this.maskTexture_ = tile_.resources_.getTexture(path_, null, null, null, this.tile_, this.internal_); this.checkStatus_ = 0; tile_.resetDrawCommands_ = true; this.map_.markDirty(); @@ -269,8 +226,9 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck this.setBoundTexture(this.extraBound_.tile_.parent_, this.extraBound_.layer_); this.checkMask_ = true; } - - while (this.extraBound_.texture_.checkStatus_ == -1) { + + while (this.extraBound_.texture_.extraBound_ || this.extraBound_.texture_.checkStatus_ == -1) { + //while (this.extraBound_.texture_.checkStatus_ == -1) { var parent_ = this.extraBound_.sourceTile_.parent_; if (parent_.id_[0] < this.extraBound_.layer_.lodRange_[0]) { this.neverReady_ = true; @@ -286,413 +244,64 @@ Melown.MapTexture.prototype.isReady = function(doNotLoad_, priority_, doNotCheck return false; } - break; - - case "negative-type": - case "negative-code": - case "negative-size": - - if (this.checkStatus_ != 2) { - if (this.checkStatus_ == 0) { - this.scheduleHeadRequest(priority_, (this.checkType_ == "negative-size")); - } else if (this.checkStatus_ == 3) { //loadError - if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_ && - performance.now() > this.loadErrorTime_ + this.map_.config_.mapLoadErrorRetryTime_) { - this.scheduleHeadRequest(priority_, (this.checkType_ == "negative-size")); - } - } else if (this.checkStatus_ == -1) { - - if (this.extraInfo_) { - /* - if (this.extraInfo_.tile_.id_[0] == Melown.debugId_[0] && - this.extraInfo_.tile_.id_[1] == Melown.debugId_[1] && - this.extraInfo_.tile_.id_[2] == Melown.debugId_[2]) { - this.extraInfo_ = this.extraInfo_; - }*/ - - if (!this.extraBound_) { - this.extraBound_ = { tile_: this.extraInfo_.tile_, layer_: this.extraInfo_.layer_}; - this.setBoundTexture(this.extraBound_.tile_.parent_, this.extraBound_.layer_); - } - - while (this.extraBound_.texture_.checkStatus_ == -1) { - this.setBoundTexture(this.extraBound_.sourceTile_.parent_, this.extraBound_.layer_); - } - } - } - - return false; - } - break; } var maskState_ = true; - if (this.mask_) { - maskState_ = this.mask_.isReady(doNotLoad_, priority_, doNotCheckGpu_); - } - - if (this.loadState_ == 2) { //loaded - if (!doNotLoad_ && this.cacheItem_) { - this.map_.resourcesCache_.updateItem(this.cacheItem_); - } - - if (((this.heightMap_ && !this.imageData_) || (!this.heightMap_ && !this.gpuTexture_)) && - this.stats_.renderBuild_ > this.map_.config_.mapMaxProcessingTime_) { - //console.log("testure resource build overflow"); - this.map_.markDirty(); - return false; - } - - if (doNotCheckGpu_) { - if (this.heightMap_) { - if (!this.imageData_) { - var t = performance.now(); - this.buildHeightMap(); - this.stats_.renderBuild_ += performance.now() - t; - } - } - - return maskState_; - } - - if (this.heightMap_) { - if (!this.imageData_) { - var t = performance.now(); - this.buildHeightMap(); - this.stats_.renderBuild_ += performance.now() - t; - } - } else { - if (!this.gpuTexture_) { - if (this.map_.stats_.gpuRenderUsed_ >= this.map_.maxGpuUsed_) { - return false; - } - - if (doNotUseGpu_) { - return false; - } - - //if (this.stats_.graphsFluxTexture_ [0][0] > 2) { - // return false; - //} - - var t = performance.now(); - this.buildGpuTexture(); - this.stats_.renderBuild_ += performance.now() - t; - } - - if (!doNotLoad_ && this.gpuCacheItem_) { - this.map_.gpuCache_.updateItem(this.gpuCacheItem_); - } - } - - - return maskState_; - } else { - if (this.loadState_ == 0) { - if (doNotLoad_) { - //remove from queue - //if (this.mapLoaderUrl_) { - //this.map_.loader_.remove(this.mapLoaderUrl_); - //} - } else { - //not loaded - //add to loading queue or top position in queue - this.scheduleLoad(priority_); - } - } else if (this.loadState_ == 3) { //loadError - if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_ && - performance.now() > this.loadErrorTime_ + this.map_.config_.mapLoadErrorRetryTime_) { - - this.scheduleLoad(priority_); - } - } //else load in progress - } - - return false; -}; - -Melown.MapTexture.prototype.scheduleLoad = function(priority_, header_) { - this.map_.loader_.load(this.mapLoaderUrl_, this.onLoad.bind(this, header_), priority_, this.tile_, this.internal_ ? "texture-in" : "texture-ex"); -}; - -Melown.MapTexture.prototype.onLoad = function(header_, url_, onLoaded_, onError_) { - this.mapLoaderCallLoaded_ = onLoaded_; - this.mapLoaderCallError_ = onError_; - - var onerror_ = this.onLoadError.bind(this); - var onload_ = this.onLoaded.bind(this); - - if (header_) { - this.checkStatus_ = 1; - } else { - this.loadState_ = 1; - } - - if (this.map_.config_.mapXhrImageLoad_) { - Melown.loadBinary(url_, this.onBinaryLoaded.bind(this), onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); - } else { - this.image_ = Melown.Http.imageFactory(url_, onload_, onerror_, (this.map_.core_.tokenCookieHost_ ? (url_.indexOf(this.map_.core_.tokenCookieHost_) != -1) : false)); + if (this.maskTexture_) { + maskState_ = this.maskTexture_.isReady(doNotLoad_, priority_, doNotCheckGpu_, this); } - //mapXhrImageLoad_ -}; - -Melown.MapTexture.prototype.onLoadError = function(killBlob_) { - if (this.map_.killed_ == true){ - return; - } - - if (killBlob_) { - window.URL.revokeObjectURL(this.image_.src); - } - - this.loadState_ = 3; - this.loadErrorTime_ = performance.now(); - this.loadErrorCounter_ ++; - //make sure we try to load it again - if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_) { - setTimeout((function(){ if (!this.map_.killed_) { this.map_.markDirty(); } }).bind(this), this.map_.config_.mapLoadErrorRetryTime_); - } - - this.mapLoaderCallError_(); -}; - -Melown.MapTexture.prototype.onBinaryLoaded = function(data_) { - if (this.fastHeaderCheck_ && this.checkType_ && this.checkType_ != "metatile") { - this.onHeadLoaded(null, data_, null /*status_*/); - - if (this.checkStatus_ == -1) { - this.mapLoaderCallLoaded_(); - return; - } - } - - var image_ = new Image(); - image_.onerror = this.onLoadError.bind(this, true); - image_.onload = this.onLoaded.bind(this, true); - this.image_ = image_; - image_.src = window.URL.createObjectURL(data_); - this.fileSize_ = data_.size; -}; - -Melown.MapTexture.prototype.onLoaded = function(killBlob_) { - if (this.map_.killed_){ - return; - } - - if (killBlob_) { - window.URL.revokeObjectURL(this.image_.src); - } - - var size_ = this.image_.naturalWidth * this.image_.naturalHeight * (this.heightMap_ ? 3 : 3); - - if (!this.image_.complete_) { - size_ = size_; - } - - //console.log(size_); - - this.cacheItem_ = this.map_.resourcesCache_.insert(this.killImage.bind(this, true), size_); - - this.map_.markDirty(); - this.loadState_ = 2; - this.loadErrorTime_ = null; - this.loadErrorCounter_ = 0; - this.mapLoaderCallLoaded_(); -}; - -Melown.MapTexture.prototype.scheduleHeadRequest = function(priority_, downloadAll_) { - if (this.map_.config_.mapXhrImageLoad_ && this.fastHeaderCheck_) { - this.scheduleLoad(priority_, true); - } else { - this.map_.loader_.load(this.mapLoaderUrl_, this.onLoadHead.bind(this, downloadAll_), priority_, this.tile_, this.internal_, this.internal_ ? "texture-in" : "texture-ex"); - } -}; - -//Melown.onlyOneHead_ = false; - -Melown.MapTexture.prototype.onLoadHead = function(downloadAll_, url_, onLoaded_, onError_) { - this.mapLoaderCallLoaded_ = onLoaded_; - this.mapLoaderCallError_ = onError_; - - var onerror_ = this.onLoadHeadError.bind(this, downloadAll_); - var onload_ = this.onHeadLoaded.bind(this, downloadAll_); - - this.checkStatus_ = 1; -/* - if (!Melown.onlyOneHead_) { - Melown.onlyOneHead_ = true; - } else { - return; - } - - //url_ = "http://m2.mapserver.mapy.cz/ophoto0203-m/20-568396-351581"; -*/ - if (downloadAll_) { - Melown.loadBinary(url_, onload_, onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); - } else { - Melown.Http.headRequest(url_, onload_, onerror_, (Melown["useCredentials"] ? (this.mapLoaderUrl_.indexOf(this.map_.baseUrl_) != -1) : false), this.map_.core_.xhrParams_, "blob"); - } - -}; - -Melown.MapTexture.prototype.onLoadHeadError = function(downloadAll_) { - if (this.map_.killed_){ - return; - } - - this.checkStatus_ = 3; - this.loadErrorTime_ = performance.now(); - this.loadErrorCounter_ ++; - - //make sure we try to load it again - if (this.loadErrorCounter_ <= this.map_.config_.mapLoadErrorMaxRetryCount_) { - setTimeout((function(){ if (!this.map_.killed_) { this.map_.markDirty(); } }).bind(this), this.map_.config_.mapLoadErrorRetryTime_); - } - - this.mapLoaderCallError_(); -}; - -Melown.MapTexture.prototype.onHeadLoaded = function(downloadAll_, data_, status_) { - if (this.map_.killed_){ - return; - } - - this.checkStatus_ = 2; - this.loadErrorTime_ = null; - this.loadErrorCounter_ = 0; - - if (this.map_.config_.mapXhrImageLoad_ && this.fastHeaderCheck_) { - - switch (this.checkType_) { - case "negative-size": - if (data_) { - if (data_.size == this.checkValue_) { - this.checkStatus_ = -1; - } - } - break; - - case "negative-type": - if (data_) { - if (data_.type == this.checkValue_) { - this.checkStatus_ = -1; - } - } - break; - - case "negative-code": - if (status_) { - if (this.checkValue_.indexOf(status_) != -1) { - this.checkStatus_ = -1; - } - } - break; - } - - } else { - - switch (this.checkType_) { - case "negative-size": - if (data_) { - if (data_.byteLength == this.checkValue_) { - this.checkStatus_ = -1; - } - } - break; - - case "negative-type": - if (data_) { - if (!data_.indexOf) { - data_ = data_; - } - - if (data_.indexOf(this.checkValue_) != -1) { - this.checkStatus_ = -1; - } - } - break; - - case "negative-code": - if (status_) { - if (this.checkValue_.indexOf(status_) != -1) { - this.checkStatus_ = -1; - } - } - break; - } - - this.mapLoaderCallLoaded_(); - } -}; - - -Melown.MapTexture.prototype.buildGpuTexture = function () { - this.gpuTexture_ = new Melown.GpuTexture(this.map_.renderer_.gpu_, null, this.map_.core_); - this.gpuTexture_.createFromImage(this.image_, "linear", false); - this.stats_.gpuTextures_ += this.gpuTexture_.size_; - - this.stats_.graphsFluxTexture_[0][0]++; - this.stats_.graphsFluxTexture_[0][1] += this.gpuTexture_.size_; - - this.gpuCacheItem_ = this.map_.gpuCache_.insert(this.killGpuTexture.bind(this, true), this.gpuTexture_.size_); -}; - -Melown.MapTexture.prototype.buildHeightMap = function () { - var canvas_ = document.createElement("canvas"); - canvas_.width = this.image_.naturalWidth; - canvas_.height = this.image_.naturalHeight; - var ctx_ = canvas_.getContext("2d"); - ctx_.drawImage(this.image_, 0, 0); - this.imageData_ = ctx_.getImageData(0, 0, this.image_.naturalWidth, this.image_.naturalHeight).data; - this.imageExtents_ = [this.image_.naturalWidth, this.image_.naturalHeight]; - this.image_ = null; + return this.mainTexture_.isReady(doNotLoad_, priority_, doNotCheckGpu_, this) && maskState_; }; Melown.MapTexture.prototype.getGpuTexture = function() { if (this.extraBound_) { if (this.extraBound_.texture_) { - return this.extraBound_.texture_.gpuTexture_; + return this.extraBound_.texture_.getGpuTexture(); } return null; } - return this.gpuTexture_; + return this.mainTexture_.getGpuTexture(); }; Melown.MapTexture.prototype.getMaskTexture = function() { if (this.extraBound_) { if (this.extraBound_.texture_) { - return this.extraBound_.texture_.mask_; + return this.extraBound_.texture_.getMaskTexture(); } } - return this.mask_; + return this.maskTexture_; }; Melown.MapTexture.prototype.getGpuMaskTexture = function() { if (this.extraBound_) { if (this.extraBound_.texture_ && this.extraBound_.texture_.mask_) { - return this.extraBound_.texture_.mask_.gpuTexture_; + return this.extraBound_.texture_.getGpuMaskTexture(); } return null; } - if (this.mask_) { - return this.mask_.gpuTexture_; + if (this.maskTexture_) { + return this.maskTexture_.getGpuTexture(); } return null; }; +Melown.MapTexture.prototype.getImageData = function() { + return this.mainTexture_.imageData_; +}; + +Melown.MapTexture.prototype.getImageExtents = function() { + return this.mainTexture_.imageExtents_; +}; + Melown.MapTexture.prototype.getHeightMapValue = function(x, y) { - if (this.imageData_) { - return this.imageData_[(y * this.imageExtents_[0] + x)*4]; - } - - return 0; + return this.mainTexture_.getHeightMapValue(x, y); }; Melown.MapTexture.prototype.getTransform = function() { diff --git a/src/core/renderer/renderer.js b/src/core/renderer/renderer.js index 90ddc1f6..af6395fe 100755 --- a/src/core/renderer/renderer.js +++ b/src/core/renderer/renderer.js @@ -26,12 +26,6 @@ Melown.Renderer = function(core_, div_, onUpdate_, onResize_, config_) { this.onlyDepth_ = false; this.onlyLayers_ = false; this.onlyHitLayers_ = false; - this.hoverFeature_ = null; - this.hoverFeatureId_ = null; - this.lastHoverFeature_ = null; - this.lastHoverFeatureId_ = null; - this.hoverFeatureCounter_ = 0; - this.hoverFeatureList_ = []; this.renderCounter_ = 1; this.hitmapCounter_ = 0; this.geoHitmapCounter_ = 0; @@ -39,8 +33,6 @@ Melown.Renderer = function(core_, div_, onUpdate_, onResize_, config_) { this.onResizeCall_ = onResize_; this.math_ = Melown.Math; - this.clickEvent_ = null; - this.hoverEvent_ = null; this.touchSurfaceEvent_ = []; var rect_ = this.div_.getBoundingClientRect(); @@ -307,7 +299,8 @@ Melown.Renderer.prototype.hitTestGeoLayers = function(screenX_, screenY_, mode_) //conver screen coords to texture coords if (gl_.checkFramebufferStatus(gl_.FRAMEBUFFER) != gl_.FRAMEBUFFER_COMPLETE) { - return [null, false, []]; + //return [null, false, []]; + return [false, 0,0,0,0]; } var surfaceHit_ = false; @@ -333,76 +326,11 @@ Melown.Renderer.prototype.hitTestGeoLayers = function(screenX_, screenY_, mode_) } - if (surfaceHit_) { - //console.log(JSON.stringify([id_, JSON.stringify(this.hoverFeatureList_[id_])])); - - if (mode_ == "hover") { - this.lastHoverFeature_ = this.hoverFeature_; - this.lastHoverFeatureId_ = this.hoverFeatureId_; - this.hoverFeature_ = null; - this.hoverFeatureId_ = null; - - this.hoverFeature_ = this.hoverFeatureList_[id_]; - this.hoverFeatureId_ = (this.hoverFeature_ != null) ? this.hoverFeature_[0]["id"] : null; - - var relatedEvents_ = []; - - if (this.hoverFeatureId_ != this.lastHoverFeatureId_) { - - if (this.lastHoverFeatureId_ != null) { - relatedEvents_.push(["leave", this.lastHoverFeature_, this.lastHoverFeatureId_]); - } - - if (this.hoverFeatureId_ != null) { - relatedEvents_.push(["enter", this.hoverFeature_, this.hoverFeatureId_]); - } - - this.dirty_ = true; - } - - if (this.hoverFeature_ != null && this.hoverFeature_[3] == true) { - return [this.hoverFeature_, surfaceHit_, relatedEvents_]; - } else { - return [null, false, relatedEvents_]; - } - } - - if (mode_ == "click") { - - var feature_ = this.hoverFeatureList_[id_]; - //this.hoverFeatureId_ = (this.hoverFeature_ != null) ? this.hoverFeature_["id"] : null; - - if (feature_ != null && this.hoverFeature_ != null && this.hoverFeature_[2] == true) { - return [feature_, surfaceHit_, []]; - } else { - return [null, false, []]; - } - - } - } else { - - var relatedEvents_ = []; - - if (mode_ == "hover") { - this.lastHoverFeature_ = this.hoverFeature_; - this.lastHoverFeatureId_ = this.hoverFeatureId_; - this.hoverFeature_ = null; - this.hoverFeatureId_ = null; - - if (this.lastHoverFeatureId_ != null) { - - if (this.lastHoverFeatureId_ != null) { - relatedEvents_.push(["leave", this.lastHoverFeature_, this.lastHoverFeatureId_]); - } - - this.dirty_ = true; - } - } - - return [null, false, relatedEvents_]; - } + return [true, pixel_[0], pixel_[1], pixel_[2], pixel_[3]]; + } + return [false, 0,0,0,0]; }; Melown.Renderer.prototype.switchToFramebuffer = function(type_) { @@ -423,6 +351,7 @@ Melown.Renderer.prototype.switchToFramebuffer = function(type_) { this.camera_.update(); //this.updateCamera(); this.onlyDepth_ = false; + this.onlyHitLayers_ = false; break; case "depth": @@ -443,17 +372,45 @@ Melown.Renderer.prototype.switchToFramebuffer = function(type_) { this.curSize_ = [size_, size_]; //this.gpu_.resize(this.curSize_, true); - var width_ = this.oldSize_[0]; - var height_ = this.oldSize_[1]; + //var width_ = this.oldSize_[0]; + //var height_ = this.oldSize_[1]; //this.camera_.setAspect(width_ / height_); this.gpu_.clear(); //this.camera_.setAspect(2.5); this.camera_.update(); this.onlyDepth_ = true; + this.onlyHitLayers_ = false; break; case "geo": + + this.hoverFeatureCounter_ = 0; + + var size_ = this.hitmapSize_; + + //set texture framebuffer + this.gpu_.setFramebuffer(this.geoHitmapTexture_); + + var oldSize_ = [ this.curSize_[0], this.curSize_[1] ]; + + var width_ = size_; + var height_ = size_; + + gl_.clearColor(1.0,1.0, 1.0, 1.0); + gl_.enable(gl_.DEPTH_TEST); + + //clear screen + gl_.viewport(0, 0, size_, size_); + gl_.clear(gl_.COLOR_BUFFER_BIT | gl_.DEPTH_BUFFER_BIT); + + this.curSize_ = [width_, height_]; + + //render scene + this.onlyHitLayers_ = true; + + this.gpu_.clear(); + this.updateCamera(); break; } }; @@ -499,103 +456,6 @@ Melown.Renderer.prototype.hitTest = function(screenX_, screenY_) { return [this.lastHitPosition_[0], this.lastHitPosition_[1], this.lastHitPosition_[2], surfaceHit_, screenRay_, depth_, cameraPos_]; }; -Melown.Renderer.prototype.hitTestOld = function(screenX_, screenY_, mode_) { - //this.core_.hover(screenX_, screenY_, false, { test:true}); - //return [0,0,0,false]; - - this.updateHitmap_ = true; - - var gl_ = this.gpu_.gl_; - - if (this.updateHitmap_ == true) { - - var size_ = this.hitmapSize_; - - //set texture framebuffer - this.gpu_.setFramebuffer(this.hitmapTexture_); - - var oldSize_ = [ this.curSize_[0], this.curSize_[1] ]; - - var width_ = size_; - var height_ = size_; - - gl_.clearColor(1.0,1.0, 1.0, 1.0); - //gl_.clearColor(0.0, 0.0, 0.0, 1.0); - gl_.enable(gl_.DEPTH_TEST); - - //clear screen - gl_.viewport(0, 0, size_, size_); - gl_.clear(gl_.COLOR_BUFFER_BIT | gl_.DEPTH_BUFFER_BIT); - - this.curSize_ = [width_, height_]; - - //gl_.viewport(0, 0, width_, height_); - //render scene - this.onlyDepth_ = true; - //this.paintGL(); - - this.gpu_.clear(); - - this.camera_.update(); - //maxPixelSize_ = this.planet_.draw(); - this.drawTiles(this.planet_); - - this.onlyDepth_ = false; - - //return screen framebuffer - width_ = oldSize_[0]; - height_ = oldSize_[1]; - - gl_.clearColor(0.0, 0.0, 0.0, 1.0); - - this.gpu_.setFramebuffer(null); - - this.camera_.setAspect(width_ / height_); - this.curSize_ = [width_, height_]; - this.gpu_.resize(this.curSize_, true); - this.camera_.update(); - this.updateCamera(); - - this.updateHitmap_ = false; - } - - //conver screen coords to texture coords - if (gl_.checkFramebufferStatus(gl_.FRAMEBUFFER) != gl_.FRAMEBUFFER_COMPLETE) { - return [0,0,0,0]; - } - - var x_ = 0, y_ = 0; - - //get screen coords - //if (this.curSize_[0] > this.curSize_[1]) { - x_ = Math.floor(screenX_ * (this.hitmapSize_ / this.curSize_[0])); - y_ = Math.floor(screenY_ * (this.hitmapSize_ / this.curSize_[1])); - - //console.log("hit screen: " + x_ + " " + y_); - - //get pixel value from framebuffer - var pixel_ = this.hitmapTexture_.readFramebufferPixels(x_, this.hitmapSize_ - y_ - 1, 1, 1); - - //convert rgb values into depth - var depth_ = (pixel_[0] * (1.0/255)) + (pixel_[1]) + (pixel_[2]*255.0) + (pixel_[3]*65025.0);// + (pixel_[3]*16581375.0); - - var surfaceHit_ = !(pixel_[0] == 255 && pixel_[1] == 255 && pixel_[2] == 255 && pixel_[3] == 255); - - //get screen ray - var screenRay_ = this.getScreenRay(screenX_, screenY_); - var cameraPos_ = this.cameraPosition(); - - //compute hit postion - this.lastHitPosition_ = [cameraPos_[0] + screenRay_[0]*depth_, cameraPos_[1] + screenRay_[1]*depth_, cameraPos_[2] + screenRay_[2]*depth_]; - - - //this.hitTestGeoLayers(screenX_, screenY_, "hover"); - this.core_.hover(screenX_, screenY_, false, { test:true}); - //this.core_.click(screenX_, screenY_, { test2:true}); - - - return [this.lastHitPosition_[0], this.lastHitPosition_[1], this.lastHitPosition_[2], surfaceHit_]; -}; Melown.Renderer.prototype.getZoffsetFactor = function(params_) { //var offsetFactor_ = 1.0 + this.distanceFactor_*params_[1]*((1-params_[2])+params_[2]*this.tiltFactor_); diff --git a/src/core/utils/libs/proj4-src.js b/src/core/utils/libs/proj4-src.js index e0aebaa1..f95b62d4 100755 --- a/src/core/utils/libs/proj4-src.js +++ b/src/core/utils/libs/proj4-src.js @@ -1,5519 +1,6321 @@ -!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._mproj4_=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 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 _mproj4_(fromProj, toProj, coord, onlyProj_) { - fromProj = checkProj(fromProj); - - if (onlyProj_) { - return 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); - }, - info: function() { - return { - "a" : toProj.a, - "b" : toProj.b, - "ra" : toProj.R_A, - "proj-name" : toProj.projName - }; - } - }; - if (single) { - obj.oProj = toProj; - } - return obj; - } -} -module.exports = _mproj4_; -},{"./Proj":2,"./transform":66}],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":67}],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('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 _mproj4_ = _dereq_('./core'); -_mproj4_.defaultDatum = 'WGS84'; //default datum -_mproj4_.Proj = _dereq_('./Proj'); -_mproj4_.WGS84 = new _mproj4_.Proj('WGS84'); -_mproj4_.Point = _dereq_('./Point'); -_mproj4_.toPoint = _dereq_("./common/toPoint"); -_mproj4_.defs = _dereq_('./defs'); -_mproj4_.transform = _dereq_('./transform'); -_mproj4_.mgrs = _dereq_('mgrs'); -_mproj4_.version = _dereq_('../package.json').version; -_dereq_('./includedProjections')(_mproj4_); -module.exports = _mproj4_; -},{"../package.json":69,"./Point":1,"./Proj":2,"./common/toPoint":23,"./core":29,"./defs":32,"./includedProjections":"Pk/iAZ","./transform":66,"mgrs":68}],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":67}],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":52,"./projections/merc":53}],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){ -exports.init = function() { - this.isGeocent = true; -}; - -function identity(pt) { - return pt; -} -exports.forward = identity; -exports.inverse = identity; -exports.names = ["geocent"];//, "identity"]; - -},{}],48:[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}],49:[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}],50:[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}],51:[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}],52:[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"]; - -},{}],53:[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}],54:[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}],55:[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}],56:[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"]; -},{}],57:[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}],58:[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}],59:[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}],60:[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"]; - -},{}],61:[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}],62:[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}],63:[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}],64:[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":63}],65:[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}],66:[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.isGeocent) { - if (source.to_meter) { - point.x *= source.to_meter; - point.y *= source.to_meter; - point.z *= source.to_meter; - } - dest.datum.geocentric_to_geodetic_noniter(point); - //dest.datum.geocentric_to_geodetic(point); - } 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 - if (dest.isGeocent) { - dest.datum.geodetic_to_geocentric(point); - if (dest.to_meter) { - point.x /= dest.to_meter; - point.y /= dest.to_meter; - point.z /= dest.to_meter; - } - } else { - 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}],67:[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}],68:[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); - } - -} - -},{}],69:[function(_dereq_,module,exports){ -module.exports={ - "name": "_mproj4_", - "version": "2.3.7-alpha", - "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/_mproj4_js/_mproj4_js.git" - }, - "author": "", - "license": "MIT", - "jam": { - "main": "dist/_mproj4_.js", - "include": [ - "dist/_mproj4_.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_('Pk/iAZ'); -},{}],"Pk/iAZ":[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'), - _dereq_('./lib/projections/geocent') -]; -module.exports = function(_mproj4_){ - projs.forEach(function(proj){ - _mproj4_.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/geocent":47,"./lib/projections/gnom":48,"./lib/projections/krovak":49,"./lib/projections/laea":50,"./lib/projections/lcc":51,"./lib/projections/mill":54,"./lib/projections/moll":55,"./lib/projections/nzmg":56,"./lib/projections/omerc":57,"./lib/projections/poly":58,"./lib/projections/sinu":59,"./lib/projections/somerc":60,"./lib/projections/stere":61,"./lib/projections/sterea":62,"./lib/projections/tmerc":63,"./lib/projections/utm":64,"./lib/projections/vandg":65}]},{},[36]) -(36) -}); \ No newline at end of file +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global._mproj4_ = factory()); +}(this, (function () { 'use strict'; + + var globals = 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('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']; + }; + + var PJD_3PARAM = 1; + var PJD_7PARAM = 2; + var PJD_WGS84 = 4; // WGS84 or equivalent + var PJD_NODATUM = 5; // WGS84 or equivalent + var SEC_TO_RAD = 4.84813681109535993589914102357e-6; + var HALF_PI = Math.PI/2; + // ellipoid pj_set_ell.c + var SIXTH = 0.1666666666666666667; + /* 1/6 */ + var RA4 = 0.04722222222222222222; + /* 17/360 */ + var RA6 = 0.02215608465608465608; + var EPSLN = (typeof Number.EPSILON === 'undefined') ? 1.0e-10 : Number.EPSILON; + var D2R = 0.01745329251994329577; + var R2D = 57.29577951308232088; + var FORTPI = Math.PI/4; + 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 exports$1 = {}; + exports$1.greenwich = 0.0; //"0dE", + exports$1.lisbon = -9.131906111111; //"9d07'54.862\"W", + exports$1.paris = 2.337229166667; //"2d20'14.025\"E", + exports$1.bogota = -74.080916666667; //"74d04'51.3\"W", + exports$1.madrid = -3.687938888889; //"3d41'16.58\"W", + exports$1.rome = 12.452333333333; //"12d27'8.4\"E", + exports$1.bern = 7.439583333333; //"7d26'22.5\"E", + exports$1.jakarta = 106.807719444444; //"106d48'27.79\"E", + exports$1.ferro = -17.666666666667; //"17d40'W", + exports$1.brussels = 4.367975; //"4d22'4.71\"E", + exports$1.stockholm = 18.058277777778; //"18d3'29.8\"E", + exports$1.athens = 23.7163375; //"23d42'58.815\"E", + exports$1.oslo = 10.722916666667; //"10d43'22.5\"E" + + var units = { + ft: {to_meter: 0.3048}, + 'us-ft': {to_meter: 1200 / 3937} + }; + + var ignoredChar = /[\s_\-\/\(\)]/g; + function match(obj, key) { + if (obj[key]) { + return obj[key]; + } + var keys = Object.keys(obj); + var lkey = key.toLowerCase().replace(ignoredChar, ''); + var i = -1; + var testkey, processedKey; + while (++i < keys.length) { + testkey = keys[i]; + processedKey = testkey.toLowerCase().replace(ignoredChar, ''); + if (processedKey === lkey) { + return obj[testkey]; + } + } + } + + var parseProj = function(defData) { + var self = {}; + var paramObj = defData.split('+').map(function(v) { + return v.trim(); + }).filter(function(a) { + return a; + }).reduce(function(p, a) { + var split = a.split('='); + split.push(true); + p[split[0].toLowerCase()] = split[1]; + return p; + }, {}); + 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; + var unit = match(units, v); + if (unit) { + self.to_meter = unit.to_meter; + } + }, + from_greenwich: function(v) { + self.from_greenwich = v * D2R; + }, + pm: function(v) { + var pm = match(exports$1, v); + self.from_greenwich = (pm ? pm : 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; + }; + + var NEUTRAL = 1; + var KEYWORD = 2; + var NUMBER = 3; + var QUOTED = 4; + var AFTERQUOTE = 5; + var ENDED = -1; + var whitespace = /\s/; + var latin = /[A-Za-z]/; + var keyword = /[A-Za-z84]/; + var endThings = /[,\]]/; + var digets = /[\d\.E\-\+]/; + // const ignoredChar = /[\s_\-\/\(\)]/g; + function Parser(text) { + if (typeof text !== 'string') { + throw new Error('not a string'); + } + this.text = text.trim(); + this.level = 0; + this.place = 0; + this.root = null; + this.stack = []; + this.currentObject = null; + this.state = NEUTRAL; + } + Parser.prototype.readCharicter = function() { + var char = this.text[this.place++]; + if (this.state !== QUOTED) { + while (whitespace.test(char)) { + if (this.place >= this.text.length) { + return; + } + char = this.text[this.place++]; + } + } + switch (this.state) { + case NEUTRAL: + return this.neutral(char); + case KEYWORD: + return this.keyword(char) + case QUOTED: + return this.quoted(char); + case AFTERQUOTE: + return this.afterquote(char); + case NUMBER: + return this.number(char); + case ENDED: + return; + } + }; + Parser.prototype.afterquote = function(char) { + if (char === '"') { + this.word += '"'; + this.state = QUOTED; + return; + } + if (endThings.test(char)) { + this.word = this.word.trim(); + this.afterItem(char); + return; + } + throw new Error('havn\'t handled "' +char + '" in afterquote yet, index ' + this.place); + }; + Parser.prototype.afterItem = function(char) { + if (char === ',') { + if (this.word !== null) { + this.currentObject.push(this.word); + } + this.word = null; + this.state = NEUTRAL; + return; + } + if (char === ']') { + this.level--; + if (this.word !== null) { + this.currentObject.push(this.word); + this.word = null; + } + this.state = NEUTRAL; + this.currentObject = this.stack.pop(); + if (!this.currentObject) { + this.state = ENDED; + } + + return; + } + }; + Parser.prototype.number = function(char) { + if (digets.test(char)) { + this.word += char; + return; + } + if (endThings.test(char)) { + this.word = parseFloat(this.word); + this.afterItem(char); + return; + } + throw new Error('havn\'t handled "' +char + '" in number yet, index ' + this.place); + }; + Parser.prototype.quoted = function(char) { + if (char === '"') { + this.state = AFTERQUOTE; + return; + } + this.word += char; + return; + }; + Parser.prototype.keyword = function(char) { + if (keyword.test(char)) { + this.word += char; + return; + } + if (char === '[') { + var newObjects = []; + newObjects.push(this.word); + this.level++; + if (this.root === null) { + this.root = newObjects; + } else { + this.currentObject.push(newObjects); + } + this.stack.push(this.currentObject); + this.currentObject = newObjects; + this.state = NEUTRAL; + return; + } + if (endThings.test(char)) { + this.afterItem(char); + return; + } + throw new Error('havn\'t handled "' +char + '" in keyword yet, index ' + this.place); + }; + Parser.prototype.neutral = function(char) { + if (latin.test(char)) { + this.word = char; + this.state = KEYWORD; + return; + } + if (char === '"') { + this.word = ''; + this.state = QUOTED; + return; + } + if (digets.test(char)) { + this.word = char; + this.state = NUMBER; + return; + } + if (endThings.test(char)) { + this.afterItem(char); + return; + } + throw new Error('havn\'t handled "' +char + '" in neutral yet, index ' + this.place); + }; + Parser.prototype.output = function() { + while (this.place < this.text.length) { + this.readCharicter(); + } + if (this.state === ENDED) { + return this.root; + } + throw new Error('unable to parse string "' +this.text + '". State is ' + this.state); + }; + + function parseString(txt) { + var parser = new Parser(txt); + return parser.output(); + } + + function mapit(obj, key, value) { + if (Array.isArray(key)) { + value.unshift(key); + key = null; + } + var thing = key ? {} : obj; + + var out = value.reduce(function(newObj, item) { + sExpr(item, newObj); + return newObj + }, thing); + if (key) { + obj[key] = out; + } + } + + function sExpr(v, obj) { + if (!Array.isArray(v)) { + obj[v] = true; + return; + } + var 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]); + return; + } + obj[key] = v[0]; + return; + } + if (!v.length) { + obj[key] = true; + return; + } + if (key === 'TOWGS84') { + obj[key] = v; + return; + } + if (!Array.isArray(key)) { + obj[key] = {}; + } + + var i; + switch (key) { + case 'UNIT': + case 'PRIMEM': + case 'VERT_DATUM': + obj[key] = { + name: v[0].toLowerCase(), + convert: v[1] + }; + if (v.length === 3) { + sExpr(v[2], obj[key]); + } + return; + case 'SPHEROID': + case 'ELLIPSOID': + obj[key] = { + name: v[0], + a: v[1], + rf: v[2] + }; + if (v.length === 4) { + sExpr(v[3], obj[key]); + } + return; + case 'PROJECTEDCRS': + case 'PROJCRS': + case 'GEOGCS': + case 'GEOCCS': + case 'PROJCS': + case 'LOCAL_CS': + case 'GEODCRS': + case 'GEODETICCRS': + case 'GEODETICDATUM': + case 'EDATUM': + case 'ENGINEERINGDATUM': + case 'VERT_CS': + case 'VERTCRS': + case 'VERTICALCRS': + case 'COMPD_CS': + case 'COMPOUNDCRS': + case 'ENGINEERINGCRS': + case 'ENGCRS': + case 'FITTED_CS': + case 'LOCAL_DATUM': + case 'DATUM': + v[0] = ['name', v[0]]; + mapit(obj, key, v); + return; + default: + i = -1; + while (++i < v.length) { + if (!Array.isArray(v[i])) { + return sExpr(v, obj[key]); + } + } + return mapit(obj, key, v); + } + } + + var D2R$1 = 0.01745329251994329577; + 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$1; + } + + 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) { + if (wkt.type === 'GEOGCS') { + if (wkt.DATUM && wkt.DATUM.SPHEROID) { + wkt.to_meter = wkt.UNIT.convert*wkt.DATUM.SPHEROID.a; + } + } else { + wkt.to_meter = wkt.UNIT.convert, 10; + } + } + } + var geogcs = wkt.GEOGCS; + if (wkt.type === 'GEOGCS') { + geogcs = wkt; + } + if (geogcs) { + //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){ + // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R; + //} + if (geogcs.DATUM) { + wkt.datumCode = geogcs.DATUM.name.toLowerCase(); + } else { + wkt.datumCode = 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 (geogcs.DATUM && geogcs.DATUM.SPHEROID) { + wkt.ellps = geogcs.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk'); + if (wkt.ellps.toLowerCase().slice(0, 13) === 'international') { + wkt.ellps = 'intl'; + } + + wkt.a = geogcs.DATUM.SPHEROID.a; + wkt.rf = parseFloat(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 input * 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; + } + } + var wkt = function(wkt) { + var lisp = parseString(wkt); + var type = lisp.shift(); + var name = lisp.shift(); + lisp.unshift(['name', name]); + lisp.unshift(['type', type]); + var obj = {}; + sExpr(lisp, obj); + cleanWKT(obj); + return obj; + }; + + 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); + + function testObj(code){ + return typeof code === 'string'; + } + function testDef(code){ + return code in defs; + } + var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS']; + function testWKT(code){ + return codeWords.some(function (word) { + return code.indexOf(word) > -1; + }); + } + 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]; + } + if (testWKT(code)) { + return wkt(code); + } + if (testProj(code)) { + return parseProj(code); + } + }else{ + return code; + } + } + + var extend = 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; + }; + + var msfnz = function(eccent, sinphi, cosphi) { + var con = eccent * sinphi; + return cosphi / (Math.sqrt(1 - con * con)); + }; + + var sign = function(x) { + return x<0 ? -1 : 1; + }; + + var adjust_lon = function(x) { + return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI)); + }; + + var tsfnz = 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); + }; + + var phi2z = 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; + }; + + function init() { + 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 + --------------------------------------------------*/ + + function forward(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 + --------------------------------------------------*/ + function inverse(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; + } + + var names$1 = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"]; + var merc = { + init: init, + forward: forward, + inverse: inverse, + names: names$1 + }; + + function init$1() { + //no-op for longlat + } + + function identity(pt) { + return pt; + } + var names$2 = ["longlat", "identity"]; + var longlat = { + init: init$1, + forward: identity, + inverse: identity, + names: names$2 + }; + + var projs = [merc, longlat]; + var names$$1 = {}; + 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$$1[n.toLowerCase()] = len; + }); + return this; + } + + function get(name) { + if (!name) { + return false; + } + var n = name.toLowerCase(); + if (typeof names$$1[n] !== 'undefined' && projStore[names$$1[n]]) { + return projStore[names$$1[n]]; + } + } + + function start() { + projs.forEach(add); + } + var projections = { + start: start, + add: add, + get: get + }; + + var exports$2 = {}; + exports$2.MERIT = { + a: 6378137.0, + rf: 298.257, + ellipseName: "MERIT 1983" + }; + + exports$2.SGS85 = { + a: 6378136.0, + rf: 298.257, + ellipseName: "Soviet Geodetic System 85" + }; + + exports$2.GRS80 = { + a: 6378137.0, + rf: 298.257222101, + ellipseName: "GRS 1980(IUGG, 1980)" + }; + + exports$2.IAU76 = { + a: 6378140.0, + rf: 298.257, + ellipseName: "IAU 1976" + }; + + exports$2.airy = { + a: 6377563.396, + b: 6356256.910, + ellipseName: "Airy 1830" + }; + + exports$2.APL4 = { + a: 6378137, + rf: 298.25, + ellipseName: "Appl. Physics. 1965" + }; + + exports$2.NWL9D = { + a: 6378145.0, + rf: 298.25, + ellipseName: "Naval Weapons Lab., 1965" + }; + + exports$2.mod_airy = { + a: 6377340.189, + b: 6356034.446, + ellipseName: "Modified Airy" + }; + + exports$2.andrae = { + a: 6377104.43, + rf: 300.0, + ellipseName: "Andrae 1876 (Den., Iclnd.)" + }; + + exports$2.aust_SA = { + a: 6378160.0, + rf: 298.25, + ellipseName: "Australian Natl & S. Amer. 1969" + }; + + exports$2.GRS67 = { + a: 6378160.0, + rf: 298.2471674270, + ellipseName: "GRS 67(IUGG 1967)" + }; + + exports$2.bessel = { + a: 6377397.155, + rf: 299.1528128, + ellipseName: "Bessel 1841" + }; + + exports$2.bess_nam = { + a: 6377483.865, + rf: 299.1528128, + ellipseName: "Bessel 1841 (Namibia)" + }; + + exports$2.clrk66 = { + a: 6378206.4, + b: 6356583.8, + ellipseName: "Clarke 1866" + }; + + exports$2.clrk80 = { + a: 6378249.145, + rf: 293.4663, + ellipseName: "Clarke 1880 mod." + }; + + exports$2.clrk58 = { + a: 6378293.645208759, + rf: 294.2606763692654, + ellipseName: "Clarke 1858" + }; + + exports$2.CPM = { + a: 6375738.7, + rf: 334.29, + ellipseName: "Comm. des Poids et Mesures 1799" + }; + + exports$2.delmbr = { + a: 6376428.0, + rf: 311.5, + ellipseName: "Delambre 1810 (Belgium)" + }; + + exports$2.engelis = { + a: 6378136.05, + rf: 298.2566, + ellipseName: "Engelis 1985" + }; + + exports$2.evrst30 = { + a: 6377276.345, + rf: 300.8017, + ellipseName: "Everest 1830" + }; + + exports$2.evrst48 = { + a: 6377304.063, + rf: 300.8017, + ellipseName: "Everest 1948" + }; + + exports$2.evrst56 = { + a: 6377301.243, + rf: 300.8017, + ellipseName: "Everest 1956" + }; + + exports$2.evrst69 = { + a: 6377295.664, + rf: 300.8017, + ellipseName: "Everest 1969" + }; + + exports$2.evrstSS = { + a: 6377298.556, + rf: 300.8017, + ellipseName: "Everest (Sabah & Sarawak)" + }; + + exports$2.fschr60 = { + a: 6378166.0, + rf: 298.3, + ellipseName: "Fischer (Mercury Datum) 1960" + }; + + exports$2.fschr60m = { + a: 6378155.0, + rf: 298.3, + ellipseName: "Fischer 1960" + }; + + exports$2.fschr68 = { + a: 6378150.0, + rf: 298.3, + ellipseName: "Fischer 1968" + }; + + exports$2.helmert = { + a: 6378200.0, + rf: 298.3, + ellipseName: "Helmert 1906" + }; + + exports$2.hough = { + a: 6378270.0, + rf: 297.0, + ellipseName: "Hough" + }; + + exports$2.intl = { + a: 6378388.0, + rf: 297.0, + ellipseName: "International 1909 (Hayford)" + }; + + exports$2.kaula = { + a: 6378163.0, + rf: 298.24, + ellipseName: "Kaula 1961" + }; + + exports$2.lerch = { + a: 6378139.0, + rf: 298.257, + ellipseName: "Lerch 1979" + }; + + exports$2.mprts = { + a: 6397300.0, + rf: 191.0, + ellipseName: "Maupertius 1738" + }; + + exports$2.new_intl = { + a: 6378157.5, + b: 6356772.2, + ellipseName: "New International 1967" + }; + + exports$2.plessis = { + a: 6376523.0, + rf: 6355863.0, + ellipseName: "Plessis 1817 (France)" + }; + + exports$2.krass = { + a: 6378245.0, + rf: 298.3, + ellipseName: "Krassovsky, 1942" + }; + + exports$2.SEasia = { + a: 6378155.0, + b: 6356773.3205, + ellipseName: "Southeast Asia" + }; + + exports$2.walbeck = { + a: 6376896.0, + b: 6355834.8467, + ellipseName: "Walbeck" + }; + + exports$2.WGS60 = { + a: 6378165.0, + rf: 298.3, + ellipseName: "WGS 60" + }; + + exports$2.WGS66 = { + a: 6378145.0, + rf: 298.25, + ellipseName: "WGS 66" + }; + + exports$2.WGS7 = { + a: 6378135.0, + rf: 298.26, + ellipseName: "WGS 72" + }; + + var WGS84 = exports$2.WGS84 = { + a: 6378137.0, + rf: 298.257223563, + ellipseName: "WGS 84" + }; + + exports$2.sphere = { + a: 6370997.0, + b: 6370997.0, + ellipseName: "Normal Sphere (r=6370997)" + }; + + function eccentricity(a, b, rf, R_A) { + var a2 = a * a; // used in geocentric + var b2 = b * b; // used in geocentric + var es = (a2 - b2) / a2; // e ^ 2 + var e = 0; + if (R_A) { + a *= 1 - es * (SIXTH + es * (RA4 + es * RA6)); + a2 = a * a; + es = 0; + } else { + e = Math.sqrt(es); // eccentricity + } + var ep2 = (a2 - b2) / b2; // used in geocentric + return { + es: es, + e: e, + ep2: ep2 + }; + } + function sphere(a, b, rf, ellps, sphere) { + if (!a) { // do we have an ellipsoid? + var ellipse = match(exports$2, ellps); + if (!ellipse) { + ellipse = WGS84; + } + a = ellipse.a; + b = ellipse.b; + rf = ellipse.rf; + } + + if (rf && !b) { + b = (1.0 - 1.0 / rf) * a; + } + if (rf === 0 || Math.abs(a - b) < EPSLN) { + sphere = true; + b = a; + } + return { + a: a, + b: b, + rf: rf, + sphere: sphere + }; + } + + var exports$3 = {}; + exports$3.wgs84 = { + towgs84: "0,0,0", + ellipse: "WGS84", + datumName: "WGS84" + }; + + exports$3.ch1903 = { + towgs84: "674.374,15.056,405.346", + ellipse: "bessel", + datumName: "swiss" + }; + + exports$3.ggrs87 = { + towgs84: "-199.87,74.79,246.62", + ellipse: "GRS80", + datumName: "Greek_Geodetic_Reference_System_1987" + }; + + exports$3.nad83 = { + towgs84: "0,0,0", + ellipse: "GRS80", + datumName: "North_American_Datum_1983" + }; + + exports$3.nad27 = { + nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", + ellipse: "clrk66", + datumName: "North_American_Datum_1927" + }; + + exports$3.potsdam = { + towgs84: "606.0,23.0,413.0", + ellipse: "bessel", + datumName: "Potsdam Rauenberg 1950 DHDN" + }; + + exports$3.carthage = { + towgs84: "-263.0,6.0,431.0", + ellipse: "clark80", + datumName: "Carthage 1934 Tunisia" + }; + + exports$3.hermannskogel = { + towgs84: "653.0,-212.0,449.0", + ellipse: "bessel", + datumName: "Hermannskogel" + }; + + exports$3.ire65 = { + towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", + ellipse: "mod_airy", + datumName: "Ireland 1965" + }; + + exports$3.rassadiran = { + towgs84: "-133.63,-157.5,-158.62", + ellipse: "intl", + datumName: "Rassadiran" + }; + + exports$3.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$3.osgb36 = { + towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", + ellipse: "airy", + datumName: "Airy 1830" + }; + + exports$3.s_jtsk = { + towgs84: "589,76,480", + ellipse: 'bessel', + datumName: 'S-JTSK (Ferro)' + }; + + exports$3.beduaram = { + towgs84: '-106,-87,188', + ellipse: 'clrk80', + datumName: 'Beduaram' + }; + + exports$3.gunung_segara = { + towgs84: '-403,684,41', + ellipse: 'bessel', + datumName: 'Gunung Segara Jakarta' + }; + + exports$3.rnb72 = { + towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1", + ellipse: "intl", + datumName: "Reseau National Belge 1972" + }; + + function datum(datumCode, datum_params, a, b, es, ep2) { + var out = {}; + + if (datumCode === undefined || datumCode === 'none') { + out.datum_type = PJD_NODATUM; + } else { + out.datum_type = PJD_WGS84; + } + + if (datum_params) { + out.datum_params = datum_params.map(parseFloat); + if (out.datum_params[0] !== 0 || out.datum_params[1] !== 0 || out.datum_params[2] !== 0) { + out.datum_type = PJD_3PARAM; + } + if (out.datum_params.length > 3) { + if (out.datum_params[3] !== 0 || out.datum_params[4] !== 0 || out.datum_params[5] !== 0 || out.datum_params[6] !== 0) { + out.datum_type = PJD_7PARAM; + out.datum_params[3] *= SEC_TO_RAD; + out.datum_params[4] *= SEC_TO_RAD; + out.datum_params[5] *= SEC_TO_RAD; + out.datum_params[6] = (out.datum_params[6] / 1000000.0) + 1.0; + } + } + } + + out.a = a; //datum object also uses these values + out.b = b; + out.es = es; + out.ep2 = ep2; + return out; + } + + function Projection$1(srsCode,callback) { + if (!(this instanceof Projection$1)) { + return new Projection$1(srsCode); + } + callback = callback || function(error){ + if(error){ + throw error; + } + }; + var json = parse(srsCode); + if(typeof json !== 'object'){ + callback(srsCode); + return; + } + var ourProj = Projection$1.projections.get(json.projName); + if(!ourProj){ + callback(srsCode); + return; + } + if (json.datumCode && json.datumCode !== 'none') { + var datumDef = match(exports$3, 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; + } + } + json.k0 = json.k0 || 1.0; + json.axis = json.axis || 'enu'; + json.ellps = json.ellps || 'wgs84'; + var sphere_ = sphere(json.a, json.b, json.rf, json.ellps, json.sphere); + var ecc = eccentricity(sphere_.a, sphere_.b, sphere_.rf, json.R_A); + var datumObj = json.datum || datum(json.datumCode, json.datum_params, sphere_.a, sphere_.b, ecc.es, ecc.ep2); + + extend(this, json); // transfer everything over from the projection because we don't know what we'll need + extend(this, ourProj); // transfer all the methods from the projection + + // copy the 4 things over we calulated in deriveConstants.sphere + this.a = sphere_.a; + this.b = sphere_.b; + this.rf = sphere_.rf; + this.sphere = sphere_.sphere; + + // copy the 3 things we calculated in deriveConstants.eccentricity + this.es = ecc.es; + this.e = ecc.e; + this.ep2 = ecc.ep2; + + // add in the datum object + this.datum = datumObj; + + // init the projection + this.init(); + + // legecy callback from back in the day when it went to spatialreference.org + callback(null, this); + + } + Projection$1.projections = projections; + Projection$1.projections.start(); + + function compareDatums(source, dest) { + if (source.datum_type !== dest.datum_type) { + return false; // false, datums are not equal + } else if (source.a !== dest.a || Math.abs(source.es - dest.es) > 0.000000000050) { + // the tolerance for es is to ensure that GRS80 and WGS84 + // are considered identical + return false; + } else if (source.datum_type === PJD_3PARAM) { + return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]); + } else if (source.datum_type === PJD_7PARAM) { + return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2] && source.datum_params[3] === dest.datum_params[3] && source.datum_params[4] === dest.datum_params[4] && source.datum_params[5] === dest.datum_params[5] && source.datum_params[6] === dest.datum_params[6]); + } 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) + * + */ + function geodeticToGeocentric(p, es, a) { + var Longitude = p.x; + var Latitude = p.y; + var Height = p.z ? p.z : 0; //Z value not always supplied + + 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 = a / (Math.sqrt(1.0e0 - es * Sin2_Lat)); + return { + x: (Rn + Height) * Cos_Lat * Math.cos(Longitude), + y: (Rn + Height) * Cos_Lat * Math.sin(Longitude), + z: ((Rn * (1 - es)) + Height) * Sin_Lat + }; + } // cs_geodetic_to_geocentric() + + function geocentricToGeodetic(p, es, a, b) { + /* 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 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; + + P = Math.sqrt(X * X + Y * Y); + RR = Math.sqrt(X * X + Y * Y + Z * Z); + + /* special cases for latitude and longitude */ + if (P / a < genau) { + + /* special case, if P=0. (X=0., Y=0.) */ + 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 / a < genau) { + Latitude = HALF_PI; + Height = -b; + return { + x: p.x, + y: p.y, + z: p.z + }; + } + } 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 - es * (2.0 - es) * ST * ST); + CPHI0 = ST * (1.0 - 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 = a / Math.sqrt(1.0 - es * SPHI0 * SPHI0); + + /* ellipsoidal (geodetic) height */ + Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - es * SPHI0 * SPHI0); + + RK = 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)); + return { + x: Longitude, + y: Latitude, + z: Height + }; + } // cs_geocentric_to_geodetic() + + /****************************************************************/ + // pj_geocentic_to_wgs84( p ) + // p = point to transform in geocentric coordinates (x,y,z) + + + /** 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. + */ + function geocentricToWgs84(p, datum_type, datum_params) { + + if (datum_type === PJD_3PARAM) { + // if( x[io] === HUGE_VAL ) + // continue; + return { + x: p.x + datum_params[0], + y: p.y + datum_params[1], + z: p.z + datum_params[2], + }; + } else if (datum_type === PJD_7PARAM) { + var Dx_BF = datum_params[0]; + var Dy_BF = datum_params[1]; + var Dz_BF = datum_params[2]; + var Rx_BF = datum_params[3]; + var Ry_BF = datum_params[4]; + var Rz_BF = datum_params[5]; + var M_BF = datum_params[6]; + // if( x[io] === HUGE_VAL ) + // continue; + return { + x: M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF, + y: M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF, + z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF + }; + } + } // cs_geocentric_to_wgs84 + + /****************************************************************/ + // pj_geocentic_from_wgs84() + // coordinate system definition, + // point to transform in geocentric coordinates (x,y,z) + function geocentricFromWgs84(p, datum_type, datum_params) { + + if (datum_type === PJD_3PARAM) { + //if( x[io] === HUGE_VAL ) + // continue; + return { + x: p.x - datum_params[0], + y: p.y - datum_params[1], + z: p.z - datum_params[2], + }; + + } else if (datum_type === PJD_7PARAM) { + var Dx_BF = datum_params[0]; + var Dy_BF = datum_params[1]; + var Dz_BF = datum_params[2]; + var Rx_BF = datum_params[3]; + var Ry_BF = datum_params[4]; + var Rz_BF = datum_params[5]; + var M_BF = 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; + + return { + x: x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp, + y: -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp, + z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp + }; + } //cs_geocentric_from_wgs84() + } + + function checkParams(type) { + return (type === PJD_3PARAM || type === PJD_7PARAM); + } + + var datum_transform = function(source, dest, point) { + // Short cut if the datums are identical. + if (compareDatums(source, 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; + } + + // If this datum requires grid shifts, then apply it to geodetic coordinates. + + // Do we need to go through geocentric coordinates? + if (source.es === dest.es && source.a === dest.a && !checkParams(source.datum_type) && !checkParams(dest.datum_type)) { + return point; + } + + // Convert to geocentric coordinates. + point = geodeticToGeocentric(point, source.es, source.a); + // Convert between datums + if (checkParams(source.datum_type)) { + point = geocentricToWgs84(point, source.datum_type, source.datum_params); + } + if (checkParams(dest.datum_type)) { + point = geocentricFromWgs84(point, dest.datum_type, dest.datum_params); + } + return geocentricToGeodetic(point, dest.es, dest.a, dest.b); + + }; + + var adjust_axis = function(crs, denorm, point) { + var xin = point.x, + yin = point.y, + zin = point.z || 0.0; + var v, t, i; + var out = {}; + 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': + out[t] = v; + break; + case 'w': + out[t] = -v; + break; + case 'n': + out[t] = v; + break; + case 's': + out[t] = -v; + break; + case 'u': + if (point[t] !== undefined) { + out.z = v; + } + break; + case 'd': + if (point[t] !== undefined) { + out.z = -v; + } + break; + default: + //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName); + return null; + } + } + return out; + }; + + var toPoint = 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; + }; + + function checkNotWGS(source, dest) { + return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== 'WGS84') || ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM) && source.datumCode !== 'WGS84'); + } + + function transform(source, dest, point) { + var wgs84; + if (Array.isArray(point)) { + point = toPoint(point); + } + + // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84 + if (source.datum && dest.datum && checkNotWGS(source, dest)) { + wgs84 = new Projection$1('WGS84'); + point = transform(source, wgs84, point); + source = wgs84; + } + // DGR, 2010/11/12 + if (source.axis !== 'enu') { + point = adjust_axis(source, false, point); + } + // Transform source points to long/lat, if they aren't already. + if (source.projName === 'longlat') { + point.x *= D2R; + point.y *= D2R; + } + else { + if (source.isGeocent) { + if (source.to_meter) { + point.x *= source.to_meter; + point.y *= source.to_meter; + point.z *= source.to_meter; + } + // originally dest.datum.geocentric_to_geodetic_noniter(point); + point = geocentricToGeodetic(point, dest.es, dest.a, dest.b); + } else { + if (source.to_meter) { + point.x *= source.to_meter; + point.y *= source.to_meter; + } + point = 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 + if (dest.isGeocent) { + point = geodeticToGeocentric(point, dest.es, dest.a); + if (dest.to_meter) { + point.x /= dest.to_meter; + point.y /= dest.to_meter; + point.z /= dest.to_meter; + } + } else { + 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') { + return adjust_axis(dest, true, point); + } + + return point; + } + + var wgs84 = Projection$1('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 Projection$1) { + return item; + } + if (item.oProj) { + return item.oProj; + } + return Projection$1(item); + } + function _mproj4_$1(fromProj, toProj, coord, retProj) { + if(retProj) { + return fromProj; + } + 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); + }, + info: function () { + return { + "a": toProj.a, + "b": toProj.b, + "ra": toProj.R_A, + "proj-name": toProj.projName + }; + } + }; + if (single) { + obj.oProj = toProj; + } + return obj; + } + } + + /** + * 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 + var mgrs = { + forward: forward$1, + inverse: inverse$1, + toPoint: toPoint$1 + }; + /** + * 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, 2 for 1000 m or 1 for 10000 m). Optional, default is 5. + * @return {string} the MGRS string for the given location and accuracy. + */ + function forward$1(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. + */ + function inverse$1(mgrs) { + var bbox = UTMtoLL(decode(mgrs.toUpperCase())); + if (bbox.lat && bbox.lon) { + return [bbox.lon, bbox.lat, bbox.lon, bbox.lat]; + } + return [bbox.left, bbox.bottom, bbox.right, bbox.top]; + } + + function toPoint$1(mgrs) { + var bbox = UTMtoLL(decode(mgrs.toUpperCase())); + if (bbox.lat && bbox.lon) { + return [bbox.lon, bbox.lat]; + } + return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 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) { + // prepend with leading zeroes + var seasting = "00000" + utm.easting, + snorthing = "00000" + 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); + } + + } + + 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(toPoint$1(mgrsStr)); + }; + Point.prototype.toMGRS = function(accuracy) { + return forward$1([this.x, this.y], accuracy); + }; + + var version = "2.4.4-alpha"; + + 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; + + var pj_enfn = 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; + }; + + var pj_mlfn = 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])))); + }; + + var MAX_ITER = 20; + + var pj_inv_mlfn = 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; + }; + + // Heavily based on this tmerc projection implementation + // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js + + function init$2() { + this.x0 = this.x0 !== undefined ? this.x0 : 0; + this.y0 = this.y0 !== undefined ? this.y0 : 0; + this.long0 = this.long0 !== undefined ? this.long0 : 0; + this.lat0 = this.lat0 !== undefined ? this.lat0 : 0; + + if (this.es) { + this.en = pj_enfn(this.es); + this.ml0 = pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en); + } + } + + /** + Transverse Mercator Forward - long/lat to x/y + long/lat in radians + */ + function forward$2(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.es) { + var b = cos_phi * Math.sin(delta_lon); + + if ((Math.abs(Math.abs(b) - 1)) < EPSLN) { + return (93); + } + else { + x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0; + y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2)); + b = Math.abs(y); + + if (b >= 1) { + if ((b - 1) > EPSLN) { + return (93); + } + else { + y = 0; + } + } + else { + y = Math.acos(y); + } + + if (lat < 0) { + y = -y; + } + + y = this.a * this.k0 * (y - this.lat0) + this.y0; + } + } + else { + var al = cos_phi * delta_lon; + var als = Math.pow(al, 2); + var c = this.ep2 * Math.pow(cos_phi, 2); + var cs = Math.pow(c, 2); + var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0; + var t = Math.pow(tq, 2); + var ts = Math.pow(t, 2); + con = 1 - this.es * Math.pow(sin_phi, 2); + al = al / Math.sqrt(con); + var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en); + + x = this.a * (this.k0 * al * (1 + + als / 6 * (1 - t + c + + als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c + + als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) + + this.x0; + + y = this.a * (this.k0 * (ml - this.ml0 + + sin_phi * delta_lon * al / 2 * (1 + + als / 12 * (5 - t + 9 * c + 4 * cs + + als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c + + als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) + + this.y0; + } + + p.x = x; + p.y = y; + + return p; + } + + /** + Transverse Mercator Inverse - x/y to long/lat + */ + function inverse$2(p) { + var con, phi; + var lat, lon; + var x = (p.x - this.x0) * (1 / this.a); + var y = (p.y - this.y0) * (1 / this.a); + + if (!this.es) { + var f = Math.exp(x / this.k0); + var g = 0.5 * (f - 1 / f); + var temp = this.lat0 + y / this.k0; + var h = Math.cos(temp); + con = Math.sqrt((1 - Math.pow(h, 2)) / (1 + Math.pow(g, 2))); + lat = Math.asin(con); + + if (y < 0) { + lat = -lat; + } + + if ((g === 0) && (h === 0)) { + lon = 0; + } + else { + lon = adjust_lon(Math.atan2(g, h) + this.long0); + } + } + else { // ellipsoidal form + con = this.ml0 + y / this.k0; + phi = pj_inv_mlfn(con, this.es, this.en); + + if (Math.abs(phi) < HALF_PI) { + var sin_phi = Math.sin(phi); + var cos_phi = Math.cos(phi); + var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0; + 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 d = x * Math.sqrt(con) / this.k0; + var ds = Math.pow(d, 2); + con = con * tan_phi; + + lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1 - + ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs - + ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c - + ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t)))); + + lon = adjust_lon(this.long0 + (d * (1 - + ds / 6 * (1 + 2 * t + c - + ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c - + ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi)); + } + else { + lat = HALF_PI * sign(y); + lon = 0; + } + } + + p.x = lon; + p.y = lat; + + return p; + } + + var names$3 = ["Transverse_Mercator", "Transverse Mercator", "tmerc"]; + var tmerc = { + init: init$2, + forward: forward$2, + inverse: inverse$2, + names: names$3 + }; + + var sinh = function(x) { + var r = Math.exp(x); + r = (r - 1 / r) / 2; + return r; + }; + + var hypot = function(x, y) { + x = Math.abs(x); + y = Math.abs(y); + var a = Math.max(x, y); + var b = Math.min(x, y) / (a ? a : 1); + + return a * Math.sqrt(1 + Math.pow(b, 2)); + }; + + var log1py = function(x) { + var y = 1 + x; + var z = y - 1; + + return z === 0 ? x : x * Math.log(y) / z; + }; + + var asinhy = function(x) { + var y = Math.abs(x); + y = log1py(y * (1 + y / (hypot(1, y) + 1))); + + return x < 0 ? -y : y; + }; + + var gatg = function(pp, B) { + var cos_2B = 2 * Math.cos(2 * B); + var i = pp.length - 1; + var h1 = pp[i]; + var h2 = 0; + var h; + + while (--i >= 0) { + h = -h2 + cos_2B * h1 + pp[i]; + h2 = h1; + h1 = h; + } + + return (B + h * Math.sin(2 * B)); + }; + + var clens = function(pp, arg_r) { + var r = 2 * Math.cos(arg_r); + var i = pp.length - 1; + var hr1 = pp[i]; + var hr2 = 0; + var hr; + + while (--i >= 0) { + hr = -hr2 + r * hr1 + pp[i]; + hr2 = hr1; + hr1 = hr; + } + + return Math.sin(arg_r) * hr; + }; + + var cosh = function(x) { + var r = Math.exp(x); + r = (r + 1 / r) / 2; + return r; + }; + + var clens_cmplx = function(pp, arg_r, arg_i) { + var sin_arg_r = Math.sin(arg_r); + var cos_arg_r = Math.cos(arg_r); + var sinh_arg_i = sinh(arg_i); + var cosh_arg_i = cosh(arg_i); + var r = 2 * cos_arg_r * cosh_arg_i; + var i = -2 * sin_arg_r * sinh_arg_i; + var j = pp.length - 1; + var hr = pp[j]; + var hi1 = 0; + var hr1 = 0; + var hi = 0; + var hr2; + var hi2; + + while (--j >= 0) { + hr2 = hr1; + hi2 = hi1; + hr1 = hr; + hi1 = hi; + hr = -hr2 + r * hr1 - i * hi1 + pp[j]; + hi = -hi2 + i * hr1 + r * hi1; + } + + r = sin_arg_r * cosh_arg_i; + i = cos_arg_r * sinh_arg_i; + + return [r * hr - i * hi, r * hi + i * hr]; + }; + + // Heavily based on this etmerc projection implementation + // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js + + function init$3() { + if (this.es === undefined || this.es <= 0) { + throw new Error('incorrect elliptical usage'); + } + + this.x0 = this.x0 !== undefined ? this.x0 : 0; + this.y0 = this.y0 !== undefined ? this.y0 : 0; + this.long0 = this.long0 !== undefined ? this.long0 : 0; + this.lat0 = this.lat0 !== undefined ? this.lat0 : 0; + + this.cgb = []; + this.cbg = []; + this.utg = []; + this.gtu = []; + + var f = this.es / (1 + Math.sqrt(1 - this.es)); + var n = f / (2 - f); + var np = n; + + this.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675 )))))); + this.cbg[0] = n * (-2 + n * ( 2 / 3 + n * ( 4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725)))))); + + np = np * n; + this.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945))))); + this.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * ( -13 / 9 + n * (904 / 315 + n * (-1522 / 945))))); + + np = np * n; + this.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835)))); + this.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835)))); + + np = np * n; + this.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175))); + this.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * ( -24832 / 14175))); + + np = np * n; + this.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237)); + this.cbg[4] = np * (-734 / 315 + n * (109598 / 31185)); + + np = np * n; + this.cgb[5] = np * (601676 / 22275); + this.cbg[5] = np * (444337 / 155925); + + np = Math.pow(n, 2); + this.Qn = this.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256))); + + this.utg[0] = n * (-0.5 + n * ( 2 / 3 + n * (-37 / 96 + n * ( 1 / 360 + n * (81 / 512 + n * (-96199 / 604800)))))); + this.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800)))))); + + this.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720))))); + this.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360))))); + + np = np * n; + this.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720 )))); + this.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440)))); + + np = np * n; + this.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600))); + this.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600))); + + np = np * n; + this.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680)); + this.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840)); + + np = np * n; + this.utg[5] = np * (-20648693 / 638668800); + this.gtu[5] = np * (212378941 / 319334400); + + var Z = gatg(this.cbg, this.lat0); + this.Zb = -this.Qn * (Z + clens(this.gtu, 2 * Z)); + } + + function forward$3(p) { + var Ce = adjust_lon(p.x - this.long0); + var Cn = p.y; + + Cn = gatg(this.cbg, Cn); + var sin_Cn = Math.sin(Cn); + var cos_Cn = Math.cos(Cn); + var sin_Ce = Math.sin(Ce); + var cos_Ce = Math.cos(Ce); + + Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn); + Ce = Math.atan2(sin_Ce * cos_Cn, hypot(sin_Cn, cos_Cn * cos_Ce)); + Ce = asinhy(Math.tan(Ce)); + + var tmp = clens_cmplx(this.gtu, 2 * Cn, 2 * Ce); + + Cn = Cn + tmp[0]; + Ce = Ce + tmp[1]; + + var x; + var y; + + if (Math.abs(Ce) <= 2.623395162778) { + x = this.a * (this.Qn * Ce) + this.x0; + y = this.a * (this.Qn * Cn + this.Zb) + this.y0; + } + else { + x = Infinity; + y = Infinity; + } + + p.x = x; + p.y = y; + + return p; + } + + function inverse$3(p) { + var Ce = (p.x - this.x0) * (1 / this.a); + var Cn = (p.y - this.y0) * (1 / this.a); + + Cn = (Cn - this.Zb) / this.Qn; + Ce = Ce / this.Qn; + + var lon; + var lat; + + if (Math.abs(Ce) <= 2.623395162778) { + var tmp = clens_cmplx(this.utg, 2 * Cn, 2 * Ce); + + Cn = Cn + tmp[0]; + Ce = Ce + tmp[1]; + Ce = Math.atan(sinh(Ce)); + + var sin_Cn = Math.sin(Cn); + var cos_Cn = Math.cos(Cn); + var sin_Ce = Math.sin(Ce); + var cos_Ce = Math.cos(Ce); + + Cn = Math.atan2(sin_Cn * cos_Ce, hypot(sin_Ce, cos_Ce * cos_Cn)); + Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn); + + lon = adjust_lon(Ce + this.long0); + lat = gatg(this.cgb, Cn); + } + else { + lon = Infinity; + lat = Infinity; + } + + p.x = lon; + p.y = lat; + + return p; + } + + var names$4 = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc"]; + var etmerc = { + init: init$3, + forward: forward$3, + inverse: inverse$3, + names: names$4 + }; + + var adjust_zone = function(zone, lon) { + if (zone === undefined) { + zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI) + 1; + + if (zone < 0) { + return 0; + } else if (zone > 60) { + return 60; + } + } + return zone; + }; + + var dependsOn = 'etmerc'; + function init$4() { + var zone = adjust_zone(this.zone, this.long0); + if (zone === undefined) { + throw new Error('unknown utm zone'); + } + this.lat0 = 0; + this.long0 = ((6 * Math.abs(zone)) - 183) * D2R; + this.x0 = 500000; + this.y0 = this.utmSouth ? 10000000 : 0; + this.k0 = 0.9996; + + etmerc.init.apply(this); + this.forward = etmerc.forward; + this.inverse = etmerc.inverse; + } + + var names$5 = ["Universal Transverse Mercator System", "utm"]; + var utm = { + init: init$4, + names: names$5, + dependsOn: dependsOn + }; + + var srat = function(esinp, exp) { + return (Math.pow((1 - esinp) / (1 + esinp), exp)); + }; + + var MAX_ITER$1 = 20; + function init$6() { + 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)); + } + + function forward$5(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; + } + + function inverse$5(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$1; 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; + } + + var names$7 = ["gauss"]; + var gauss = { + init: init$6, + forward: forward$5, + inverse: inverse$5, + names: names$7 + }; + + function init$5() { + 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"; + } + } + + function forward$4(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; + } + + function inverse$4(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; + } + + var names$6 = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"]; + var sterea = { + init: init$5, + forward: forward$4, + inverse: inverse$4, + names: names$6 + }; + + function ssfn_(phit, sinphi, eccen) { + sinphi *= eccen; + return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen)); + } + + function init$7() { + 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 + function forward$6(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 + function inverse$6(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; + + } + + var names$8 = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"]; + var stere = { + init: init$7, + forward: forward$6, + inverse: inverse$6, + names: names$8, + ssfn_: ssfn_ + }; + + /* + 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 + */ + + function init$8() { + 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; + } + + function forward$7(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; + } + + function inverse$7(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; + } + + var names$9 = ["somerc"]; + var somerc = { + init: init$8, + forward: forward$7, + inverse: inverse$7, + names: names$9 + }; + + /* Initialize the Oblique Mercator projection + ------------------------------------------*/ + function init$9() { + 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 + ----------------------------------------------------------*/ + function forward$8(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; + } + + function inverse$8(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; + } + + var names$10 = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"]; + var omerc = { + init: init$9, + forward: forward$8, + inverse: inverse$8, + names: names$10 + }; + + function init$10() { + + // 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 + // ----------------------------------------------------------------- + function forward$9(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 + // ----------------------------------------------------------------- + function inverse$9(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; + } + + var names$11 = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"]; + var lcc = { + init: init$10, + forward: forward$9, + inverse: inverse$9, + names: names$11 + }; + + function init$11() { + 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 */ + function forward$10(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 */ + function inverse$10(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); + } + + var names$12 = ["Krovak", "krovak"]; + var krovak = { + init: init$11, + forward: forward$10, + inverse: inverse$10, + names: names$12 + }; + + var mlfn = function(e0, e1, e2, e3, phi) { + return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi)); + }; + + var e0fn = function(x) { + return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x))); + }; + + var e1fn = function(x) { + return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x))); + }; + + var e2fn = function(x) { + return (0.05859375 * x * x * (1 + 0.75 * x)); + }; + + var e3fn = function(x) { + return (x * x * x * (35 / 3072)); + }; + + var gN = function(a, e, sinphi) { + var temp = e * sinphi; + return a / Math.sqrt(1 - temp * temp); + }; + + var adjust_lat = function(x) { + return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI)); + }; + + var imlfn = 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; + }; + + function init$12() { + 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 + -----------------------------------------------------------------------*/ + function forward$11(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 + -----------------*/ + function inverse$11(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; + + } + + var names$13 = ["Cassini", "Cassini_Soldner", "cass"]; + var cass = { + init: init$12, + forward: forward$11, + inverse: inverse$11, + names: names$13 + }; + + var qsfnz = 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); + } + }; + + /* + reference + "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder, + The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355. + */ + + var S_POLE = 1; + + var N_POLE = 2; + var EQUIT = 3; + var OBLIQ = 4; + + /* Initialize the Lambert Azimuthal Equal Area projection + ------------------------------------------------------*/ + function init$13() { + 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 = 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 + -----------------------------------------------------------------------*/ + function forward$12(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 + -----------------*/ + function inverse$12(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 = authlat(Math.asin(ab), this.apa); + } + + p.x = adjust_lon(this.long0 + lam); + p.y = phi; + return p; + } + + /* determine latitude from authalic latitude */ + var P00 = 0.33333333333333333333; + + var P01 = 0.17222222222222222222; + var P02 = 0.10257936507936507936; + var P10 = 0.06388888888888888888; + var P11 = 0.06640211640211640211; + var P20 = 0.01641501294219154443; + + function authset(es) { + var t; + var APA = []; + APA[0] = es * P00; + t = es * es; + APA[0] += t * P01; + APA[1] = t * P10; + t *= es; + APA[0] += t * P02; + APA[1] += t * P11; + APA[2] = t * P20; + return APA; + } + + function authlat(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)); + } + + var names$14 = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"]; + var laea = { + init: init$13, + forward: forward$12, + inverse: inverse$12, + names: names$14, + S_POLE: S_POLE, + N_POLE: N_POLE, + EQUIT: EQUIT, + OBLIQ: OBLIQ + }; + + var asinz = function(x) { + if (Math.abs(x) > 1) { + x = (x > 1) ? 1 : -1; + } + return Math.asin(x); + }; + + function init$14() { + + 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 + -------------------------------------------------------------------*/ + function forward$13(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; + } + + function inverse$13(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. + -------------------------------------------*/ + function phi1z(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; + } + + var names$15 = ["Albers_Conic_Equal_Area", "Albers", "aea"]; + var aea = { + init: init$14, + forward: forward$13, + inverse: inverse$13, + names: names$15, + phi1z: phi1z + }; + + /* + reference: + Wolfram Mathworld "Gnomonic Projection" + http://mathworld.wolfram.com/GnomonicProjection.html + Accessed: 12th November 2009 + */ + function init$15() { + + /* 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 + ---------------------------------------------------*/ + function forward$14(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; + } + + function inverse$14(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; + } + + var names$16 = ["gnom"]; + var gnom = { + init: init$15, + forward: forward$14, + inverse: inverse$14, + names: names$16 + }; + + var iqsfnz = 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; + }; + + /* + 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) + */ + function init$16() { + //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 + ------------------------------------------------------------*/ + function forward$15(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 + ------------------------------------------------------------*/ + function inverse$15(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; + } + + var names$17 = ["cea"]; + var cea = { + init: init$16, + forward: forward$15, + inverse: inverse$15, + names: names$17 + }; + + function init$17() { + + 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 + // ----------------------------------------------------------------- + function forward$16(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 + // ----------------------------------------------------------------- + function inverse$16(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; + } + + var names$18 = ["Equirectangular", "Equidistant_Cylindrical", "eqc"]; + var eqc = { + init: init$17, + forward: forward$16, + inverse: inverse$16, + names: names$18 + }; + + var MAX_ITER$2 = 20; + + function init$18() { + /* 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 + ---------------------------------------------------*/ + function forward$17(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 + -----------------*/ + function inverse$17(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$2; 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$2; 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; + } + + var names$19 = ["Polyconic", "poly"]; + var poly = { + init: init$18, + forward: forward$17, + inverse: inverse$17, + names: names$19 + }; + + /* + 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 + */ + + + function init$19() { + 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 + */ + function forward$18(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 + */ + function inverse$18(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; + } + + var names$20 = ["New_Zealand_Map_Grid", "nzmg"]; + var nzmg = { + init: init$19, + forward: forward$18, + inverse: inverse$18, + names: names$20 + }; + + /* + 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 + -------------------------------------------*/ + function init$20() { + //no-op + } + + /* Miller Cylindrical forward equations--mapping lat,long to x,y + ------------------------------------------------------------*/ + function forward$19(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 + ------------------------------------------------------------*/ + function inverse$19(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; + } + + var names$21 = ["Miller_Cylindrical", "mill"]; + var mill = { + init: init$20, + forward: forward$19, + inverse: inverse$19, + names: names$21 + }; + + var MAX_ITER$3 = 20; + function init$21() { + /* 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 + -----------------------------------------------------*/ + function forward$20(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$3; 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; + } + + function inverse$20(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; + } + + var names$22 = ["Sinusoidal", "sinu"]; + var sinu = { + init: init$21, + forward: forward$20, + inverse: inverse$20, + names: names$22 + }; + + function init$22() {} + /* Mollweide forward equations--mapping lat,long to x,y + ----------------------------------------------------*/ + function forward$21(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; + } + + function inverse$21(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; + } + + var names$23 = ["Mollweide", "moll"]; + var moll = { + init: init$22, + forward: forward$21, + inverse: inverse$21, + names: names$23 + }; + + function init$23() { + + /* 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 + -----------------------------------------------------------*/ + function forward$22(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 + -----------------*/ + function inverse$22(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; + } + + } + + var names$24 = ["Equidistant_Conic", "eqdc"]; + var eqdc = { + init: init$23, + forward: forward$22, + inverse: inverse$22, + names: names$24 + }; + + /* Initialize the Van Der Grinten projection + ----------------------------------------*/ + function init$24() { + //this.R = 6370997; //Radius of earth + this.R = this.a; + } + + function forward$23(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 + ---------------------------------------------------------*/ + function inverse$23(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; + } + + var names$25 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"]; + var vandg = { + init: init$24, + forward: forward$23, + inverse: inverse$23, + names: names$25 + }; + + function init$25() { + this.sin_p12 = Math.sin(this.lat0); + this.cos_p12 = Math.cos(this.lat0); + } + + function forward$24(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; + } + } + + + } + + function inverse$24(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; + } + } + + } + + var names$26 = ["Azimuthal_Equidistant", "aeqd"]; + var aeqd = { + init: init$25, + forward: forward$24, + inverse: inverse$24, + names: names$26 + }; + + function init$26() { + //double temp; /* temporary variable */ + + /* Place parameters in static storage for common use + -------------------------------------------------*/ + this.sin_p14 = Math.sin(this.lat0); + this.cos_p14 = Math.cos(this.lat0); + } + + /* Orthographic forward equations--mapping lat,long to x,y + ---------------------------------------------------*/ + function forward$25(p) { + var sinphi, cosphi; /* sin and cos value */ + var dlon; /* delta longitude value */ + var coslon; /* cos of longitude */ + var ksp; /* scale factor */ + var g, 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.a * ksp * cosphi * Math.sin(dlon); + y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon); + } + p.x = x; + p.y = y; + return p; + } + + function inverse$25(p) { + var rh; /* height above ellipsoid */ + var z; /* angle */ + var sinz, cosz; /* sin of z and cos of z */ + var con; + var lon, lat; + /* Inverse equations + -----------------*/ + p.x -= this.x0; + p.y -= this.y0; + rh = Math.sqrt(p.x * p.x + p.y * p.y); + z = asinz(rh / this.a); + + sinz = Math.sin(z); + cosz = Math.cos(z); + + lon = this.long0; + if (Math.abs(rh) <= EPSLN) { + lat = this.lat0; + p.x = lon; + p.y = lat; + return p; + } + lat = asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14) / 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)); + } + p.x = lon; + p.y = lat; + return p; + } + lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz), rh * this.cos_p14 * cosz - p.y * this.sin_p14 * sinz)); + p.x = lon; + p.y = lat; + return p; + } + + var names$27 = ["ortho"]; + var ortho = { + init: init$26, + forward: forward$25, + inverse: inverse$25, + names: names$27 + }; + + function init$27() { + this.isGeocent = true; + } + + function identity$1(pt) { + return pt; + } + var names$28 = ["geocent"]; + var geocent = { + init: init$27, + forward: identity$1, + inverse: identity$1, + names: names$28 + }; + + function init$28() { + + 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 || "Quadrilateralized Spherical Cube"; + + this.face_enum = { + FRONT: 1, + RIGHT: 2, + BACK: 3, + LEFT: 4, + TOP: 5, + BOTTOM: 6 + }; + + this.area_enum = { + AREA_0: 1, + AREA_1: 2, + AREA_2: 3, + AREA_3: 4 + }; + + /* Determine the cube face from the center of projection. */ + if (this.lat0 >= HALF_PI - FORTPI / 2.0) { + this.face = this.face_enum.TOP; + } else if (this.lat0 <= -(HALF_PI - FORTPI / 2.0)) { + this.face = this.face_enum.BOTTOM; + } else if (Math.abs(this.long0) <= FORTPI) { + this.face = this.face_enum.FRONT; + } else if (Math.abs(this.long0) <= HALF_PI + FORTPI) { + this.face = this.long0 > 0.0 ? this.face_enum.RIGHT : this.face_enum.LEFT; + } else { + this.face = this.face_enum.BACK; + } + + //this.es = 1 - (this.b * this.b) / (this.a * this.a); + + /* Fill in useful values for the ellipsoid <-> sphere shift + * described in [LK12]. */ + if (this.es !== 0.0) { + this.one_minus_f = 1 - (this.a - this.b) / this.a; + this.one_minus_f_squared = this.one_minus_f * this.one_minus_f; + } + } + + // QSC forward equations--mapping lat,long to x,y + // ----------------------------------------------------------------- + function forward$26(p) { + var xy = {x: 0, y: 0.0}; + var lat, lon; + var theta, phi; + var t, mu; + /* nu; */ + var area = {value: 0}; + + // move lon according to projection's lon + p.x -= this.long0; + + /* Convert the geodetic latitude to a geocentric latitude. + * This corresponds to the shift from the ellipsoid to the sphere + * described in [LK12]. */ + if (this.es !== 0) {//if (P->es != 0.0) { + lat = Math.atan(this.one_minus_f_squared * Math.tan(p.y)); + } else { + lat = p.y; + } + + /* Convert the input lat, lon into theta, phi as used by QSC. + * This depends on the cube face and the area on it. + * For the top and bottom face, we can compute theta and phi + * directly from phi, lam. For the other faces, we must use + * unit sphere cartesian coordinates as an intermediate step. */ + lon = p.x; //lon = lp.lam; + if (this.face === this.face_enum.TOP) { + phi = HALF_PI - lat; + if (lon >= FORTPI && lon <= HALF_PI + FORTPI) { + area.value = this.area_enum.AREA_0; + theta = lon - HALF_PI; + } else if (lon > HALF_PI + FORTPI || lon <= -(HALF_PI + FORTPI)) { + area.value = this.area_enum.AREA_1; + theta = (lon > 0.0 ? lon - SPI : lon + SPI); + } else if (lon > -(HALF_PI + FORTPI) && lon <= -FORTPI) { + area.value = this.area_enum.AREA_2; + theta = lon + HALF_PI; + } else { + area.value = this.area_enum.AREA_3; + theta = lon; + } + } else if (this.face === this.face_enum.BOTTOM) { + phi = HALF_PI + lat; + if (lon >= FORTPI && lon <= HALF_PI + FORTPI) { + area.value = this.area_enum.AREA_0; + theta = -lon + HALF_PI; + } else if (lon < FORTPI && lon >= -FORTPI) { + area.value = this.area_enum.AREA_1; + theta = -lon; + } else if (lon < -FORTPI && lon >= -(HALF_PI + FORTPI)) { + area.value = this.area_enum.AREA_2; + theta = -lon - HALF_PI; + } else { + area.value = this.area_enum.AREA_3; + theta = (lon > 0.0 ? -lon + SPI : -lon - SPI); + } + } else { + var q, r, s; + var sinlat, coslat; + var sinlon, coslon; + + if (this.face === this.face_enum.RIGHT) { + lon = this.qsc_shift_lon_origin(lon, +HALF_PI); + } else if (this.face === this.face_enum.BACK) { + lon = this.qsc_shift_lon_origin(lon, +SPI); + } else if (this.face === this.face_enum.LEFT) { + lon = this.qsc_shift_lon_origin(lon, -HALF_PI); + } + sinlat = Math.sin(lat); + coslat = Math.cos(lat); + sinlon = Math.sin(lon); + coslon = Math.cos(lon); + q = coslat * coslon; + r = coslat * sinlon; + s = sinlat; + + if (this.face === this.face_enum.FRONT) { + phi = Math.acos(q); + theta = this.qsc_fwd_equat_face_theta(phi, s, r, area); + } else if (this.face === this.face_enum.RIGHT) { + phi = Math.acos(r); + theta = this.qsc_fwd_equat_face_theta(phi, s, -q, area); + } else if (this.face === this.face_enum.BACK) { + phi = Math.acos(-q); + theta = this.qsc_fwd_equat_face_theta(phi, s, -r, area); + } else if (this.face === this.face_enum.LEFT) { + phi = Math.acos(-r); + theta = this.qsc_fwd_equat_face_theta(phi, s, q, area); + } else { + /* Impossible */ + phi = theta = 0.0; + area.value = this.area_enum.AREA_0; + } + } + + /* Compute mu and nu for the area of definition. + * For mu, see Eq. (3-21) in [OL76], but note the typos: + * compare with Eq. (3-14). For nu, see Eq. (3-38). */ + mu = Math.atan((12.0 / SPI) * (theta + Math.acos(Math.sin(theta) * Math.cos(FORTPI)) - HALF_PI)); + t = Math.sqrt((1.0 - Math.cos(phi)) / (Math.cos(mu) * Math.cos(mu)) / (1.0 - Math.cos(Math.atan(1.0 / Math.cos(theta))))); + + /* Apply the result to the real area. */ + if (area.value === this.area_enum.AREA_1) { + mu += HALF_PI; + } else if (area.value === this.area_enum.AREA_2) { + mu += SPI; + } else if (area.value === this.area_enum.AREA_3) { + mu += 1.5 * SPI; + } + + /* Now compute x, y from mu and nu */ + /* t = Math.tan(nu); */ + xy.x = t * Math.cos(mu); + xy.y = t * Math.sin(mu); + xy.x = xy.x * this.a + this.x0; + xy.y = xy.y * this.a + this.y0; + + p.x = xy.x; + p.y = xy.y; + return p; + } + + // QSC inverse equations--mapping x,y to lat/long + // ----------------------------------------------------------------- + function inverse$26(p) { + var lp = {lam: 0, phi: 0.0}; + //struct pj_opaque *Q = P->opaque; + var mu, nu, cosmu, tannu; + var tantheta, theta, cosphi, phi; + var t; + var area = {value: 0}; + + /* de-offset */ + p.x = (p.x - this.x0) / this.a; + p.y = (p.y - this.y0) / this.a; + + /* Convert the input x, y to the mu and nu angles as used by QSC. + * This depends on the area of the cube face. */ + nu = Math.atan(Math.sqrt(p.x * p.x + p.y * p.y)); + mu = Math.atan2(p.y, p.x); + if (p.x >= 0.0 && p.x >= Math.abs(p.y)) { + area.value = this.area_enum.AREA_0; + } else if (p.y >= 0.0 && p.y >= Math.abs(p.x)) { + area.value = this.area_enum.AREA_1; + mu -= HALF_PI; + } else if (p.x < 0.0 && -p.x >= Math.abs(p.y)) { + area.value = this.area_enum.AREA_2; + mu = (mu < 0.0 ? mu + SPI : mu - SPI); + } else { + area.value = this.area_enum.AREA_3; + mu += HALF_PI; + } + + /* Compute phi and theta for the area of definition. + * The inverse projection is not described in the original paper, but some + * good hints can be found here (as of 2011-12-14): + * http://fits.gsfc.nasa.gov/fitsbits/saf.93/saf.9302 + * (search for "Message-Id: <9302181759.AA25477 at fits.cv.nrao.edu>") */ + t = (SPI / 12.0) * Math.tan(mu); + tantheta = Math.sin(t) / (Math.cos(t) - (1.0 / Math.sqrt(2.0))); + theta = Math.atan(tantheta); + cosmu = Math.cos(mu); + tannu = Math.tan(nu); + cosphi = 1.0 - cosmu * cosmu * tannu * tannu * (1.0 - Math.cos(Math.atan(1.0 / Math.cos(theta)))); + if (cosphi < -1.0) { + cosphi = -1.0; + } else if (cosphi > +1.0) { + cosphi = +1.0; + } + + /* Apply the result to the real area on the cube face. + * For the top and bottom face, we can compute phi and lam directly. + * For the other faces, we must use unit sphere cartesian coordinates + * as an intermediate step. */ + if (this.face === this.face_enum.TOP) { + phi = Math.acos(cosphi); + lp.phi = HALF_PI - phi; + if (area.value === this.area_enum.AREA_0) { + lp.lam = theta + HALF_PI; + } else if (area.value === this.area_enum.AREA_1) { + lp.lam = (theta < 0.0 ? theta + SPI : theta - SPI); + } else if (area.value === this.area_enum.AREA_2) { + lp.lam = theta - HALF_PI; + } else /* area.value == this.area_enum.AREA_3 */ { + lp.lam = theta; + } + } else if (this.face === this.face_enum.BOTTOM) { + phi = Math.acos(cosphi); + lp.phi = phi - HALF_PI; + if (area.value === this.area_enum.AREA_0) { + lp.lam = -theta + HALF_PI; + } else if (area.value === this.area_enum.AREA_1) { + lp.lam = -theta; + } else if (area.value === this.area_enum.AREA_2) { + lp.lam = -theta - HALF_PI; + } else /* area.value == this.area_enum.AREA_3 */ { + lp.lam = (theta < 0.0 ? -theta - SPI : -theta + SPI); + } + } else { + /* Compute phi and lam via cartesian unit sphere coordinates. */ + var q, r, s; + q = cosphi; + t = q * q; + if (t >= 1.0) { + s = 0.0; + } else { + s = Math.sqrt(1.0 - t) * Math.sin(theta); + } + t += s * s; + if (t >= 1.0) { + r = 0.0; + } else { + r = Math.sqrt(1.0 - t); + } + /* Rotate q,r,s into the correct area. */ + if (area.value === this.area_enum.AREA_1) { + t = r; + r = -s; + s = t; + } else if (area.value === this.area_enum.AREA_2) { + r = -r; + s = -s; + } else if (area.value === this.area_enum.AREA_3) { + t = r; + r = s; + s = -t; + } + /* Rotate q,r,s into the correct cube face. */ + if (this.face === this.face_enum.RIGHT) { + t = q; + q = -r; + r = t; + } else if (this.face === this.face_enum.BACK) { + q = -q; + r = -r; + } else if (this.face === this.face_enum.LEFT) { + t = q; + q = r; + r = -t; + } + /* Now compute phi and lam from the unit sphere coordinates. */ + lp.phi = Math.acos(-s) - HALF_PI; + lp.lam = Math.atan2(r, q); + if (this.face === this.face_enum.RIGHT) { + lp.lam = this.qsc_shift_lon_origin(lp.lam, -HALF_PI); + } else if (this.face === this.face_enum.BACK) { + lp.lam = this.qsc_shift_lon_origin(lp.lam, -SPI); + } else if (this.face === this.face_enum.LEFT) { + lp.lam = this.qsc_shift_lon_origin(lp.lam, +HALF_PI); + } + } + + /* Apply the shift from the sphere to the ellipsoid as described + * in [LK12]. */ + if (this.es !== 0.0) { + var invert_sign; + var tanphi, xa; + invert_sign = (lp.phi < 0.0 ? 1 : 0); + tanphi = Math.tan(lp.phi); + xa = this.b / Math.sqrt(tanphi * tanphi + this.one_minus_f_squared); + lp.phi = Math.atan(Math.sqrt(this.a * this.a - xa * xa) / (this.one_minus_f * xa)); + if (invert_sign) { + lp.phi = -lp.phi; + } + } + + lp.lam += this.long0; + p.x = lp.lam; + p.y = lp.phi; + return p; + } + + /* Helper function for forward projection: compute the theta angle + * and determine the area number. */ + function qsc_fwd_equat_face_theta(phi, y, x, area) { + var theta; + if (phi < EPSLN) { + area.value = this.area_enum.AREA_0; + theta = 0.0; + } else { + theta = Math.atan2(y, x); + if (Math.abs(theta) <= FORTPI) { + area.value = this.area_enum.AREA_0; + } else if (theta > FORTPI && theta <= HALF_PI + FORTPI) { + area.value = this.area_enum.AREA_1; + theta -= HALF_PI; + } else if (theta > HALF_PI + FORTPI || theta <= -(HALF_PI + FORTPI)) { + area.value = this.area_enum.AREA_2; + theta = (theta >= 0.0 ? theta - SPI : theta + SPI); + } else { + area.value = this.area_enum.AREA_3; + theta += HALF_PI; + } + } + return theta; + } + + /* Helper function: shift the longitude. */ + function qsc_shift_lon_origin(lon, offset) { + var slon = lon + offset; + if (slon < -SPI) { + slon += TWO_PI; + } else if (slon > +SPI) { + slon -= TWO_PI; + } + return slon; + } + + var names$29 = ["Quadrilateralized Spherical Cube", "qsc"]; + var qsc = { + init: init$28, + forward: forward$26, + inverse: inverse$26, + names: names$29, + qsc_fwd_equat_face_theta: qsc_fwd_equat_face_theta, + qsc_shift_lon_origin: qsc_shift_lon_origin + }; + + var includedProjections = function(_mproj4_){ + _mproj4_.Proj.projections.add(tmerc); + _mproj4_.Proj.projections.add(etmerc); + _mproj4_.Proj.projections.add(utm); + _mproj4_.Proj.projections.add(sterea); + _mproj4_.Proj.projections.add(stere); + _mproj4_.Proj.projections.add(somerc); + _mproj4_.Proj.projections.add(omerc); + _mproj4_.Proj.projections.add(lcc); + _mproj4_.Proj.projections.add(krovak); + _mproj4_.Proj.projections.add(cass); + _mproj4_.Proj.projections.add(laea); + _mproj4_.Proj.projections.add(aea); + _mproj4_.Proj.projections.add(gnom); + _mproj4_.Proj.projections.add(cea); + _mproj4_.Proj.projections.add(eqc); + _mproj4_.Proj.projections.add(poly); + _mproj4_.Proj.projections.add(nzmg); + _mproj4_.Proj.projections.add(mill); + _mproj4_.Proj.projections.add(sinu); + _mproj4_.Proj.projections.add(moll); + _mproj4_.Proj.projections.add(eqdc); + _mproj4_.Proj.projections.add(vandg); + _mproj4_.Proj.projections.add(aeqd); + _mproj4_.Proj.projections.add(ortho); + _mproj4_.Proj.projections.add(geocent); + _mproj4_.Proj.projections.add(qsc); + }; + + _mproj4_$1.defaultDatum = 'WGS84'; //default datum + _mproj4_$1.Proj = Projection$1; + _mproj4_$1.WGS84 = new _mproj4_$1.Proj('WGS84'); + _mproj4_$1.Point = Point; + _mproj4_$1.toPoint = toPoint; + _mproj4_$1.defs = defs; + _mproj4_$1.transform = transform; + _mproj4_$1.mgrs = mgrs; + _mproj4_$1.version = version; + includedProjections(_mproj4_$1); + + return _mproj4_$1; + +}))); diff --git a/src/core/utils/libs/proj4.js b/src/core/utils/libs/proj4.js index 26842c9a..1ce0a77a 100755 --- a/src/core/utils/libs/proj4.js +++ b/src/core/utils/libs/proj4.js @@ -1,3 +1,3 @@ -!function(a){if("object"==typeof exports)module.exports=a();else if("function"==typeof define&&define.amd)define(a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b._mproj4_=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gf;f++)if(!b||2!==f||void 0!==c.z)switch(0===f?(d=g,e="x"):1===f?(d=h,e="y"):(d=i,e="z"),a.axis[f]){case"e":c[e]=d;break;case"w":c[e]=-d;break;case"n":c[e]=d;break;case"s":c[e]=-d;break;case"u":void 0!==c[e]&&(c.z=d);break;case"d":void 0!==c[e]&&(c.z=-d);break;default:return null}return c}},{}],4:[function(a,b,c){var d=Math.PI/2,e=a("./sign");b.exports=function(a){return Math.abs(a)1&&(a=a>1?1:-1),Math.asin(a)}},{}],7:[function(a,b,c){b.exports=function(a){return 1-.25*a*(1+a/16*(3+1.25*a))}},{}],8:[function(a,b,c){b.exports=function(a){return.375*a*(1+.25*a*(1+.46875*a))}},{}],9:[function(a,b,c){b.exports=function(a){return.05859375*a*a*(1+.75*a)}},{}],10:[function(a,b,c){b.exports=function(a){return a*a*a*(35/3072)}},{}],11:[function(a,b,c){b.exports=function(a,b,c){var d=b*c;return a/Math.sqrt(1-d*d)}},{}],12:[function(a,b,c){b.exports=function(a,b,c,d,e){var f,g;f=a/b;for(var h=0;15>h;h++)if(g=(a-(b*f-c*Math.sin(2*f)+d*Math.sin(4*f)-e*Math.sin(6*f)))/(b-2*c*Math.cos(2*f)+4*d*Math.cos(4*f)-6*e*Math.cos(6*f)),f+=g,Math.abs(g)<=1e-10)return f;return NaN}},{}],13:[function(a,b,c){var d=Math.PI/2;b.exports=function(a,b){var c=1-(1-a*a)/(2*a)*Math.log((1-a)/(1+a));if(Math.abs(Math.abs(b)-c)<1e-6)return 0>b?-1*d:d;for(var e,f,g,h,i=Math.asin(.5*b),j=0;30>j;j++)if(f=Math.sin(i),g=Math.cos(i),h=a*f,e=Math.pow(1-h*h,2)/(2*g)*(b/(1-a*a)-f/(1-h*h)+.5/a*Math.log((1-h)/(1+h))),i+=e,Math.abs(e)<=1e-10)return i;return NaN}},{}],14:[function(a,b,c){b.exports=function(a,b,c,d,e){return a*e-b*Math.sin(2*e)+c*Math.sin(4*e)-d*Math.sin(6*e)}},{}],15:[function(a,b,c){b.exports=function(a,b,c){var d=a*b;return c/Math.sqrt(1-d*d)}},{}],16:[function(a,b,c){var d=Math.PI/2;b.exports=function(a,b){for(var c,e,f=.5*a,g=d-2*Math.atan(b),h=0;15>=h;h++)if(c=a*Math.sin(g),e=d-2*Math.atan(b*Math.pow((1-c)/(1+c),f))-g,g+=e,Math.abs(e)<=1e-10)return g;return-9999}},{}],17:[function(a,b,c){var d=1,e=.25,f=.046875,g=.01953125,h=.01068115234375,i=.75,j=.46875,k=.013020833333333334,l=.007120768229166667,m=.3645833333333333,n=.005696614583333333,o=.3076171875;b.exports=function(a){var b=[];b[0]=d-a*(e+a*(f+a*(g+a*h))),b[1]=a*(i-a*(f+a*(g+a*h)));var c=a*a;return b[2]=c*(j-a*(k+a*l)),c*=a,b[3]=c*(m-a*n),b[4]=c*a*o,b}},{}],18:[function(a,b,c){var d=a("./pj_mlfn"),e=1e-10,f=20;b.exports=function(a,b,c){for(var g=1/(1-b),h=a,i=f;i;--i){var j=Math.sin(h),k=1-b*j*j;if(k=(d(h,j,Math.cos(h),c)-a)*(k*Math.sqrt(k))*g,h-=k,Math.abs(k)1e-7?(c=a*b,(1-a*a)*(b/(1-c*c)-.5/a*Math.log((1-c)/(1+c)))):2*b}},{}],21:[function(a,b,c){b.exports=function(a){return 0>a?-1:1}},{}],22:[function(a,b,c){b.exports=function(a,b){return Math.pow((1-a)/(1+a),b)}},{}],23:[function(a,b,c){b.exports=function(a){var b={x:a[0],y:a[1]};return a.length>2&&(b.z=a[2]),a.length>3&&(b.m=a[3]),b}},{}],24:[function(a,b,c){var d=Math.PI/2;b.exports=function(a,b,c){var e=a*c,f=.5*a;return e=Math.pow((1-e)/(1+e),f),Math.tan(.5*(d-b))/e}},{}],25:[function(a,b,c){c.wgs84={towgs84:"0,0,0",ellipse:"WGS84",datumName:"WGS84"},c.ch1903={towgs84:"674.374,15.056,405.346",ellipse:"bessel",datumName:"swiss"},c.ggrs87={towgs84:"-199.87,74.79,246.62",ellipse:"GRS80",datumName:"Greek_Geodetic_Reference_System_1987"},c.nad83={towgs84:"0,0,0",ellipse:"GRS80",datumName:"North_American_Datum_1983"},c.nad27={nadgrids:"@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",ellipse:"clrk66",datumName:"North_American_Datum_1927"},c.potsdam={towgs84:"606.0,23.0,413.0",ellipse:"bessel",datumName:"Potsdam Rauenberg 1950 DHDN"},c.carthage={towgs84:"-263.0,6.0,431.0",ellipse:"clark80",datumName:"Carthage 1934 Tunisia"},c.hermannskogel={towgs84:"653.0,-212.0,449.0",ellipse:"bessel",datumName:"Hermannskogel"},c.ire65={towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"mod_airy",datumName:"Ireland 1965"},c.rassadiran={towgs84:"-133.63,-157.5,-158.62",ellipse:"intl",datumName:"Rassadiran"},c.nzgd49={towgs84:"59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",ellipse:"intl",datumName:"New Zealand Geodetic Datum 1949"},c.osgb36={towgs84:"446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",ellipse:"airy",datumName:"Airy 1830"},c.s_jtsk={towgs84:"589,76,480",ellipse:"bessel",datumName:"S-JTSK (Ferro)"},c.beduaram={towgs84:"-106,-87,188",ellipse:"clrk80",datumName:"Beduaram"},c.gunung_segara={towgs84:"-403,684,41",ellipse:"bessel",datumName:"Gunung Segara Jakarta"},c.rnb72={towgs84:"106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",ellipse:"intl",datumName:"Reseau National Belge 1972"}},{}],26:[function(a,b,c){c.MERIT={a:6378137,rf:298.257,ellipseName:"MERIT 1983"},c.SGS85={a:6378136,rf:298.257,ellipseName:"Soviet Geodetic System 85"},c.GRS80={a:6378137,rf:298.257222101,ellipseName:"GRS 1980(IUGG, 1980)"},c.IAU76={a:6378140,rf:298.257,ellipseName:"IAU 1976"},c.airy={a:6377563.396,b:6356256.91,ellipseName:"Airy 1830"},c.APL4={a:6378137,rf:298.25,ellipseName:"Appl. Physics. 1965"},c.NWL9D={a:6378145,rf:298.25,ellipseName:"Naval Weapons Lab., 1965"},c.mod_airy={a:6377340.189,b:6356034.446,ellipseName:"Modified Airy"},c.andrae={a:6377104.43,rf:300,ellipseName:"Andrae 1876 (Den., Iclnd.)"},c.aust_SA={a:6378160,rf:298.25,ellipseName:"Australian Natl & S. Amer. 1969"},c.GRS67={a:6378160,rf:298.247167427,ellipseName:"GRS 67(IUGG 1967)"},c.bessel={a:6377397.155,rf:299.1528128,ellipseName:"Bessel 1841"},c.bess_nam={a:6377483.865,rf:299.1528128,ellipseName:"Bessel 1841 (Namibia)"},c.clrk66={a:6378206.4,b:6356583.8,ellipseName:"Clarke 1866"},c.clrk80={a:6378249.145,rf:293.4663,ellipseName:"Clarke 1880 mod."},c.clrk58={a:6378293.645208759,rf:294.2606763692654,ellipseName:"Clarke 1858"},c.CPM={a:6375738.7,rf:334.29,ellipseName:"Comm. des Poids et Mesures 1799"},c.delmbr={a:6376428,rf:311.5,ellipseName:"Delambre 1810 (Belgium)"},c.engelis={a:6378136.05,rf:298.2566,ellipseName:"Engelis 1985"},c.evrst30={a:6377276.345,rf:300.8017,ellipseName:"Everest 1830"},c.evrst48={a:6377304.063,rf:300.8017,ellipseName:"Everest 1948"},c.evrst56={a:6377301.243,rf:300.8017,ellipseName:"Everest 1956"},c.evrst69={a:6377295.664,rf:300.8017,ellipseName:"Everest 1969"},c.evrstSS={a:6377298.556,rf:300.8017,ellipseName:"Everest (Sabah & Sarawak)"},c.fschr60={a:6378166,rf:298.3,ellipseName:"Fischer (Mercury Datum) 1960"},c.fschr60m={a:6378155,rf:298.3,ellipseName:"Fischer 1960"},c.fschr68={a:6378150,rf:298.3,ellipseName:"Fischer 1968"},c.helmert={a:6378200,rf:298.3,ellipseName:"Helmert 1906"},c.hough={a:6378270,rf:297,ellipseName:"Hough"},c.intl={a:6378388,rf:297,ellipseName:"International 1909 (Hayford)"},c.kaula={a:6378163,rf:298.24,ellipseName:"Kaula 1961"},c.lerch={a:6378139,rf:298.257,ellipseName:"Lerch 1979"},c.mprts={a:6397300,rf:191,ellipseName:"Maupertius 1738"},c.new_intl={a:6378157.5,b:6356772.2,ellipseName:"New International 1967"},c.plessis={a:6376523,rf:6355863,ellipseName:"Plessis 1817 (France)"},c.krass={a:6378245,rf:298.3,ellipseName:"Krassovsky, 1942"},c.SEasia={a:6378155,b:6356773.3205,ellipseName:"Southeast Asia"},c.walbeck={a:6376896,b:6355834.8467,ellipseName:"Walbeck"},c.WGS60={a:6378165,rf:298.3,ellipseName:"WGS 60"},c.WGS66={a:6378145,rf:298.25,ellipseName:"WGS 66"},c.WGS7={a:6378135,rf:298.26,ellipseName:"WGS 72"},c.WGS84={a:6378137,rf:298.257223563,ellipseName:"WGS 84"},c.sphere={a:6370997,b:6370997,ellipseName:"Normal Sphere (r=6370997)"}},{}],27:[function(a,b,c){c.greenwich=0,c.lisbon=-9.131906111111,c.paris=2.337229166667,c.bogota=-74.080916666667,c.madrid=-3.687938888889,c.rome=12.452333333333,c.bern=7.439583333333,c.jakarta=106.807719444444,c.ferro=-17.666666666667,c.brussels=4.367975,c.stockholm=18.058277777778,c.athens=23.7163375,c.oslo=10.722916666667},{}],28:[function(a,b,c){c.ft={to_meter:.3048},c["us-ft"]={to_meter:1200/3937}},{}],29:[function(a,b,c){function d(a,b,c){var d;return Array.isArray(c)?(d=g(a,b,c),3===c.length?[d.x,d.y,d.z]:[d.x,d.y]):g(a,b,c)}function e(a){return a instanceof f?a:a.oProj?a.oProj:f(a)}function _mproj4_(a,b,c,_dddd_){a=e(a);if(_dddd_) return a; var f,g=!1;return"undefined"==typeof b?(b=a,a=h,g=!0):("undefined"!=typeof b.x||Array.isArray(b))&&(c=b,b=a,a=h,g=!0),b=e(b),c?d(a,b,c):(f={forward:function(c){return d(a,b,c)},inverse:function(c){return d(b,a,c)},info:function(){return{a:b.a,b:b.b,ra:b.R_A,"proj-name":b.projName}}},g&&(f.oProj=b),f)}var f=a("./Proj"),g=a("./transform"),h=f("WGS84");b.exports=_mproj4_},{"./Proj":2,"./transform":66}],30:[function(a,b,c){var d=Math.PI/2,e=1,f=2,g=3,h=4,i=5,j=484813681109536e-20,k=1.0026,l=.3826834323650898,m=function(a){if(!(this instanceof m))return new m(a);if(this.datum_type=h,a){if(a.datumCode&&"none"===a.datumCode&&(this.datum_type=i),a.datum_params){for(var b=0;b3&&(0!==a.datum_params[3]||0!==a.datum_params[4]||0!==a.datum_params[5]||0!==a.datum_params[6])&&(this.datum_type=f,a.datum_params[3]*=j,a.datum_params[4]*=j,a.datum_params[5]*=j,a.datum_params[6]=a.datum_params[6]/1e6+1)}this.datum_type=a.grids?g:this.datum_type,this.a=a.a,this.b=a.b,this.es=a.es,this.ep2=a.ep2,this.datum_params=a.datum_params,this.datum_type===g&&(this.grids=a.grids)}};m.prototype={compare_datums:function(a){return this.datum_type!==a.datum_type?!1:this.a!==a.a||Math.abs(this.es-a.es)>5e-11?!1:this.datum_type===e?this.datum_params[0]===a.datum_params[0]&&this.datum_params[1]===a.datum_params[1]&&this.datum_params[2]===a.datum_params[2]:this.datum_type===f?this.datum_params[0]===a.datum_params[0]&&this.datum_params[1]===a.datum_params[1]&&this.datum_params[2]===a.datum_params[2]&&this.datum_params[3]===a.datum_params[3]&&this.datum_params[4]===a.datum_params[4]&&this.datum_params[5]===a.datum_params[5]&&this.datum_params[6]===a.datum_params[6]:this.datum_type===g||a.datum_type===g?this.nadgrids===a.nadgrids:!0},geodetic_to_geocentric:function(a){var b,c,e,f,g,h,i,j=a.x,k=a.y,l=a.z?a.z:0,m=0;if(-d>k&&k>-1.001*d)k=-d;else if(k>d&&1.001*d>k)k=d;else if(-d>k||k>d)return null;return j>Math.PI&&(j-=2*Math.PI),g=Math.sin(k),i=Math.cos(k),h=g*g,f=this.a/Math.sqrt(1-this.es*h),b=(f+l)*i*Math.cos(j),c=(f+l)*i*Math.sin(j),e=(f*(1-this.es)+l)*g,a.x=b,a.y=c,a.z=e,m},geocentric_to_geodetic:function(a){var b,c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t=1e-12,u=t*t,v=30,w=a.x,x=a.y,y=a.z?a.z:0;if(o=!1,b=Math.sqrt(w*w+x*x),c=Math.sqrt(w*w+x*x+y*y),b/this.au&&v>p);return r=Math.atan(m/Math.abs(l)),a.x=q,a.y=r,a.z=s,a},geocentric_to_geodetic_noniter:function(a){var b,c,e,f,g,h,i,j,m,n,o,p,q,r,s,t,u,v=a.x,w=a.y,x=a.z?a.z:0;if(v=parseFloat(v),w=parseFloat(w),x=parseFloat(x),u=!1,0!==v)b=Math.atan2(w,v);else if(w>0)b=d;else if(0>w)b=-d;else if(u=!0,b=0,x>0)c=d;else{if(!(0>x))return c=d,void(e=-this.b);c=-d}return g=v*v+w*w,f=Math.sqrt(g),h=x*k,j=Math.sqrt(h*h+g),n=h/j,p=f/j,o=n*n*n,i=x+this.b*this.ep2*o,t=f-this.a*this.es*p*p*p,m=Math.sqrt(i*i+t*t),q=i/m,r=t/m,s=this.a/Math.sqrt(1-this.es*q*q),e=r>=l?f/r-s:-l>=r?f/-r-s:x/q+s*(this.es-1),u===!1&&(c=Math.atan(q/r)),a.x=b,a.y=c,a.z=e,a},geocentric_to_wgs84:function(a){if(this.datum_type===e)a.x+=this.datum_params[0],a.y+=this.datum_params[1],a.z+=this.datum_params[2];else if(this.datum_type===f){var b=this.datum_params[0],c=this.datum_params[1],d=this.datum_params[2],g=this.datum_params[3],h=this.datum_params[4],i=this.datum_params[5],j=this.datum_params[6],k=j*(a.x-i*a.y+h*a.z)+b,l=j*(i*a.x+a.y-g*a.z)+c,m=j*(-h*a.x+g*a.y+a.z)+d;a.x=k,a.y=l,a.z=m}},geocentric_from_wgs84:function(a){if(this.datum_type===e)a.x-=this.datum_params[0],a.y-=this.datum_params[1],a.z-=this.datum_params[2];else if(this.datum_type===f){var b=this.datum_params[0],c=this.datum_params[1],d=this.datum_params[2],g=this.datum_params[3],h=this.datum_params[4],i=this.datum_params[5],j=this.datum_params[6],k=(a.x-b)/j,l=(a.y-c)/j,m=(a.z-d)/j;a.x=k+i*l-h*m,a.y=-i*k+l+g*m,a.z=h*k-g*l+m}}},b.exports=m},{}],31:[function(a,b,c){var d=1,e=2,f=3,g=5,h=6378137,i=.006694379990141316;b.exports=function(a,b,c){function j(a){return a===d||a===e}var k,l,m;if(a.compare_datums(b))return c;if(a.datum_type===g||b.datum_type===g)return c;var n=a.a,o=a.es,p=b.a,q=b.es,r=a.datum_type;if(r===f)if(0===this.apply_gridshift(a,0,c))a.a=h,a.es=i;else{if(!a.datum_params)return a.a=n,a.es=a.es,c;for(k=1,l=0,m=a.datum_params.length;m>l;l++)k*=a.datum_params[l];if(0===k)return a.a=n,a.es=a.es,c;r=a.datum_params.length>3?e:d}return b.datum_type===f&&(b.a=h,b.es=i),(a.es!==b.es||a.a!==b.a||j(r)||j(b.datum_type))&&(a.geodetic_to_geocentric(c),j(a.datum_type)&&a.geocentric_to_wgs84(c),j(b.datum_type)&&b.geocentric_from_wgs84(c),b.geocentric_to_geodetic(c)),b.datum_type===f&&this.apply_gridshift(b,1,c),a.a=n,a.es=o,b.a=p,b.es=q,c}},{}],32:[function(a,b,c){function d(a){var b=this;if(2===arguments.length){var c=arguments[1];"string"==typeof c?"+"===c.charAt(0)?d[a]=f(arguments[1]):d[a]=g(arguments[1]):d[a]=c}else if(1===arguments.length){if(Array.isArray(a))return a.map(function(a){Array.isArray(a)?d.apply(b,a):d(a)});if("string"==typeof a){if(a in d)return d[a]}else"EPSG"in a?d["EPSG:"+a.EPSG]=a:"ESRI"in a?d["ESRI:"+a.ESRI]=a:"IAU2000"in a?d["IAU2000:"+a.IAU2000]=a:console.log(a);return}}var e=a("./global"),f=a("./projString"),g=a("./wkt");e(d),b.exports=d},{"./global":35,"./projString":38,"./wkt":67}],33:[function(a,b,c){var d=a("./constants/Datum"),e=a("./constants/Ellipsoid"),f=a("./extend"),g=a("./datum"),h=1e-10,i=.16666666666666666,j=.04722222222222222,k=.022156084656084655;b.exports=function(a){if(a.datumCode&&"none"!==a.datumCode){var b=d[a.datumCode];b&&(a.datum_params=b.towgs84?b.towgs84.split(","):null,a.ellps=b.ellipse,a.datumName=b.datumName?b.datumName:a.datumCode)}if(!a.a){var c=e[a.ellps]?e[a.ellps]:e.WGS84;f(a,c)}return a.rf&&!a.b&&(a.b=(1-1/a.rf)*a.a),(0===a.rf||Math.abs(a.a-a.b)d?this.ns0=(this.ms1*this.ms1-this.ms2*this.ms2)/(this.qs2-this.qs1):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)},c.forward=function(a){var b=a.x,c=a.y;this.sin_phi=Math.sin(c),this.cos_phi=Math.cos(c);var d=f(this.e3,this.sin_phi,this.cos_phi),e=this.a*Math.sqrt(this.c-this.ns0*d)/this.ns0,h=this.ns0*g(b-this.long0),i=e*Math.sin(h)+this.x0,j=this.rh-e*Math.cos(h)+this.y0;return a.x=i,a.y=j,a},c.inverse=function(a){var b,c,d,e,f,h;return a.x-=this.x0,a.y=this.rh-a.y+this.y0,this.ns0>=0?(b=Math.sqrt(a.x*a.x+a.y*a.y),d=1):(b=-Math.sqrt(a.x*a.x+a.y*a.y),d=-1),e=0,0!==b&&(e=Math.atan2(d*a.x,d*a.y)),d=b*this.ns0/this.a,this.sphere?h=Math.asin((this.c-d*d)/(2*this.ns0)):(c=(this.c-d*d)/this.ns0,h=this.phi1z(this.e3,c)),f=g(e/this.ns0+this.long0),a.x=f,a.y=h,a},c.phi1z=function(a,b){var c,e,f,g,i,j=h(.5*b);if(d>a)return j;for(var k=a*a,l=1;25>=l;l++)if(c=Math.sin(j),e=Math.cos(j),f=a*c,g=1-f*f,i=.5*g*g/e*(b/(1-k)-c/g+.5/a*Math.log((1-f)/(1+f))),j+=i,Math.abs(i)<=1e-7)return j;return null},c.names=["Albers_Conic_Equal_Area","Albers","aea"]},{"../common/adjust_lon":5,"../common/asinz":6,"../common/msfnz":15,"../common/qsfnz":20}],41:[function(a,b,c){var d=a("../common/adjust_lon"),e=Math.PI/2,f=1e-10,g=a("../common/mlfn"),h=a("../common/e0fn"),i=a("../common/e1fn"),j=a("../common/e2fn"),k=a("../common/e3fn"),l=a("../common/gN"),m=a("../common/asinz"),n=a("../common/imlfn");c.init=function(){this.sin_p12=Math.sin(this.lat0),this.cos_p12=Math.cos(this.lat0)},c.forward=function(a){var b,c,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H=a.x,I=a.y,J=Math.sin(a.y),K=Math.cos(a.y),L=d(H-this.long0);return this.sphere?Math.abs(this.sin_p12-1)<=f?(a.x=this.x0+this.a*(e-I)*Math.sin(L),a.y=this.y0-this.a*(e-I)*Math.cos(L),a):Math.abs(this.sin_p12+1)<=f?(a.x=this.x0+this.a*(e+I)*Math.sin(L),a.y=this.y0+this.a*(e+I)*Math.cos(L),a):(B=this.sin_p12*J+this.cos_p12*K*Math.cos(L),z=Math.acos(B),A=z/Math.sin(z),a.x=this.x0+this.a*A*K*Math.sin(L),a.y=this.y0+this.a*A*(this.cos_p12*J-this.sin_p12*K*Math.cos(L)),a):(b=h(this.es),c=i(this.es),m=j(this.es),n=k(this.es),Math.abs(this.sin_p12-1)<=f?(o=this.a*g(b,c,m,n,e),p=this.a*g(b,c,m,n,I),a.x=this.x0+(o-p)*Math.sin(L),a.y=this.y0-(o-p)*Math.cos(L),a):Math.abs(this.sin_p12+1)<=f?(o=this.a*g(b,c,m,n,e),p=this.a*g(b,c,m,n,I),a.x=this.x0+(o+p)*Math.sin(L),a.y=this.y0+(o+p)*Math.cos(L),a):(q=J/K,r=l(this.a,this.e,this.sin_p12),s=l(this.a,this.e,J),t=Math.atan((1-this.es)*q+this.es*r*this.sin_p12/(s*K)),u=Math.atan2(Math.sin(L),this.cos_p12*Math.tan(t)-this.sin_p12*Math.cos(L)),C=0===u?Math.asin(this.cos_p12*Math.sin(t)-this.sin_p12*Math.cos(t)):Math.abs(Math.abs(u)-Math.PI)<=f?-Math.asin(this.cos_p12*Math.sin(t)-this.sin_p12*Math.cos(t)):Math.asin(Math.sin(L)*Math.cos(t)/Math.sin(u)),v=this.e*this.sin_p12/Math.sqrt(1-this.es),w=this.e*this.cos_p12*Math.cos(u)/Math.sqrt(1-this.es),x=v*w,y=w*w,D=C*C,E=D*C,F=E*C,G=F*C,z=r*C*(1-D*y*(1-y)/6+E/8*x*(1-2*y)+F/120*(y*(4-7*y)-3*v*v*(1-7*y))-G/48*x),a.x=this.x0+z*Math.sin(u),a.y=this.y0+z*Math.cos(u),a))},c.inverse=function(a){a.x-=this.x0,a.y-=this.y0;var b,c,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I;if(this.sphere){if(b=Math.sqrt(a.x*a.x+a.y*a.y),b>2*e*this.a)return;return c=b/this.a,o=Math.sin(c),p=Math.cos(c),q=this.long0,Math.abs(b)<=f?r=this.lat0:(r=m(p*this.sin_p12+a.y*o*this.cos_p12/b),s=Math.abs(this.lat0)-e,q=d(Math.abs(s)<=f?this.lat0>=0?this.long0+Math.atan2(a.x,-a.y):this.long0-Math.atan2(-a.x,a.y):this.long0+Math.atan2(a.x*o,b*this.cos_p12*p-a.y*this.sin_p12*o))),a.x=q,a.y=r,a}return t=h(this.es),u=i(this.es),v=j(this.es),w=k(this.es),Math.abs(this.sin_p12-1)<=f?(x=this.a*g(t,u,v,w,e),b=Math.sqrt(a.x*a.x+a.y*a.y),y=x-b,r=n(y/this.a,t,u,v,w),q=d(this.long0+Math.atan2(a.x,-1*a.y)),a.x=q,a.y=r,a):Math.abs(this.sin_p12+1)<=f?(x=this.a*g(t,u,v,w,e),b=Math.sqrt(a.x*a.x+a.y*a.y),y=b-x,r=n(y/this.a,t,u,v,w),q=d(this.long0+Math.atan2(a.x,a.y)),a.x=q,a.y=r,a):(b=Math.sqrt(a.x*a.x+a.y*a.y),B=Math.atan2(a.x,a.y),z=l(this.a,this.e,this.sin_p12),C=Math.cos(B),D=this.e*this.cos_p12*C,E=-D*D/(1-this.es),F=3*this.es*(1-E)*this.sin_p12*this.cos_p12*C/(1-this.es),G=b/z,H=G-E*(1+E)*Math.pow(G,3)/6-F*(1+3*E)*Math.pow(G,4)/24,I=1-E*H*H/2-G*H*H*H/6,A=Math.asin(this.sin_p12*Math.cos(H)+this.cos_p12*Math.sin(H)*C),q=d(this.long0+Math.asin(Math.sin(B)*Math.sin(H)/Math.cos(A))),r=Math.atan((1-this.es*I*this.sin_p12/Math.sin(A))*Math.tan(A)/(1-this.es)),a.x=q,a.y=r,a)},c.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(a,b,c){var d=a("../common/mlfn"),e=a("../common/e0fn"),f=a("../common/e1fn"),g=a("../common/e2fn"),h=a("../common/e3fn"),i=a("../common/gN"),j=a("../common/adjust_lon"),k=a("../common/adjust_lat"),l=a("../common/imlfn"),m=Math.PI/2,n=1e-10;c.init=function(){this.sphere||(this.e0=e(this.es),this.e1=f(this.es),this.e2=g(this.es),this.e3=h(this.es),this.ml0=this.a*d(this.e0,this.e1,this.e2,this.e3,this.lat0))},c.forward=function(a){var b,c,e=a.x,f=a.y;if(e=j(e-this.long0),this.sphere)b=this.a*Math.asin(Math.cos(f)*Math.sin(e)),c=this.a*(Math.atan2(Math.tan(f),Math.cos(e))-this.lat0);else{var g=Math.sin(f),h=Math.cos(f),k=i(this.a,this.e,g),l=Math.tan(f)*Math.tan(f),m=e*Math.cos(f),n=m*m,o=this.es*h*h/(1-this.es),p=this.a*d(this.e0,this.e1,this.e2,this.e3,f);b=k*m*(1-n*l*(1/6-(8-l+8*o)*n/120)),c=p-this.ml0+k*g/h*n*(.5+(5-l+6*o)*n/24)}return a.x=b+this.x0,a.y=c+this.y0,a},c.inverse=function(a){a.x-=this.x0,a.y-=this.y0;var b,c,d=a.x/this.a,e=a.y/this.a;if(this.sphere){var f=e+this.lat0;b=Math.asin(Math.sin(f)*Math.cos(d)),c=Math.atan2(Math.tan(d),Math.cos(f))}else{var g=this.ml0/this.a+e,h=l(g,this.e0,this.e1,this.e2,this.e3);if(Math.abs(Math.abs(h)-m)<=n)return a.x=this.long0,a.y=m,0>e&&(a.y*=-1),a;var o=i(this.a,this.e,Math.sin(h)),p=o*o*o/this.a/this.a*(1-this.es),q=Math.pow(Math.tan(h),2),r=d*this.a/o,s=r*r;b=h-o*Math.tan(h)/p*r*r*(.5-(1+3*q)*r*r/24),c=r*(1-s*(q/3+(1+3*q)*q*s/15))/Math.cos(h)}return a.x=j(c+this.long0),a.y=k(b),a},c.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(a,b,c){var d=a("../common/adjust_lon"),e=a("../common/qsfnz"),f=a("../common/msfnz"),g=a("../common/iqsfnz");c.init=function(){this.sphere||(this.k0=f(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)))},c.forward=function(a){var b,c,f=a.x,g=a.y,h=d(f-this.long0);if(this.sphere)b=this.x0+this.a*h*Math.cos(this.lat_ts),c=this.y0+this.a*Math.sin(g)/Math.cos(this.lat_ts);else{var i=e(this.e,Math.sin(g));b=this.x0+this.a*this.k0*h,c=this.y0+this.a*i*.5/this.k0}return a.x=b,a.y=c,a},c.inverse=function(a){a.x-=this.x0,a.y-=this.y0;var b,c;return this.sphere?(b=d(this.long0+a.x/this.a/Math.cos(this.lat_ts)),c=Math.asin(a.y/this.a*Math.cos(this.lat_ts))):(c=g(this.e,2*a.y*this.k0/this.a),b=d(this.long0+a.x/(this.a*this.k0))),a.x=b,a.y=c,a},c.names=["cea"]},{"../common/adjust_lon":5,"../common/iqsfnz":13,"../common/msfnz":15,"../common/qsfnz":20}],44:[function(a,b,c){var d=a("../common/adjust_lon"),e=a("../common/adjust_lat");c.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)},c.forward=function(a){var b=a.x,c=a.y,f=d(b-this.long0),g=e(c-this.lat0);return a.x=this.x0+this.a*f*this.rc,a.y=this.y0+this.a*g,a},c.inverse=function(a){var b=a.x,c=a.y;return a.x=d(this.long0+(b-this.x0)/(this.a*this.rc)),a.y=e(this.lat0+(c-this.y0)/this.a),a},c.names=["Equirectangular","Equidistant_Cylindrical","eqc"]},{"../common/adjust_lat":4,"../common/adjust_lon":5}],45:[function(a,b,c){var d=a("../common/e0fn"),e=a("../common/e1fn"),f=a("../common/e2fn"),g=a("../common/e3fn"),h=a("../common/msfnz"),i=a("../common/mlfn"),j=a("../common/adjust_lon"),k=a("../common/adjust_lat"),l=a("../common/imlfn"),m=1e-10;c.init=function(){Math.abs(this.lat1+this.lat2)=0?(c=Math.sqrt(a.x*a.x+a.y*a.y),b=1):(c=-Math.sqrt(a.x*a.x+a.y*a.y),b=-1);var f=0;if(0!==c&&(f=Math.atan2(b*a.x,b*a.y)),this.sphere)return e=j(this.long0+f/this.ns),d=k(this.g-c/this.a),a.x=e,a.y=d,a;var g=this.g-c/this.a;return d=l(g,this.e0,this.e1,this.e2,this.e3),e=j(this.long0+f/this.ns),a.x=e,a.y=d,a},c.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(a,b,c){var d=Math.PI/4,e=a("../common/srat"),f=Math.PI/2,g=20;c.init=function(){var a=Math.sin(this.lat0),b=Math.cos(this.lat0);b*=b,this.rc=Math.sqrt(1-this.es)/(1-this.es*a*a),this.C=Math.sqrt(1+this.es*b*b/(1-this.es)),this.phic0=Math.asin(a/this.C),this.ratexp=.5*this.C*this.e,this.K=Math.tan(.5*this.phic0+d)/(Math.pow(Math.tan(.5*this.lat0+d),this.C)*e(this.e*a,this.ratexp))},c.forward=function(a){var b=a.x,c=a.y;return a.y=2*Math.atan(this.K*Math.pow(Math.tan(.5*c+d),this.C)*e(this.e*Math.sin(c),this.ratexp))-f,a.x=this.C*b,a},c.inverse=function(a){for(var b=1e-14,c=a.x/this.C,h=a.y,i=Math.pow(Math.tan(.5*h+d)/this.K,1/this.C),j=g;j>0&&(h=2*Math.atan(i*e(this.e*Math.sin(a.y),-.5*this.e))-f,!(Math.abs(h-a.y)0||Math.abs(i)<=e?(j=this.x0+this.a*h*c*Math.sin(f)/i,k=this.y0+this.a*h*(this.cos_p14*b-this.sin_p14*c*g)/i):(j=this.x0+this.infinity_dist*c*Math.sin(f),k=this.y0+this.infinity_dist*(this.cos_p14*b-this.sin_p14*c*g)),a.x=j,a.y=k,a},c.inverse=function(a){var b,c,e,g,h,i;return a.x=(a.x-this.x0)/this.a,a.y=(a.y-this.y0)/this.a,a.x/=this.k0,a.y/=this.k0,(b=Math.sqrt(a.x*a.x+a.y*a.y))?(g=Math.atan2(b,this.rc),c=Math.sin(g),e=Math.cos(g),i=f(e*this.sin_p14+a.y*c*this.cos_p14/b),h=Math.atan2(a.x*c,b*this.cos_p14*e-a.y*this.sin_p14*c),h=d(this.long0+h)):(i=this.phic0,h=0),a.x=h,a.y=i,a},c.names=["gnom"]},{"../common/adjust_lon":5,"../common/asinz":6}],49:[function(a,b,c){var d=a("../common/adjust_lon");c.init=function(){this.a=6377397.155,this.es=.006674372230614,this.e=Math.sqrt(this.es),this.lat0||(this.lat0=.863937979737193),this.long0||(this.long0=.4334234309119251),this.k0||(this.k0=.9999),this.s45=.785398163397448,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},c.forward=function(a){var b,c,e,f,g,h,i,j=a.x,k=a.y,l=d(j-this.long0);return b=Math.pow((1+this.e*Math.sin(k))/(1-this.e*Math.sin(k)),this.alfa*this.e/2),c=2*(Math.atan(this.k*Math.pow(Math.tan(k/2+this.s45),this.alfa)/b)-this.s45),e=-l*this.alfa,f=Math.asin(Math.cos(this.ad)*Math.sin(c)+Math.sin(this.ad)*Math.cos(c)*Math.cos(e)),g=Math.asin(Math.cos(c)*Math.sin(e)/Math.cos(f)),h=this.n*g,i=this.ro0*Math.pow(Math.tan(this.s0/2+this.s45),this.n)/Math.pow(Math.tan(f/2+this.s45),this.n),a.y=i*Math.cos(h)/1,a.x=i*Math.sin(h)/1,this.czech||(a.y*=-1,a.x*=-1),a},c.inverse=function(a){var b,c,d,e,f,g,h,i,j=a.x;a.x=a.y,a.y=j,this.czech||(a.y*=-1,a.x*=-1),g=Math.sqrt(a.x*a.x+a.y*a.y),f=Math.atan2(a.y,a.x),e=f/Math.sin(this.s0),d=2*(Math.atan(Math.pow(this.ro0/g,1/this.n)*Math.tan(this.s0/2+this.s45))-this.s45),b=Math.asin(Math.cos(this.ad)*Math.sin(d)-Math.sin(this.ad)*Math.cos(d)*Math.cos(e)),c=Math.asin(Math.cos(d)*Math.sin(e)/Math.cos(b)),a.x=this.long0-c/this.alfa,h=b,i=0;var k=0;do a.y=2*(Math.atan(Math.pow(this.k,-1/this.alfa)*Math.pow(Math.tan(b/2+this.s45),1/this.alfa)*Math.pow((1+this.e*Math.sin(h))/(1-this.e*Math.sin(h)),this.e/2))-this.s45),Math.abs(h-a.y)<1e-10&&(i=1),h=a.y,k+=1;while(0===i&&15>k);return k>=15?null:a},c.names=["Krovak","krovak"]},{"../common/adjust_lon":5}],50:[function(a,b,c){var d=Math.PI/2,e=Math.PI/4,f=1e-10,g=a("../common/qsfnz"),h=a("../common/adjust_lon");c.S_POLE=1,c.N_POLE=2,c.EQUIT=3,c.OBLIQ=4,c.init=function(){var a=Math.abs(this.lat0);if(Math.abs(a-d)0){var b;switch(this.qp=g(this.e,1),this.mmf=.5/(1-this.es),this.apa=this.authset(this.es),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(.5*this.qp),this.dd=1/this.rq,this.xmf=1,this.ymf=.5*this.qp;break;case this.OBLIQ:this.rq=Math.sqrt(.5*this.qp),b=Math.sin(this.lat0),this.sinb1=g(this.e,b)/this.qp,this.cosb1=Math.sqrt(1-this.sinb1*this.sinb1),this.dd=Math.cos(this.lat0)/(Math.sqrt(1-this.es*b*b)*this.rq*this.cosb1),this.ymf=(this.xmf=this.rq)/this.dd,this.xmf*=this.dd}}else this.mode===this.OBLIQ&&(this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0))},c.forward=function(a){var b,c,i,j,k,l,m,n,o,p,q=a.x,r=a.y;if(q=h(q-this.long0),this.sphere){if(k=Math.sin(r),p=Math.cos(r),i=Math.cos(q),this.mode===this.OBLIQ||this.mode===this.EQUIT){if(c=this.mode===this.EQUIT?1+p*i:1+this.sinph0*k+this.cosph0*p*i,f>=c)return null;c=Math.sqrt(2/c),b=c*p*Math.sin(q),c*=this.mode===this.EQUIT?k:this.cosph0*k-this.sinph0*p*i}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(i=-i),Math.abs(r+this.phi0)=0?(b=(o=Math.sqrt(l))*j,c=i*(this.mode===this.S_POLE?o:-o)):b=c=0}}return a.x=this.a*b+this.x0,a.y=this.a*c+this.y0,a},c.inverse=function(a){a.x-=this.x0,a.y-=this.y0;var b,c,e,g,i,j,k,l=a.x/this.a,m=a.y/this.a;if(this.sphere){var n,o=0,p=0;if(n=Math.sqrt(l*l+m*m),c=.5*n,c>1)return null;switch(c=2*Math.asin(c),(this.mode===this.OBLIQ||this.mode===this.EQUIT)&&(p=Math.sin(c),o=Math.cos(c)),this.mode){case this.EQUIT:c=Math.abs(n)<=f?0:Math.asin(m*p/n),l*=p,m=o*n;break;case this.OBLIQ:c=Math.abs(n)<=f?this.phi0:Math.asin(o*this.sinph0+m*p*this.cosph0/n),l*=p*this.cosph0,m=(o-Math.sin(c)*this.sinph0)*n;break;case this.N_POLE:m=-m,c=d-c;break;case this.S_POLE:c-=d}b=0!==m||this.mode!==this.EQUIT&&this.mode!==this.OBLIQ?Math.atan2(l,m):0}else{if(k=0,this.mode===this.OBLIQ||this.mode===this.EQUIT){if(l/=this.dd,m*=this.dd,j=Math.sqrt(l*l+m*m),f>j)return a.x=0,a.y=this.phi0,a;g=2*Math.asin(.5*j/this.rq),e=Math.cos(g),l*=g=Math.sin(g),this.mode===this.OBLIQ?(k=e*this.sinb1+m*g*this.cosb1/j,i=this.qp*k,m=j*this.cosb1*e-m*this.sinb1*g):(k=m*g/j,i=this.qp*k,m=j*e)}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(m=-m),i=l*l+m*m,!i)return a.x=0,a.y=this.phi0,a;k=1-i/this.qp,this.mode===this.S_POLE&&(k=-k)}b=Math.atan2(l,m),c=this.authlat(Math.asin(k),this.apa)}return a.x=h(this.long0+b),a.y=c,a},c.P00=.3333333333333333,c.P01=.17222222222222222,c.P02=.10257936507936508,c.P10=.06388888888888888,c.P11=.0664021164021164,c.P20=.016415012942191543,c.authset=function(a){var b,c=[];return c[0]=a*this.P00,b=a*a,c[0]+=b*this.P01,c[1]=b*this.P10,b*=a,c[0]+=b*this.P02,c[1]+=b*this.P11,c[2]=b*this.P20,c},c.authlat=function(a,b){var c=a+a;return a+b[0]*Math.sin(c)+b[1]*Math.sin(c+c)+b[2]*Math.sin(c+c+c)},c.names=["Lambert Azimuthal Equal Area","Lambert_Azimuthal_Equal_Area","laea"]},{"../common/adjust_lon":5,"../common/qsfnz":20}],51:[function(a,b,c){var d=1e-10,e=a("../common/msfnz"),f=a("../common/tsfnz"),g=Math.PI/2,h=a("../common/sign"),i=a("../common/adjust_lon"),j=a("../common/phi2z");c.init=function(){if(this.lat2||(this.lat2=this.lat1),this.k0||(this.k0=1),this.x0=this.x0||0,this.y0=this.y0||0,!(Math.abs(this.lat1+this.lat2)d?this.ns=Math.log(g/k)/Math.log(h/l):this.ns=b,isNaN(this.ns)&&(this.ns=b),this.f0=g/(this.ns*Math.pow(h,this.ns)),this.rh=this.a*this.f0*Math.pow(m,this.ns),this.title||(this.title="Lambert Conformal Conic")}},c.forward=function(a){var b=a.x,c=a.y;Math.abs(2*Math.abs(c)-Math.PI)<=d&&(c=h(c)*(g-2*d));var e,j,k=Math.abs(Math.abs(c)-g);if(k>d)e=f(this.e,c,Math.sin(c)),j=this.a*this.f0*Math.pow(e,this.ns);else{if(k=c*this.ns,0>=k)return null;j=0}var l=this.ns*i(b-this.long0);return a.x=this.k0*(j*Math.sin(l))+this.x0,a.y=this.k0*(this.rh-j*Math.cos(l))+this.y0,a},c.inverse=function(a){var b,c,d,e,f,h=(a.x-this.x0)/this.k0,k=this.rh-(a.y-this.y0)/this.k0;this.ns>0?(b=Math.sqrt(h*h+k*k),c=1):(b=-Math.sqrt(h*h+k*k),c=-1);var l=0;if(0!==b&&(l=Math.atan2(c*h,c*k)),0!==b||this.ns>0){if(c=1/this.ns,d=Math.pow(b/(this.a*this.f0),c),e=j(this.e,d),-9999===e)return null}else e=-g;return f=i(l/this.ns+this.long0),a.x=f,a.y=e,a},c.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}],52:[function(a,b,c){function d(a){return a}c.init=function(){},c.forward=d,c.inverse=d,c.names=["longlat","identity"]},{}],53:[function(a,b,c){var d=a("../common/msfnz"),e=Math.PI/2,f=1e-10,g=57.29577951308232,h=a("../common/adjust_lon"),i=Math.PI/4,j=a("../common/tsfnz"),k=a("../common/phi2z");c.init=function(){var a=this.b/this.a;this.es=1-a*a,"x0"in this||(this.x0=0),"y0"in this||(this.y0=0),this.e=Math.sqrt(this.es),this.lat_ts?this.sphere?this.k0=Math.cos(this.lat_ts):this.k0=d(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)):this.k0||(this.k?this.k0=this.k:this.k0=1)},c.forward=function(a){var b=a.x,c=a.y;if(c*g>90&&-90>c*g&&b*g>180&&-180>b*g)return null;var d,k;if(Math.abs(Math.abs(c)-e)<=f)return null;if(this.sphere)d=this.x0+this.a*this.k0*h(b-this.long0),k=this.y0+this.a*this.k0*Math.log(Math.tan(i+.5*c));else{var l=Math.sin(c),m=j(this.e,c,l);d=this.x0+this.a*this.k0*h(b-this.long0),k=this.y0-this.a*this.k0*Math.log(m)}return a.x=d,a.y=k,a},c.inverse=function(a){var b,c,d=a.x-this.x0,f=a.y-this.y0;if(this.sphere)c=e-2*Math.atan(Math.exp(-f/(this.a*this.k0)));else{var g=Math.exp(-f/(this.a*this.k0));if(c=k(this.e,g),-9999===c)return null}return b=h(this.long0+d/(this.a*this.k0)),a.x=b,a.y=c,a},c.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}],54:[function(a,b,c){var d=a("../common/adjust_lon");c.init=function(){},c.forward=function(a){var b=a.x,c=a.y,e=d(b-this.long0),f=this.x0+this.a*e,g=this.y0+this.a*Math.log(Math.tan(Math.PI/4+c/2.5))*1.25;return a.x=f,a.y=g,a},c.inverse=function(a){a.x-=this.x0,a.y-=this.y0;var b=d(this.long0+a.x/this.a),c=2.5*(Math.atan(Math.exp(.8*a.y/this.a))-Math.PI/4);return a.x=b,a.y=c,a},c.names=["Miller_Cylindrical","mill"]},{"../common/adjust_lon":5}],55:[function(a,b,c){var d=a("../common/adjust_lon"),e=1e-10;c.init=function(){},c.forward=function(a){for(var b=a.x,c=a.y,f=d(b-this.long0),g=c,h=Math.PI*Math.sin(c),i=0;!0;i++){var j=-(g+Math.sin(g)-h)/(1+Math.cos(g));if(g+=j,Math.abs(j).999999999999&&(c=.999999999999),b=Math.asin(c);var e=d(this.long0+a.x/(.900316316158*this.a*Math.cos(b)));e<-Math.PI&&(e=-Math.PI),e>Math.PI&&(e=Math.PI),c=(2*b+Math.sin(2*b))/Math.PI,Math.abs(c)>1&&(c=1);var f=Math.asin(c);return a.x=e,a.y=f,a},c.names=["Mollweide","moll"]},{"../common/adjust_lon":5}],56:[function(a,b,c){var d=484813681109536e-20;c.iterations=1,c.init=function(){this.A=[],this.A[1]=.6399175073,this.A[2]=-.1358797613,this.A[3]=.063294409,this.A[4]=-.02526853,this.A[5]=.0117879,this.A[6]=-.0055161,this.A[7]=.0026906,this.A[8]=-.001333,this.A[9]=67e-5,this.A[10]=-34e-5,this.B_re=[],this.B_im=[],this.B_re[1]=.7557853228,this.B_im[1]=0,this.B_re[2]=.249204646,this.B_im[2]=.003371507,this.B_re[3]=-.001541739,this.B_im[3]=.04105856,this.B_re[4]=-.10162907,this.B_im[4]=.01727609,this.B_re[5]=-.26623489,this.B_im[5]=-.36249218,this.B_re[6]=-.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]=-.577245789,this.C_im[2]=-.007809598,this.C_re[3]=.508307513,this.C_im[3]=-.112208952,this.C_re[4]=-.15094762,this.C_im[4]=.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]=.5185406398,this.D[3]=-.03333098,this.D[4]=-.1052906,this.D[5]=-.0368594,this.D[6]=.007317,this.D[7]=.0122,this.D[8]=.00394,this.D[9]=-.0013},c.forward=function(a){var b,c=a.x,e=a.y,f=e-this.lat0,g=c-this.long0,h=f/d*1e-5,i=g,j=1,k=0;for(b=1;10>=b;b++)j*=h,k+=this.A[b]*j;var l,m,n=k,o=i,p=1,q=0,r=0,s=0;for(b=1;6>=b;b++)l=p*n-q*o,m=q*n+p*o,p=l,q=m,r=r+this.B_re[b]*p-this.B_im[b]*q,s=s+this.B_im[b]*p+this.B_re[b]*q;return a.x=s*this.a+this.x0,a.y=r*this.a+this.y0,a},c.inverse=function(a){var b,c,e,f=a.x,g=a.y,h=f-this.x0,i=g-this.y0,j=i/this.a,k=h/this.a,l=1,m=0,n=0,o=0;for(b=1;6>=b;b++)c=l*j-m*k,e=m*j+l*k,l=c,m=e,n=n+this.C_re[b]*l-this.C_im[b]*m,o=o+this.C_im[b]*l+this.C_re[b]*m;for(var p=0;p=b;b++)q=s*n-t*o,r=t*n+s*o,s=q,t=r,u+=(b-1)*(this.B_re[b]*s-this.B_im[b]*t),v+=(b-1)*(this.B_im[b]*s+this.B_re[b]*t);s=1,t=0;var w=this.B_re[1],x=this.B_im[1];for(b=2;6>=b;b++)q=s*n-t*o,r=t*n+s*o,s=q,t=r,w+=b*(this.B_re[b]*s-this.B_im[b]*t),x+=b*(this.B_im[b]*s+this.B_re[b]*t);var y=w*w+x*x;n=(u*w+v*x)/y,o=(v*w-u*x)/y}var z=n,A=o,B=1,C=0;for(b=1;9>=b;b++)B*=z,C+=this.D[b]*B;var D=this.lat0+C*d*1e5,E=this.long0+A;return a.x=E,a.y=D,a},c.names=["New_Zealand_Map_Grid","nzmg"]},{}],57:[function(a,b,c){var d=a("../common/tsfnz"),e=a("../common/adjust_lon"),f=a("../common/phi2z"),g=Math.PI/2,h=Math.PI/4,i=1e-10;c.init=function(){this.no_off=this.no_off||!1,this.no_rot=this.no_rot||!1,isNaN(this.k0)&&(this.k0=1);var a=Math.sin(this.lat0),b=Math.cos(this.lat0),c=this.e*a;this.bl=Math.sqrt(1+this.es/(1-this.es)*Math.pow(b,4)),this.al=this.a*this.bl*this.k0*Math.sqrt(1-this.es)/(1-c*c);var f=d(this.e,this.lat0,a),g=this.bl/b*Math.sqrt((1-this.es)/(1-c*c));1>g*g&&(g=1);var h,i;if(isNaN(this.longc)){var j=d(this.e,this.lat1,Math.sin(this.lat1)),k=d(this.e,this.lat2,Math.sin(this.lat2));this.lat0>=0?this.el=(g+Math.sqrt(g*g-1))*Math.pow(f,this.bl):this.el=(g-Math.sqrt(g*g-1))*Math.pow(f,this.bl);var l=Math.pow(j,this.bl),m=Math.pow(k,this.bl);h=this.el/l,i=.5*(h-1/h);var n=(this.el*this.el-m*l)/(this.el*this.el+m*l),o=(m-l)/(m+l),p=e(this.long1-this.long2);this.long0=.5*(this.long1+this.long2)-Math.atan(n*Math.tan(.5*this.bl*p)/o)/this.bl,this.long0=e(this.long0);var q=e(this.long1-this.long0);this.gamma0=Math.atan(Math.sin(this.bl*q)/i),this.alpha=Math.asin(g*Math.sin(this.gamma0))}else h=this.lat0>=0?g+Math.sqrt(g*g-1):g-Math.sqrt(g*g-1),this.el=h*Math.pow(f,this.bl),i=.5*(h-1/h),this.gamma0=Math.asin(Math.sin(this.alpha)/g),this.long0=this.longc-Math.asin(i*Math.tan(this.gamma0))/this.bl;this.no_off?this.uc=0:this.lat0>=0?this.uc=this.al/this.bl*Math.atan2(Math.sqrt(g*g-1),Math.cos(this.alpha)):this.uc=-1*this.al/this.bl*Math.atan2(Math.sqrt(g*g-1),Math.cos(this.alpha))},c.forward=function(a){var b,c,f,j=a.x,k=a.y,l=e(j-this.long0);if(Math.abs(Math.abs(k)-g)<=i)f=k>0?-1:1,c=this.al/this.bl*Math.log(Math.tan(h+f*this.gamma0*.5)),b=-1*f*g*this.al/this.bl;else{var m=d(this.e,k,Math.sin(k)),n=this.el/Math.pow(m,this.bl),o=.5*(n-1/n),p=.5*(n+1/n),q=Math.sin(this.bl*l),r=(o*Math.sin(this.gamma0)-q*Math.cos(this.gamma0))/p;c=Math.abs(Math.abs(r)-1)<=i?Number.POSITIVE_INFINITY:.5*this.al*Math.log((1-r)/(1+r))/this.bl,b=Math.abs(Math.cos(this.bl*l))<=i?this.al*this.bl*l:this.al*Math.atan2(o*Math.cos(this.gamma0)+q*Math.sin(this.gamma0),Math.cos(this.bl*l))/this.bl}return this.no_rot?(a.x=this.x0+b,a.y=this.y0+c):(b-=this.uc,a.x=this.x0+c*Math.cos(this.alpha)+b*Math.sin(this.alpha),a.y=this.y0+b*Math.cos(this.alpha)-c*Math.sin(this.alpha)),a},c.inverse=function(a){var b,c;this.no_rot?(c=a.y-this.y0,b=a.x-this.x0):(c=(a.x-this.x0)*Math.cos(this.alpha)-(a.y-this.y0)*Math.sin(this.alpha),b=(a.y-this.y0)*Math.cos(this.alpha)+(a.x-this.x0)*Math.sin(this.alpha),b+=this.uc);var d=Math.exp(-1*this.bl*c/this.al),h=.5*(d-1/d),j=.5*(d+1/d),k=Math.sin(this.bl*b/this.al),l=(k*Math.cos(this.gamma0)+h*Math.sin(this.gamma0))/j,m=Math.pow(this.el/Math.sqrt((1+l)/(1-l)),1/this.bl);return Math.abs(l-1)g?(g=Math.sin(b),c=this.long0+a.x*Math.sqrt(1-this.es*g*g)/(this.a*Math.cos(b)),f=d(c)):j>g-k&&(f=this.long0)),a.x=f,a.y=b,a},c.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}],60:[function(a,b,c){c.init=function(){var a=this.lat0;this.lambda0=this.long0;var b=Math.sin(a),c=this.a,d=this.rf,e=1/d,f=2*e-Math.pow(e,2),g=this.e=Math.sqrt(f);this.R=this.k0*c*Math.sqrt(1-f)/(1-f*Math.pow(b,2)),this.alpha=Math.sqrt(1+f/(1-f)*Math.pow(Math.cos(a),4)),this.b0=Math.asin(b/this.alpha);var h=Math.log(Math.tan(Math.PI/4+this.b0/2)),i=Math.log(Math.tan(Math.PI/4+a/2)),j=Math.log((1+g*b)/(1-g*b));this.K=h-this.alpha*i+this.alpha*g/2*j},c.forward=function(a){var b=Math.log(Math.tan(Math.PI/4-a.y/2)),c=this.e/2*Math.log((1+this.e*Math.sin(a.y))/(1-this.e*Math.sin(a.y))),d=-this.alpha*(b+c)+this.K,e=2*(Math.atan(Math.exp(d))-Math.PI/4),f=this.alpha*(a.x-this.lambda0),g=Math.atan(Math.sin(f)/(Math.sin(this.b0)*Math.tan(e)+Math.cos(this.b0)*Math.cos(f))),h=Math.asin(Math.cos(this.b0)*Math.sin(e)-Math.sin(this.b0)*Math.cos(e)*Math.cos(f));return a.y=this.R/2*Math.log((1+Math.sin(h))/(1-Math.sin(h)))+this.y0,a.x=this.R*g+this.x0,a},c.inverse=function(a){for(var b=a.x-this.x0,c=a.y-this.y0,d=b/this.R,e=2*(Math.atan(Math.exp(c/this.R))-Math.PI/4),f=Math.asin(Math.cos(this.b0)*Math.sin(e)+Math.sin(this.b0)*Math.cos(e)*Math.cos(d)),g=Math.atan(Math.sin(d)/(Math.cos(this.b0)*Math.cos(d)-Math.sin(this.b0)*Math.tan(e))),h=this.lambda0+g/this.alpha,i=0,j=f,k=-1e3,l=0;Math.abs(j-k)>1e-7;){if(++l>20)return;i=1/this.alpha*(Math.log(Math.tan(Math.PI/4+f/2))-this.K)+this.e*Math.log(Math.tan(Math.PI/4+Math.asin(this.e*Math.sin(j))/2)),k=j,j=2*Math.atan(Math.exp(i))-Math.PI/2}return a.x=h,a.y=j,a},c.names=["somerc"]},{}],61:[function(a,b,c){var d=Math.PI/2,e=1e-10,f=a("../common/sign"),g=a("../common/msfnz"),h=a("../common/tsfnz"),i=a("../common/phi2z"),j=a("../common/adjust_lon");c.ssfn_=function(a,b,c){return b*=c,Math.tan(.5*(d+a))*Math.pow((1-b)/(1+b),.5*c)},c.init=function(){this.coslat0=Math.cos(this.lat0),this.sinlat0=Math.sin(this.lat0),this.sphere?1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=e&&(this.k0=.5*(1+f(this.lat0)*Math.sin(this.lat_ts))):(Math.abs(this.coslat0)<=e&&(this.lat0>0?this.con=1:this.con=-1),this.cons=Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)),1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=e&&(this.k0=.5*this.cons*g(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts))/h(this.e,this.con*this.lat_ts,this.con*Math.sin(this.lat_ts))),this.ms1=g(this.e,this.sinlat0,this.coslat0),this.X0=2*Math.atan(this.ssfn_(this.lat0,this.sinlat0,this.e))-d,this.cosX0=Math.cos(this.X0),this.sinX0=Math.sin(this.X0))},c.forward=function(a){var b,c,f,g,i,k,l=a.x,m=a.y,n=Math.sin(m),o=Math.cos(m),p=j(l-this.long0);return Math.abs(Math.abs(l-this.long0)-Math.PI)<=e&&Math.abs(m+this.lat0)<=e?(a.x=NaN,a.y=NaN,a):this.sphere?(b=2*this.k0/(1+this.sinlat0*n+this.coslat0*o*Math.cos(p)),a.x=this.a*b*o*Math.sin(p)+this.x0,a.y=this.a*b*(this.coslat0*n-this.sinlat0*o*Math.cos(p))+this.y0,a):(c=2*Math.atan(this.ssfn_(m,n,this.e))-d,g=Math.cos(c),f=Math.sin(c),Math.abs(this.coslat0)<=e?(i=h(this.e,m*this.con,this.con*n),k=2*this.a*this.k0*i/this.cons,a.x=this.x0+k*Math.sin(l-this.long0),a.y=this.y0-this.con*k*Math.cos(l-this.long0),a):(Math.abs(this.sinlat0)=k?(a.x=b,a.y=c,a):(c=Math.asin(Math.cos(l)*this.sinlat0+a.y*Math.sin(l)*this.coslat0/k),b=j(Math.abs(this.coslat0)0?this.long0+Math.atan2(a.x,-1*a.y):this.long0+Math.atan2(a.x,a.y):this.long0+Math.atan2(a.x*Math.sin(l),k*this.coslat0*Math.cos(l)-a.y*this.sinlat0*Math.sin(l))),a.x=b,a.y=c,a)}if(Math.abs(this.coslat0)<=e){if(e>=k)return c=this.lat0,b=this.long0,a.x=b,a.y=c,a;a.x*=this.con,a.y*=this.con,f=k*this.cons/(2*this.a*this.k0),c=this.con*i(this.e,f),b=this.con*j(this.con*this.long0+Math.atan2(a.x,-1*a.y))}else g=2*Math.atan(k*this.cosX0/(2*this.a*this.k0*this.ms1)),b=this.long0,e>=k?h=this.X0:(h=Math.asin(Math.cos(g)*this.sinX0+a.y*Math.sin(g)*this.cosX0/k),b=j(this.long0+Math.atan2(a.x*Math.sin(g),k*this.cosX0*Math.cos(g)-a.y*this.sinX0*Math.sin(g)))),c=-1*i(this.e,Math.tan(.5*(d+h)));return a.x=b,a.y=c,a},c.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}],62:[function(a,b,c){var d=a("./gauss"),e=a("../common/adjust_lon");c.init=function(){d.init.apply(this),this.rc&&(this.sinc0=Math.sin(this.phic0),this.cosc0=Math.cos(this.phic0),this.R2=2*this.rc,this.title||(this.title="Oblique Stereographic Alternative"))},c.forward=function(a){var b,c,f,g;return a.x=e(a.x-this.long0),d.forward.apply(this,[a]),b=Math.sin(a.y),c=Math.cos(a.y),f=Math.cos(a.x),g=this.k0*this.R2/(1+this.sinc0*b+this.cosc0*c*f),a.x=g*c*Math.sin(a.x),a.y=g*(this.cosc0*b-this.sinc0*c*f),a.x=this.a*a.x+this.x0,a.y=this.a*a.y+this.y0,a},c.inverse=function(a){var b,c,f,g,h;if(a.x=(a.x-this.x0)/this.a,a.y=(a.y-this.y0)/this.a,a.x/=this.k0,a.y/=this.k0,h=Math.sqrt(a.x*a.x+a.y*a.y)){var i=2*Math.atan2(h,this.R2);b=Math.sin(i),c=Math.cos(i),g=Math.asin(c*this.sinc0+a.y*b*this.cosc0/h),f=Math.atan2(a.x*b,h*this.cosc0*c-a.y*this.sinc0*b)}else g=this.phic0,f=0;return a.x=f,a.y=g,d.inverse.apply(this,[a]),a.x=e(a.x+this.long0),a},c.names=["Stereographic_North_Pole","Oblique_Stereographic","Polar_Stereographic","sterea","Oblique Stereographic Alternative"]},{"../common/adjust_lon":5,"./gauss":46}],63:[function(a,b,c){var d=a("../common/e0fn"),e=a("../common/e1fn"),f=a("../common/e2fn"),g=a("../common/e3fn"),h=a("../common/mlfn"),i=a("../common/adjust_lon"),j=Math.PI/2,k=1e-10,l=a("../common/sign"),m=a("../common/asinz");c.init=function(){this.e0=d(this.es),this.e1=e(this.es),this.e2=f(this.es),this.e3=g(this.es),this.ml0=this.a*h(this.e0,this.e1,this.e2,this.e3,this.lat0)},c.forward=function(a){var b,c,d,e=a.x,f=a.y,g=i(e-this.long0),j=Math.sin(f),k=Math.cos(f);if(this.sphere){var l=k*Math.sin(g);if(Math.abs(Math.abs(l)-1)<1e-10)return 93;c=.5*this.a*this.k0*Math.log((1+l)/(1-l)),b=Math.acos(k*Math.cos(g)/Math.sqrt(1-l*l)),0>f&&(b=-b),d=this.a*this.k0*(b-this.lat0)}else{var m=k*g,n=Math.pow(m,2),o=this.ep2*Math.pow(k,2),p=Math.tan(f),q=Math.pow(p,2);b=1-this.es*Math.pow(j,2);var r=this.a/Math.sqrt(b),s=this.a*h(this.e0,this.e1,this.e2,this.e3,f);c=this.k0*r*m*(1+n/6*(1-q+o+n/20*(5-18*q+Math.pow(q,2)+72*o-58*this.ep2)))+this.x0,d=this.k0*(s-this.ml0+r*p*(n*(.5+n/24*(5-q+9*o+4*Math.pow(o,2)+n/30*(61-58*q+Math.pow(q,2)+600*o-330*this.ep2)))))+this.y0}return a.x=c,a.y=d,a},c.inverse=function(a){var b,c,d,e,f,g,h=6;if(this.sphere){var n=Math.exp(a.x/(this.a*this.k0)),o=.5*(n-1/n),p=this.lat0+a.y/(this.a*this.k0),q=Math.cos(p);b=Math.sqrt((1-q*q)/(1+o*o)),f=m(b),0>p&&(f=-f),g=0===o&&0===q?this.long0:i(Math.atan2(o,q)+this.long0)}else{var r=a.x-this.x0,s=a.y-this.y0;for(b=(this.ml0+s/this.k0)/this.a,c=b,e=0;!0&&(d=(b+this.e1*Math.sin(2*c)-this.e2*Math.sin(4*c)+this.e3*Math.sin(6*c))/this.e0-c,c+=d,!(Math.abs(d)<=k));e++)if(e>=h)return 95;if(Math.abs(c)=0?this.y0+Math.PI*this.R*Math.tan(.5*k):this.y0+Math.PI*this.R*-Math.tan(.5*k));var l=.5*Math.abs(Math.PI/j-j/Math.PI),m=l*l,n=Math.sin(k),o=Math.cos(k),p=o/(n+o-1),q=p*p,r=p*(2/n-1),s=r*r,t=Math.PI*this.R*(l*(p-s)+Math.sqrt(m*(p-s)*(p-s)-(s+m)*(q-s)))/(s+m);0>j&&(t=-t),b=this.x0+t;var u=m+p;return t=Math.PI*this.R*(r*u-l*Math.sqrt((s+m)*(m+1)-u*u))/(s+m),c=i>=0?this.y0+t:this.y0-t,a.x=b,a.y=c,a},c.inverse=function(a){var b,c,e,g,h,i,j,k,l,m,n,o,p;return a.x-=this.x0,a.y-=this.y0,n=Math.PI*this.R,e=a.x/n,g=a.y/n,h=e*e+g*g,i=-Math.abs(g)*(1+h),j=i-2*g*g+e*e,k=-2*i+1+2*g*g+h*h,p=g*g/k+(2*j*j*j/k/k/k-9*i*j/k/k)/27,l=(i-j*j/3/k)/k,m=2*Math.sqrt(-l/3),n=3*p/l/m,Math.abs(n)>1&&(n=n>=0?1:-1),o=Math.acos(n)/3,c=a.y>=0?(-m*Math.cos(o+Math.PI/3)-j/3/k)*Math.PI:-(-m*Math.cos(o+Math.PI/3)-j/3/k)*Math.PI,b=Math.abs(e)-1?(b[c]={name:a[0].toLowerCase(),convert:a[1]},3===a.length&&(b[c].auth=a[2])):"SPHEROID"===c?(b[c]={name:a[0],a:a[1],rf:a[2]},4===a.length&&(b[c].auth=a[3])):["GEOGCS","GEOCCS","DATUM","VERT_CS","COMPD_CS","LOCAL_CS","FITTED_CS","LOCAL_DATUM"].indexOf(c)>-1?(a[0]=["name",a[0]],d(b,c,a)):a.every(function(a){return Array.isArray(a)})?d(b,c,a):e(a,b[c])):b[c]=!0, -void 0):void(b[a]=!0)}function f(a,b){var c=b[0],d=b[1];!(c in a)&&d in a&&(a[c]=a[d],3===b.length&&(a[c]=b[2](a[c])))}function g(a){return a*i}function h(a){function b(b){var c=a.to_meter||1;return parseFloat(b,10)*c}"GEOGCS"===a.type?a.projName="longlat":"LOCAL_CS"===a.type?(a.projName="identity",a.local=!0):"object"==typeof a.PROJECTION?a.projName=Object.keys(a.PROJECTION)[0]:a.projName=a.PROJECTION,a.UNIT&&(a.units=a.UNIT.name.toLowerCase(),"metre"===a.units&&(a.units="meter"),a.UNIT.convert&&(a.to_meter=parseFloat(a.UNIT.convert,10))),a.GEOGCS&&(a.GEOGCS.DATUM?a.datumCode=a.GEOGCS.DATUM.name.toLowerCase():a.datumCode=a.GEOGCS.name.toLowerCase(),"d_"===a.datumCode.slice(0,2)&&(a.datumCode=a.datumCode.slice(2)),("new_zealand_geodetic_datum_1949"===a.datumCode||"new_zealand_1949"===a.datumCode)&&(a.datumCode="nzgd49"),"wgs_1984"===a.datumCode&&("Mercator_Auxiliary_Sphere"===a.PROJECTION&&(a.sphere=!0),a.datumCode="wgs84"),"_ferro"===a.datumCode.slice(-6)&&(a.datumCode=a.datumCode.slice(0,-6)),"_jakarta"===a.datumCode.slice(-8)&&(a.datumCode=a.datumCode.slice(0,-8)),~a.datumCode.indexOf("belge")&&(a.datumCode="rnb72"),a.GEOGCS.DATUM&&a.GEOGCS.DATUM.SPHEROID&&(a.ellps=a.GEOGCS.DATUM.SPHEROID.name.replace("_19","").replace(/[Cc]larke\_18/,"clrk"),"international"===a.ellps.toLowerCase().slice(0,13)&&(a.ellps="intl"),a.a=a.GEOGCS.DATUM.SPHEROID.a,a.rf=parseFloat(a.GEOGCS.DATUM.SPHEROID.rf,10)),~a.datumCode.indexOf("osgb_1936")&&(a.datumCode="osgb36")),a.b&&!isFinite(a.b)&&(a.b=a.a);var c=function(b){return f(a,b)},d=[["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",g],["longitude_of_center","Longitude_Of_Center"],["longc","longitude_of_center",g],["x0","false_easting",b],["y0","false_northing",b],["long0","central_meridian",g],["lat0","latitude_of_origin",g],["lat0","standard_parallel_1",g],["lat1","standard_parallel_1",g],["lat2","standard_parallel_2",g],["alpha","azimuth",g],["srsCode","name"]];d.forEach(c),a.long0||!a.longc||"Albers_Conic_Equal_Area"!==a.projName&&"Lambert_Azimuthal_Equal_Area"!==a.projName||(a.long0=a.longc),a.lat_ts||!a.lat1||"Stereographic_South_Pole"!==a.projName&&"Polar Stereographic (variant B)"!==a.projName||(a.lat0=g(a.lat1>0?90:-90),a.lat_ts=a.lat1)}var i=.017453292519943295,j=a("./extend");b.exports=function(a,b){var c=JSON.parse((","+a).replace(/\s*\,\s*([A-Z_0-9]+?)(\[)/g,',["$1",').slice(1).replace(/\s*\,\s*([A-Z_0-9]+?)\]/g,',"$1"]').replace(/,\["VERTCS".+/,"")),d=c.shift(),f=c.shift();c.unshift(["name",f]),c.unshift(["type",d]),c.unshift("output");var g={};return e(c,g),h(g.output),j(b,g.output)}},{"./extend":34}],68:[function(a,b,c){function d(a){return a*(Math.PI/180)}function e(a){return 180*(a/Math.PI)}function f(a){var b,c,e,f,g,i,j,k,l,m=a.lat,n=a.lon,o=6378137,p=.00669438,q=.9996,r=d(m),s=d(n);l=Math.floor((n+180)/6)+1,180===n&&(l=60),m>=56&&64>m&&n>=3&&12>n&&(l=32),m>=72&&84>m&&(n>=0&&9>n?l=31:n>=9&&21>n?l=33:n>=21&&33>n?l=35:n>=33&&42>n&&(l=37)),b=6*(l-1)-180+3,k=d(b),c=p/(1-p),e=o/Math.sqrt(1-p*Math.sin(r)*Math.sin(r)),f=Math.tan(r)*Math.tan(r),g=c*Math.cos(r)*Math.cos(r),i=Math.cos(r)*(s-k),j=o*((1-p/4-3*p*p/64-5*p*p*p/256)*r-(3*p/8+3*p*p/32+45*p*p*p/1024)*Math.sin(2*r)+(15*p*p/256+45*p*p*p/1024)*Math.sin(4*r)-35*p*p*p/3072*Math.sin(6*r));var t=q*e*(i+(1-f+g)*i*i*i/6+(5-18*f+f*f+72*g-58*c)*i*i*i*i*i/120)+5e5,u=q*(j+e*Math.tan(r)*(i*i/2+(5-f+9*g+4*g*g)*i*i*i*i/24+(61-58*f+f*f+600*g-330*c)*i*i*i*i*i*i/720));return 0>m&&(u+=1e7),{northing:Math.round(u),easting:Math.round(t),zoneNumber:l,zoneLetter:h(m)}}function g(a){var b=a.northing,c=a.easting,d=a.zoneLetter,f=a.zoneNumber;if(0>f||f>60)return null;var h,i,j,k,l,m,n,o,p,q,r=.9996,s=6378137,t=.00669438,u=(1-Math.sqrt(1-t))/(1+Math.sqrt(1-t)),v=c-5e5,w=b;"N">d&&(w-=1e7),o=6*(f-1)-180+3,h=t/(1-t),n=w/r,p=n/(s*(1-t/4-3*t*t/64-5*t*t*t/256)),q=p+(3*u/2-27*u*u*u/32)*Math.sin(2*p)+(21*u*u/16-55*u*u*u*u/32)*Math.sin(4*p)+151*u*u*u/96*Math.sin(6*p),i=s/Math.sqrt(1-t*Math.sin(q)*Math.sin(q)),j=Math.tan(q)*Math.tan(q),k=h*Math.cos(q)*Math.cos(q),l=s*(1-t)/Math.pow(1-t*Math.sin(q)*Math.sin(q),1.5),m=v/(i*r);var x=q-i*Math.tan(q)/l*(m*m/2-(5+3*j+10*k-4*k*k-9*h)*m*m*m*m/24+(61+90*j+298*k+45*j*j-252*h-3*k*k)*m*m*m*m*m*m/720);x=e(x);var y=(m-(1+2*j+k)*m*m*m/6+(5-2*k+28*j-3*k*k+8*h+24*j*j)*m*m*m*m*m/120)/Math.cos(q);y=o+e(y);var z;if(a.accuracy){var A=g({northing:a.northing+a.accuracy,easting:a.easting+a.accuracy,zoneLetter:a.zoneLetter,zoneNumber:a.zoneNumber});z={top:A.lat,right:A.lon,bottom:x,left:y}}else z={lat:x,lon:y};return z}function h(a){var b="Z";return 84>=a&&a>=72?b="X":72>a&&a>=64?b="W":64>a&&a>=56?b="V":56>a&&a>=48?b="U":48>a&&a>=40?b="T":40>a&&a>=32?b="S":32>a&&a>=24?b="R":24>a&&a>=16?b="Q":16>a&&a>=8?b="P":8>a&&a>=0?b="N":0>a&&a>=-8?b="M":-8>a&&a>=-16?b="L":-16>a&&a>=-24?b="K":-24>a&&a>=-32?b="J":-32>a&&a>=-40?b="H":-40>a&&a>=-48?b="G":-48>a&&a>=-56?b="F":-56>a&&a>=-64?b="E":-64>a&&a>=-72?b="D":-72>a&&a>=-80&&(b="C"),b}function i(a,b){var c=""+a.easting,d=""+a.northing;return a.zoneNumber+a.zoneLetter+j(a.easting,a.northing,a.zoneNumber)+c.substr(c.length-5,b)+d.substr(d.length-5,b)}function j(a,b,c){var d=k(c),e=Math.floor(a/1e5),f=Math.floor(b/1e5)%20;return l(e,f,d)}function k(a){var b=a%q;return 0===b&&(b=q),b}function l(a,b,c){var d=c-1,e=r.charCodeAt(d),f=s.charCodeAt(d),g=e+a-1,h=f+b,i=!1;g>x&&(g=g-x+t-1,i=!0),(g===u||u>e&&g>u||(g>u||u>e)&&i)&&g++,(g===v||v>e&&g>v||(g>v||v>e)&&i)&&(g++,g===u&&g++),g>x&&(g=g-x+t-1),h>w?(h=h-w+t-1,i=!0):i=!1,(h===u||u>f&&h>u||(h>u||u>f)&&i)&&h++,(h===v||v>f&&h>v||(h>v||v>f)&&i)&&(h++,h===u&&h++),h>w&&(h=h-w+t-1);var j=String.fromCharCode(g)+String.fromCharCode(h);return j}function m(a){if(a&&0===a.length)throw"MGRSPoint coverting from nothing";for(var b,c=a.length,d=null,e="",f=0;!/[A-Z]/.test(b=a.charAt(f));){if(f>=2)throw"MGRSPoint bad conversion from: "+a;e+=b,f++}var g=parseInt(e,10);if(0===f||f+3>c)throw"MGRSPoint bad conversion from: "+a;var h=a.charAt(f++);if("A">=h||"B"===h||"Y"===h||h>="Z"||"I"===h||"O"===h)throw"MGRSPoint zone letter "+h+" not handled: "+a;d=a.substring(f,f+=2);for(var i=k(g),j=n(d.charAt(0),i),l=o(d.charAt(1),i);l0&&(q=1e5/Math.pow(10,v),r=a.substring(f,f+v),w=parseFloat(r)*q,s=a.substring(f+v),x=parseFloat(s)*q),t=w+j,u=x+l,{easting:t,northing:u,zoneLetter:h,zoneNumber:g,accuracy:q}}function n(a,b){for(var c=r.charCodeAt(b-1),d=1e5,e=!1;c!==a.charCodeAt(0);){if(c++,c===u&&c++,c===v&&c++,c>x){if(e)throw"Bad character: "+a;c=t,e=!0}d+=1e5}return d}function o(a,b){if(a>"V")throw"MGRSPoint given invalid Northing "+a;for(var c=s.charCodeAt(b-1),d=0,e=!1;c!==a.charCodeAt(0);){if(c++,c===u&&c++,c===v&&c++,c>w){if(e)throw"Bad character: "+a;c=t,e=!0}d+=1e5}return d}function p(a){var b;switch(a){case"C":b=11e5;break;case"D":b=2e6;break;case"E":b=28e5;break;case"F":b=37e5;break;case"G":b=46e5;break;case"H":b=55e5;break;case"J":b=64e5;break;case"K":b=73e5;break;case"L":b=82e5;break;case"M":b=91e5;break;case"N":b=0;break;case"P":b=8e5;break;case"Q":b=17e5;break;case"R":b=26e5;break;case"S":b=35e5;break;case"T":b=44e5;break;case"U":b=53e5;break;case"V":b=62e5;break;case"W":b=7e6;break;case"X":b=79e5;break;default:b=-1}if(b>=0)return b;throw"Invalid zone letter: "+a}var q=6,r="AJSAJS",s="AFAFAF",t=65,u=73,v=79,w=86,x=90;c.forward=function(a,b){return b=b||5,i(f({lat:a[1],lon:a[0]}),b)},c.inverse=function(a){var b=g(m(a.toUpperCase()));return[b.left,b.bottom,b.right,b.top]},c.toPoint=function(a){var b=c.inverse(a);return[(b[2]+b[0])/2,(b[3]+b[1])/2]}},{}],69:[function(a,b,c){b.exports={name:"_mproj4_",version:"2.3.7-alpha",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/_mproj4_js/_mproj4_js.git"},author:"",license:"MIT",jam:{main:"dist/_mproj4_.js",include:["dist/_mproj4_.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(a,b,c){b.exports=a("Pk/iAZ")},{}],"Pk/iAZ":[function(a,b,c){var d=[a("./lib/projections/tmerc"),a("./lib/projections/utm"),a("./lib/projections/sterea"),a("./lib/projections/stere"),a("./lib/projections/somerc"),a("./lib/projections/omerc"),a("./lib/projections/lcc"),a("./lib/projections/krovak"),a("./lib/projections/cass"),a("./lib/projections/laea"),a("./lib/projections/aea"),a("./lib/projections/gnom"),a("./lib/projections/cea"),a("./lib/projections/eqc"),a("./lib/projections/poly"),a("./lib/projections/nzmg"),a("./lib/projections/mill"),a("./lib/projections/sinu"),a("./lib/projections/moll"),a("./lib/projections/eqdc"),a("./lib/projections/vandg"),a("./lib/projections/aeqd"),a("./lib/projections/geocent")];b.exports=function(_mproj4_){d.forEach(function(a){_mproj4_.Proj.projections.add(a)})}},{"./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/geocent":47,"./lib/projections/gnom":48,"./lib/projections/krovak":49,"./lib/projections/laea":50,"./lib/projections/lcc":51,"./lib/projections/mill":54,"./lib/projections/moll":55,"./lib/projections/nzmg":56,"./lib/projections/omerc":57,"./lib/projections/poly":58,"./lib/projections/sinu":59,"./lib/projections/somerc":60,"./lib/projections/stere":61,"./lib/projections/sterea":62,"./lib/projections/tmerc":63,"./lib/projections/utm":64,"./lib/projections/vandg":65}]},{},[36])(36)}); \ No newline at end of file +!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a._mproj4_=b()}(this,function(){"use strict";function a(a,b){if(a[b])return a[b];for(var c,d,e=Object.keys(a),f=b.toLowerCase().replace(Vb,""),g=-1;++g0?90:-90),a.lat_ts=a.lat1)}function i(a){var b=this;if(2===arguments.length){var c=arguments[1];"string"==typeof c?"+"===c.charAt(0)?i[a]=Wb(arguments[1]):i[a]=hc(arguments[1]):i[a]=c}else if(1===arguments.length){if(Array.isArray(a))return a.map(function(a){Array.isArray(a)?i.apply(b,a):i(a)});if("string"==typeof a){if(a in i)return i[a]}else"EPSG"in a?i["EPSG:"+a.EPSG]=a:"ESRI"in a?i["ESRI:"+a.ESRI]=a:"IAU2000"in a?i["IAU2000:"+a.IAU2000]=a:console.log(a);return}}function j(a){return"string"==typeof a}function k(a){return a in i}function l(a){return ic.some(function(b){return a.indexOf(b)>-1})}function m(a){return"+"===a[0]}function n(a){return j(a)?k(a)?i[a]:l(a)?hc(a):m(a)?Wb(a):void 0:a}function o(){var a=this.b/this.a;this.es=1-a*a,"x0"in this||(this.x0=0),"y0"in this||(this.y0=0),this.e=Math.sqrt(this.es),this.lat_ts?this.sphere?this.k0=Math.cos(this.lat_ts):this.k0=kc(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)):this.k0||(this.k?this.k0=this.k:this.k0=1)}function p(a){var b=a.x,c=a.y;if(c*Pb>90&&c*Pb<-90&&b*Pb>180&&b*Pb<-180)return null;var d,e;if(Math.abs(Math.abs(c)-Jb)<=Nb)return null;if(this.sphere)d=this.x0+this.a*this.k0*mc(b-this.long0),e=this.y0+this.a*this.k0*Math.log(Math.tan(Qb+.5*c));else{var f=Math.sin(c),g=nc(this.e,c,f);d=this.x0+this.a*this.k0*mc(b-this.long0),e=this.y0-this.a*this.k0*Math.log(g)}return a.x=d,a.y=e,a}function q(a){var b,c,d=a.x-this.x0,e=a.y-this.y0;if(this.sphere)c=Jb-2*Math.atan(Math.exp(-e/(this.a*this.k0)));else{var f=Math.exp(-e/(this.a*this.k0));if(c=oc(this.e,f),c===-9999)return null}return b=mc(this.long0+d/(this.a*this.k0)),a.x=b,a.y=c,a}function r(){}function s(a){return a}function t(a,b){var c=vc.length;return a.names?(vc[c]=a,a.names.forEach(function(a){uc[a.toLowerCase()]=c}),this):(console.log(b),!0)}function u(a){if(!a)return!1;var b=a.toLowerCase();return"undefined"!=typeof uc[b]&&vc[uc[b]]?vc[uc[b]]:void 0}function v(){tc.forEach(t)}function w(a,b,c,d){var e=a*a,f=b*b,g=(e-f)/e,h=0;d?(a*=1-g*(Kb+g*(Lb+g*Mb)),e=a*a,g=0):h=Math.sqrt(g);var i=(e-f)/f;return{es:g,e:h,ep2:i}}function x(b,c,d,e,f){if(!b){var g=a(xc,e);g||(g=yc),b=g.a,c=g.b,d=g.rf}return d&&!c&&(c=(1-1/d)*b),(0===d||Math.abs(b-c)3&&(0===g.datum_params[3]&&0===g.datum_params[4]&&0===g.datum_params[5]&&0===g.datum_params[6]||(g.datum_type=Fb,g.datum_params[3]*=Ib,g.datum_params[4]*=Ib,g.datum_params[5]*=Ib,g.datum_params[6]=g.datum_params[6]/1e6+1))),g.a=c,g.b=d,g.es=e,g.ep2=f,g}function z(b,c){if(!(this instanceof z))return new z(b);c=c||function(a){if(a)throw a};var d=n(b);if("object"!=typeof d)return void c(b);var e=z.projections.get(d.projName);if(!e)return void c(b);if(d.datumCode&&"none"!==d.datumCode){var f=a(zc,d.datumCode);f&&(d.datum_params=f.towgs84?f.towgs84.split(","):null,d.ellps=f.ellipse,d.datumName=f.datumName?f.datumName:d.datumCode)}d.k0=d.k0||1,d.axis=d.axis||"enu",d.ellps=d.ellps||"wgs84";var g=x(d.a,d.b,d.rf,d.ellps,d.sphere),h=w(g.a,g.b,g.rf,d.R_A),i=d.datum||y(d.datumCode,d.datum_params,g.a,g.b,h.es,h.ep2);jc(this,d),jc(this,e),this.a=g.a,this.b=g.b,this.rf=g.rf,this.sphere=g.sphere,this.es=h.es,this.e=h.e,this.ep2=h.ep2,this.datum=i,this.init(),c(null,this)}function A(a,b){return a.datum_type===b.datum_type&&(!(a.a!==b.a||Math.abs(a.es-b.es)>5e-11)&&(a.datum_type===Eb?a.datum_params[0]===b.datum_params[0]&&a.datum_params[1]===b.datum_params[1]&&a.datum_params[2]===b.datum_params[2]:a.datum_type!==Fb||a.datum_params[0]===b.datum_params[0]&&a.datum_params[1]===b.datum_params[1]&&a.datum_params[2]===b.datum_params[2]&&a.datum_params[3]===b.datum_params[3]&&a.datum_params[4]===b.datum_params[4]&&a.datum_params[5]===b.datum_params[5]&&a.datum_params[6]===b.datum_params[6]))}function B(a,b,c){var d,e,f,g,h=a.x,i=a.y,j=a.z?a.z:0;if(i<-Jb&&i>-1.001*Jb)i=-Jb;else if(i>Jb&&i<1.001*Jb)i=Jb;else if(i<-Jb||i>Jb)return null;return h>Math.PI&&(h-=2*Math.PI),e=Math.sin(i),g=Math.cos(i),f=e*e,d=c/Math.sqrt(1-b*f),{x:(d+j)*g*Math.cos(h),y:(d+j)*g*Math.sin(h),z:(d*(1-b)+j)*e}}function C(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u=1e-12,v=u*u,w=30,x=a.x,y=a.y,z=a.z?a.z:0;if(e=Math.sqrt(x*x+y*y),f=Math.sqrt(x*x+y*y+z*z),e/cv&&q=56&&k<64&&l>=3&&l<12&&(j=32),k>=72&&k<84&&(l>=0&&l<9?j=31:l>=9&&l<21?j=33:l>=21&&l<33?j=35:l>=33&&l<42&&(j=37)),b=6*(j-1)-180+3,i=O(b),c=n/(1-n),d=m/Math.sqrt(1-n*Math.sin(p)*Math.sin(p)),e=Math.tan(p)*Math.tan(p),f=c*Math.cos(p)*Math.cos(p),g=Math.cos(p)*(q-i),h=m*((1-n/4-3*n*n/64-5*n*n*n/256)*p-(3*n/8+3*n*n/32+45*n*n*n/1024)*Math.sin(2*p)+(15*n*n/256+45*n*n*n/1024)*Math.sin(4*p)-35*n*n*n/3072*Math.sin(6*p));var r=o*d*(g+(1-e+f)*g*g*g/6+(5-18*e+e*e+72*f-58*c)*g*g*g*g*g/120)+5e5,s=o*(h+d*Math.tan(p)*(g*g/2+(5-e+9*f+4*f*f)*g*g*g*g/24+(61-58*e+e*e+600*f-330*c)*g*g*g*g*g*g/720));return k<0&&(s+=1e7),{northing:Math.round(s),easting:Math.round(r),zoneNumber:j,zoneLetter:S(k)}}function R(a){var b=a.northing,c=a.easting,d=a.zoneLetter,e=a.zoneNumber;if(e<0||e>60)return null;var f,g,h,i,j,k,l,m,n,o,p=.9996,q=6378137,r=.00669438,s=(1-Math.sqrt(1-r))/(1+Math.sqrt(1-r)),t=c-5e5,u=b;d<"N"&&(u-=1e7),m=6*(e-1)-180+3,f=r/(1-r),l=u/p,n=l/(q*(1-r/4-3*r*r/64-5*r*r*r/256)),o=n+(3*s/2-27*s*s*s/32)*Math.sin(2*n)+(21*s*s/16-55*s*s*s*s/32)*Math.sin(4*n)+151*s*s*s/96*Math.sin(6*n),g=q/Math.sqrt(1-r*Math.sin(o)*Math.sin(o)),h=Math.tan(o)*Math.tan(o),i=f*Math.cos(o)*Math.cos(o),j=q*(1-r)/Math.pow(1-r*Math.sin(o)*Math.sin(o),1.5),k=t/(g*p);var v=o-g*Math.tan(o)/j*(k*k/2-(5+3*h+10*i-4*i*i-9*f)*k*k*k*k/24+(61+90*h+298*i+45*h*h-252*f-3*i*i)*k*k*k*k*k*k/720);v=P(v);var w=(k-(1+2*h+i)*k*k*k/6+(5-2*i+28*h-3*i*i+8*f+24*h*h)*k*k*k*k*k/120)/Math.cos(o);w=m+P(w);var x;if(a.accuracy){var y=R({northing:a.northing+a.accuracy,easting:a.easting+a.accuracy,zoneLetter:a.zoneLetter,zoneNumber:a.zoneNumber});x={top:y.lat,right:y.lon,bottom:v,left:w}}else x={lat:v,lon:w};return x}function S(a){var b="Z";return 84>=a&&a>=72?b="X":72>a&&a>=64?b="W":64>a&&a>=56?b="V":56>a&&a>=48?b="U":48>a&&a>=40?b="T":40>a&&a>=32?b="S":32>a&&a>=24?b="R":24>a&&a>=16?b="Q":16>a&&a>=8?b="P":8>a&&a>=0?b="N":0>a&&a>=-8?b="M":-8>a&&a>=-16?b="L":-16>a&&a>=-24?b="K":-24>a&&a>=-32?b="J":-32>a&&a>=-40?b="H":-40>a&&a>=-48?b="G":-48>a&&a>=-56?b="F":-56>a&&a>=-64?b="E":-64>a&&a>=-72?b="D":-72>a&&a>=-80&&(b="C"),b}function T(a,b){var c="00000"+a.easting,d="00000"+a.northing;return a.zoneNumber+a.zoneLetter+U(a.easting,a.northing,a.zoneNumber)+c.substr(c.length-5,b)+d.substr(d.length-5,b)}function U(a,b,c){var d=V(c),e=Math.floor(a/1e5),f=Math.floor(b/1e5)%20;return W(e,f,d)}function V(a){var b=a%Ec;return 0===b&&(b=Ec),b}function W(a,b,c){var d=c-1,e=Fc.charCodeAt(d),f=Gc.charCodeAt(d),g=e+a-1,h=f+b,i=!1;g>Lc&&(g=g-Lc+Hc-1,i=!0),(g===Ic||eIc||(g>Ic||eJc||(g>Jc||eLc&&(g=g-Lc+Hc-1),h>Kc?(h=h-Kc+Hc-1,i=!0):i=!1,(h===Ic||fIc||(h>Ic||fJc||(h>Jc||fKc&&(h=h-Kc+Hc-1);var j=String.fromCharCode(g)+String.fromCharCode(h);return j}function X(a){if(a&&0===a.length)throw"MGRSPoint coverting from nothing";for(var b,c=a.length,d=null,e="",f=0;!/[A-Z]/.test(b=a.charAt(f));){if(f>=2)throw"MGRSPoint bad conversion from: "+a;e+=b,f++}var g=parseInt(e,10);if(0===f||f+3>c)throw"MGRSPoint bad conversion from: "+a;var h=a.charAt(f++);if(h<="A"||"B"===h||"Y"===h||h>="Z"||"I"===h||"O"===h)throw"MGRSPoint zone letter "+h+" not handled: "+a;d=a.substring(f,f+=2);for(var i=V(g),j=Y(d.charAt(0),i),k=Z(d.charAt(1),i);k<$(h);)k+=2e6;var l=c-f;if(l%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"+a;var m,n,o,p,q,r=l/2,s=0,t=0;return r>0&&(m=1e5/Math.pow(10,r),n=a.substring(f,f+r),s=parseFloat(n)*m,o=a.substring(f+r),t=parseFloat(o)*m),p=s+j,q=t+k,{easting:p,northing:q,zoneLetter:h,zoneNumber:g,accuracy:m}}function Y(a,b){for(var c=Fc.charCodeAt(b-1),d=1e5,e=!1;c!==a.charCodeAt(0);){if(c++,c===Ic&&c++,c===Jc&&c++,c>Lc){if(e)throw"Bad character: "+a;c=Hc,e=!0}d+=1e5}return d}function Z(a,b){if(a>"V")throw"MGRSPoint given invalid Northing "+a;for(var c=Gc.charCodeAt(b-1),d=0,e=!1;c!==a.charCodeAt(0);){if(c++,c===Ic&&c++,c===Jc&&c++,c>Kc){if(e)throw"Bad character: "+a;c=Hc,e=!0}d+=1e5}return d}function $(a){var b;switch(a){case"C":b=11e5;break;case"D":b=2e6;break;case"E":b=28e5;break;case"F":b=37e5;break;case"G":b=46e5;break;case"H":b=55e5;break;case"J":b=64e5;break;case"K":b=73e5;break;case"L":b=82e5;break;case"M":b=91e5;break;case"N":b=0;break;case"P":b=8e5;break;case"Q":b=17e5;break;case"R":b=26e5;break;case"S":b=35e5;break;case"T":b=44e5;break;case"U":b=53e5;break;case"V":b=62e5;break;case"W":b=7e6;break;case"X":b=79e5;break;default:b=-1}if(b>=0)return b;throw"Invalid zone letter: "+a}function Point(a,b,c){if(!(this instanceof Point))return new Point(a,b,c);if(Array.isArray(a))this.x=a[0],this.y=a[1],this.z=a[2]||0;else if("object"==typeof a)this.x=a.x,this.y=a.y,this.z=a.z||0;else if("string"==typeof a&&"undefined"==typeof b){var d=a.split(",");this.x=parseFloat(d[0],10),this.y=parseFloat(d[1],10),this.z=parseFloat(d[2],10)||0}else this.x=a,this.y=b,this.z=c||0;console.warn("proj4.Point will be removed in version 3, use proj4.toPoint")}function _(){this.x0=void 0!==this.x0?this.x0:0,this.y0=void 0!==this.y0?this.y0:0,this.long0=void 0!==this.long0?this.long0:0,this.lat0=void 0!==this.lat0?this.lat0:0,this.es&&(this.en=$c(this.es),this.ml0=_c(this.lat0,Math.sin(this.lat0),Math.cos(this.lat0),this.en))}function aa(a){var b,c,d,e=a.x,f=a.y,g=mc(e-this.long0),h=Math.sin(f),i=Math.cos(f);if(this.es){var j=i*g,k=Math.pow(j,2),l=this.ep2*Math.pow(i,2),m=Math.pow(l,2),n=Math.abs(i)>Nb?Math.tan(f):0,o=Math.pow(n,2),p=Math.pow(o,2);b=1-this.es*Math.pow(h,2),j/=Math.sqrt(b);var q=_c(f,h,i,this.en);c=this.a*(this.k0*j*(1+k/6*(1-o+l+k/20*(5-18*o+p+14*l-58*o*l+k/42*(61+179*p-p*o-479*o)))))+this.x0,d=this.a*(this.k0*(q-this.ml0+h*g*j/2*(1+k/12*(5-o+9*l+4*m+k/30*(61+p-58*o+270*l-330*o*l+k/56*(1385+543*p-p*o-3111*o))))))+this.y0}else{var r=i*Math.sin(g);if(Math.abs(Math.abs(r)-1)=1){if(r-1>Nb)return 93;d=0}else d=Math.acos(d);f<0&&(d=-d),d=this.a*this.k0*(d-this.lat0)+this.y0}return a.x=c,a.y=d,a}function ba(a){var b,c,d,e,f=(a.x-this.x0)*(1/this.a),g=(a.y-this.y0)*(1/this.a);if(this.es)if(b=this.ml0+g/this.k0,c=bd(b,this.es,this.en),Math.abs(c)Nb?Math.tan(c):0,k=this.ep2*Math.pow(i,2),l=Math.pow(k,2),m=Math.pow(j,2),n=Math.pow(m,2);b=1-this.es*Math.pow(h,2);var o=f*Math.sqrt(b)/this.k0,p=Math.pow(o,2);b*=j,d=c-b*p/(1-this.es)*.5*(1-p/12*(5+3*m-9*k*m+k-4*l-p/30*(61+90*m-252*k*m+45*n+46*k-p/56*(1385+3633*m+4095*n+1574*n*m)))),e=mc(this.long0+o*(1-p/6*(1+2*m+k-p/20*(5+28*m+24*n+8*k*m+6*k-p/42*(61+662*m+1320*n+720*n*m))))/i)}else d=Jb*lc(g),e=0;else{var q=Math.exp(f/this.k0),r=.5*(q-1/q),s=this.lat0+g/this.k0,t=Math.cos(s);b=Math.sqrt((1-Math.pow(t,2))/(1+Math.pow(r,2))),d=Math.asin(b),g<0&&(d=-d),e=0===r&&0===t?0:mc(Math.atan2(r,t)+this.long0)}return a.x=e,a.y=d,a}function ca(){if(void 0===this.es||this.es<=0)throw new Error("incorrect elliptical usage");this.x0=void 0!==this.x0?this.x0:0,this.y0=void 0!==this.y0?this.y0:0,this.long0=void 0!==this.long0?this.long0:0,this.lat0=void 0!==this.lat0?this.lat0:0,this.cgb=[],this.cbg=[],this.utg=[],this.gtu=[];var a=this.es/(1+Math.sqrt(1-this.es)),b=a/(2-a),c=b;this.cgb[0]=b*(2+b*(-2/3+b*(-2+b*(116/45+b*(26/45+b*(-2854/675)))))),this.cbg[0]=b*(-2+b*(2/3+b*(4/3+b*(-82/45+b*(32/45+b*(4642/4725)))))),c*=b,this.cgb[1]=c*(7/3+b*(-1.6+b*(-227/45+b*(2704/315+b*(2323/945))))),this.cbg[1]=c*(5/3+b*(-16/15+b*(-13/9+b*(904/315+b*(-1522/945))))),c*=b,this.cgb[2]=c*(56/15+b*(-136/35+b*(-1262/105+b*(73814/2835)))),this.cbg[2]=c*(-26/15+b*(34/21+b*(1.6+b*(-12686/2835)))),c*=b,this.cgb[3]=c*(4279/630+b*(-332/35+b*(-399572/14175))),this.cbg[3]=c*(1237/630+b*(-2.4+b*(-24832/14175))),c*=b,this.cgb[4]=c*(4174/315+b*(-144838/6237)),this.cbg[4]=c*(-734/315+b*(109598/31185)),c*=b,this.cgb[5]=c*(601676/22275),this.cbg[5]=c*(444337/155925),c=Math.pow(b,2),this.Qn=this.k0/(1+b)*(1+c*(.25+c*(1/64+c/256))),this.utg[0]=b*(-.5+b*(2/3+b*(-37/96+b*(1/360+b*(81/512+b*(-96199/604800)))))),this.gtu[0]=b*(.5+b*(-2/3+b*(5/16+b*(41/180+b*(-127/288+b*(7891/37800)))))),this.utg[1]=c*(-1/48+b*(-1/15+b*(437/1440+b*(-46/105+b*(1118711/3870720))))),this.gtu[1]=c*(13/48+b*(-.6+b*(557/1440+b*(281/630+b*(-1983433/1935360))))),c*=b,this.utg[2]=c*(-17/480+b*(37/840+b*(209/4480+b*(-5569/90720)))),this.gtu[2]=c*(61/240+b*(-103/140+b*(15061/26880+b*(167603/181440)))),c*=b,this.utg[3]=c*(-4397/161280+b*(11/504+b*(830251/7257600))),this.gtu[3]=c*(49561/161280+b*(-179/168+b*(6601661/7257600))),c*=b,this.utg[4]=c*(-4583/161280+b*(108847/3991680)),this.gtu[4]=c*(34729/80640+b*(-3418889/1995840)),c*=b,this.utg[5]=c*-.03233083094085698,this.gtu[5]=.6650675310896665*c;var d=id(this.cbg,this.lat0);this.Zb=-this.Qn*(d+jd(this.gtu,2*d))}function da(a){var b=mc(a.x-this.long0),c=a.y;c=id(this.cbg,c);var d=Math.sin(c),e=Math.cos(c),f=Math.sin(b),g=Math.cos(b);c=Math.atan2(d,g*e),b=Math.atan2(f*e,fd(d,e*g)),b=hd(Math.tan(b));var h=ld(this.gtu,2*c,2*b);c+=h[0],b+=h[1];var i,j;return Math.abs(b)<=2.623395162778?(i=this.a*(this.Qn*b)+this.x0,j=this.a*(this.Qn*c+this.Zb)+this.y0):(i=1/0,j=1/0),a.x=i,a.y=j,a}function ea(a){var b=(a.x-this.x0)*(1/this.a),c=(a.y-this.y0)*(1/this.a);c=(c-this.Zb)/this.Qn,b/=this.Qn;var d,e;if(Math.abs(b)<=2.623395162778){var f=ld(this.utg,2*c,2*b);c+=f[0],b+=f[1],b=Math.atan(ed(b));var g=Math.sin(c),h=Math.cos(c),i=Math.sin(b),j=Math.cos(b);c=Math.atan2(g*j,fd(i,j*h)),b=Math.atan2(i,j*h),d=mc(b+this.long0),e=id(this.cgb,c)}else d=1/0,e=1/0;return a.x=d,a.y=e,a}function fa(){var a=od(this.zone,this.long0);if(void 0===a)throw new Error("unknown utm zone");this.lat0=0,this.long0=(6*Math.abs(a)-183)*Ob,this.x0=5e5,this.y0=this.utmSouth?1e7:0,this.k0=.9996,nd.init.apply(this),this.forward=nd.forward,this.inverse=nd.inverse}function ga(){var a=Math.sin(this.lat0),b=Math.cos(this.lat0);b*=b,this.rc=Math.sqrt(1-this.es)/(1-this.es*a*a),this.C=Math.sqrt(1+this.es*b*b/(1-this.es)),this.phic0=Math.asin(a/this.C),this.ratexp=.5*this.C*this.e,this.K=Math.tan(.5*this.phic0+Qb)/(Math.pow(Math.tan(.5*this.lat0+Qb),this.C)*sd(this.e*a,this.ratexp))}function ha(a){var b=a.x,c=a.y;return a.y=2*Math.atan(this.K*Math.pow(Math.tan(.5*c+Qb),this.C)*sd(this.e*Math.sin(c),this.ratexp))-Jb,a.x=this.C*b,a}function ia(a){for(var b=1e-14,c=a.x/this.C,d=a.y,e=Math.pow(Math.tan(.5*d+Qb)/this.K,1/this.C),f=td;f>0&&(d=2*Math.atan(e*sd(this.e*Math.sin(a.y),-.5*this.e))-Jb,!(Math.abs(d-a.y)0?this.con=1:this.con=-1),this.cons=Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)),1===this.k0&&!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=Nb&&(this.k0=.5*this.cons*kc(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts))/nc(this.e,this.con*this.lat_ts,this.con*Math.sin(this.lat_ts))),this.ms1=kc(this.e,this.sinlat0,this.coslat0),this.X0=2*Math.atan(this.ssfn_(this.lat0,this.sinlat0,this.e))-Jb,this.cosX0=Math.cos(this.X0),this.sinX0=Math.sin(this.X0))}function oa(a){var b,c,d,e,f,g,h=a.x,i=a.y,j=Math.sin(i),k=Math.cos(i),l=mc(h-this.long0);return Math.abs(Math.abs(h-this.long0)-Math.PI)<=Nb&&Math.abs(i+this.lat0)<=Nb?(a.x=NaN,a.y=NaN,a):this.sphere?(b=2*this.k0/(1+this.sinlat0*j+this.coslat0*k*Math.cos(l)),a.x=this.a*b*k*Math.sin(l)+this.x0,a.y=this.a*b*(this.coslat0*j-this.sinlat0*k*Math.cos(l))+this.y0,a):(c=2*Math.atan(this.ssfn_(i,j,this.e))-Jb,e=Math.cos(c),d=Math.sin(c),Math.abs(this.coslat0)<=Nb?(f=nc(this.e,i*this.con,this.con*j),g=2*this.a*this.k0*f/this.cons,a.x=this.x0+g*Math.sin(h-this.long0),a.y=this.y0-this.con*g*Math.cos(h-this.long0),a):(Math.abs(this.sinlat0)0?this.long0+Math.atan2(a.x,-1*a.y):this.long0+Math.atan2(a.x,a.y):this.long0+Math.atan2(a.x*Math.sin(h),g*this.coslat0*Math.cos(h)-a.y*this.sinlat0*Math.sin(h))),a.x=b,a.y=c,a)}if(Math.abs(this.coslat0)<=Nb){if(g<=Nb)return c=this.lat0,b=this.long0,a.x=b,a.y=c,a;a.x*=this.con,a.y*=this.con,d=g*this.cons/(2*this.a*this.k0),c=this.con*oc(this.e,d),b=this.con*mc(this.con*this.long0+Math.atan2(a.x,-1*a.y))}else e=2*Math.atan(g*this.cosX0/(2*this.a*this.k0*this.ms1)),b=this.long0,g<=Nb?f=this.X0:(f=Math.asin(Math.cos(e)*this.sinX0+a.y*Math.sin(e)*this.cosX0/g),b=mc(this.long0+Math.atan2(a.x*Math.sin(e),g*this.cosX0*Math.cos(e)-a.y*this.sinX0*Math.sin(e)))),c=-1*oc(this.e,Math.tan(.5*(Jb+f)));return a.x=b,a.y=c,a}function qa(){var a=this.lat0;this.lambda0=this.long0;var b=Math.sin(a),c=this.a,d=this.rf,e=1/d,f=2*e-Math.pow(e,2),g=this.e=Math.sqrt(f);this.R=this.k0*c*Math.sqrt(1-f)/(1-f*Math.pow(b,2)),this.alpha=Math.sqrt(1+f/(1-f)*Math.pow(Math.cos(a),4)),this.b0=Math.asin(b/this.alpha);var h=Math.log(Math.tan(Math.PI/4+this.b0/2)),i=Math.log(Math.tan(Math.PI/4+a/2)),j=Math.log((1+g*b)/(1-g*b));this.K=h-this.alpha*i+this.alpha*g/2*j}function ra(a){var b=Math.log(Math.tan(Math.PI/4-a.y/2)),c=this.e/2*Math.log((1+this.e*Math.sin(a.y))/(1-this.e*Math.sin(a.y))),d=-this.alpha*(b+c)+this.K,e=2*(Math.atan(Math.exp(d))-Math.PI/4),f=this.alpha*(a.x-this.lambda0),g=Math.atan(Math.sin(f)/(Math.sin(this.b0)*Math.tan(e)+Math.cos(this.b0)*Math.cos(f))),h=Math.asin(Math.cos(this.b0)*Math.sin(e)-Math.sin(this.b0)*Math.cos(e)*Math.cos(f));return a.y=this.R/2*Math.log((1+Math.sin(h))/(1-Math.sin(h)))+this.y0,a.x=this.R*g+this.x0,a}function sa(a){for(var b=a.x-this.x0,c=a.y-this.y0,d=b/this.R,e=2*(Math.atan(Math.exp(c/this.R))-Math.PI/4),f=Math.asin(Math.cos(this.b0)*Math.sin(e)+Math.sin(this.b0)*Math.cos(e)*Math.cos(d)),g=Math.atan(Math.sin(d)/(Math.cos(this.b0)*Math.cos(d)-Math.sin(this.b0)*Math.tan(e))),h=this.lambda0+g/this.alpha,i=0,j=f,k=-1e3,l=0;Math.abs(j-k)>1e-7;){if(++l>20)return;i=1/this.alpha*(Math.log(Math.tan(Math.PI/4+f/2))-this.K)+this.e*Math.log(Math.tan(Math.PI/4+Math.asin(this.e*Math.sin(j))/2)),k=j,j=2*Math.atan(Math.exp(i))-Math.PI/2}return a.x=h,a.y=j,a}function ta(){this.no_off=this.no_off||!1,this.no_rot=this.no_rot||!1,isNaN(this.k0)&&(this.k0=1);var a=Math.sin(this.lat0),b=Math.cos(this.lat0),c=this.e*a;this.bl=Math.sqrt(1+this.es/(1-this.es)*Math.pow(b,4)),this.al=this.a*this.bl*this.k0*Math.sqrt(1-this.es)/(1-c*c);var d=nc(this.e,this.lat0,a),e=this.bl/b*Math.sqrt((1-this.es)/(1-c*c));e*e<1&&(e=1);var f,g;if(isNaN(this.longc)){var h=nc(this.e,this.lat1,Math.sin(this.lat1)),i=nc(this.e,this.lat2,Math.sin(this.lat2));this.lat0>=0?this.el=(e+Math.sqrt(e*e-1))*Math.pow(d,this.bl):this.el=(e-Math.sqrt(e*e-1))*Math.pow(d,this.bl);var j=Math.pow(h,this.bl),k=Math.pow(i,this.bl);f=this.el/j,g=.5*(f-1/f);var l=(this.el*this.el-k*j)/(this.el*this.el+k*j),m=(k-j)/(k+j),n=mc(this.long1-this.long2);this.long0=.5*(this.long1+this.long2)-Math.atan(l*Math.tan(.5*this.bl*n)/m)/this.bl,this.long0=mc(this.long0);var o=mc(this.long1-this.long0);this.gamma0=Math.atan(Math.sin(this.bl*o)/g),this.alpha=Math.asin(e*Math.sin(this.gamma0))}else f=this.lat0>=0?e+Math.sqrt(e*e-1):e-Math.sqrt(e*e-1),this.el=f*Math.pow(d,this.bl),g=.5*(f-1/f),this.gamma0=Math.asin(Math.sin(this.alpha)/e),this.long0=this.longc-Math.asin(g*Math.tan(this.gamma0))/this.bl;this.no_off?this.uc=0:this.lat0>=0?this.uc=this.al/this.bl*Math.atan2(Math.sqrt(e*e-1),Math.cos(this.alpha)):this.uc=-1*this.al/this.bl*Math.atan2(Math.sqrt(e*e-1),Math.cos(this.alpha))}function ua(a){var b,c,d,e=a.x,f=a.y,g=mc(e-this.long0);if(Math.abs(Math.abs(f)-Jb)<=Nb)d=f>0?-1:1,c=this.al/this.bl*Math.log(Math.tan(Qb+d*this.gamma0*.5)),b=-1*d*Jb*this.al/this.bl;else{var h=nc(this.e,f,Math.sin(f)),i=this.el/Math.pow(h,this.bl),j=.5*(i-1/i),k=.5*(i+1/i),l=Math.sin(this.bl*g),m=(j*Math.sin(this.gamma0)-l*Math.cos(this.gamma0))/k;c=Math.abs(Math.abs(m)-1)<=Nb?Number.POSITIVE_INFINITY:.5*this.al*Math.log((1-m)/(1+m))/this.bl,b=Math.abs(Math.cos(this.bl*g))<=Nb?this.al*this.bl*g:this.al*Math.atan2(j*Math.cos(this.gamma0)+l*Math.sin(this.gamma0),Math.cos(this.bl*g))/this.bl}return this.no_rot?(a.x=this.x0+b,a.y=this.y0+c):(b-=this.uc,a.x=this.x0+c*Math.cos(this.alpha)+b*Math.sin(this.alpha),a.y=this.y0+b*Math.cos(this.alpha)-c*Math.sin(this.alpha)),a}function va(a){var b,c;this.no_rot?(c=a.y-this.y0,b=a.x-this.x0):(c=(a.x-this.x0)*Math.cos(this.alpha)-(a.y-this.y0)*Math.sin(this.alpha),b=(a.y-this.y0)*Math.cos(this.alpha)+(a.x-this.x0)*Math.sin(this.alpha),b+=this.uc);var d=Math.exp(-1*this.bl*c/this.al),e=.5*(d-1/d),f=.5*(d+1/d),g=Math.sin(this.bl*b/this.al),h=(g*Math.cos(this.gamma0)+e*Math.sin(this.gamma0))/f,i=Math.pow(this.el/Math.sqrt((1+h)/(1-h)),1/this.bl);return Math.abs(h-1)Nb?this.ns=Math.log(d/h)/Math.log(e/i):this.ns=b,isNaN(this.ns)&&(this.ns=b),this.f0=d/(this.ns*Math.pow(e,this.ns)),this.rh=this.a*this.f0*Math.pow(j,this.ns),this.title||(this.title="Lambert Conformal Conic")}}function xa(a){var b=a.x,c=a.y;Math.abs(2*Math.abs(c)-Math.PI)<=Nb&&(c=lc(c)*(Jb-2*Nb));var d,e,f=Math.abs(Math.abs(c)-Jb);if(f>Nb)d=nc(this.e,c,Math.sin(c)),e=this.a*this.f0*Math.pow(d,this.ns);else{if(f=c*this.ns,f<=0)return null;e=0}var g=this.ns*mc(b-this.long0);return a.x=this.k0*(e*Math.sin(g))+this.x0,a.y=this.k0*(this.rh-e*Math.cos(g))+this.y0,a}function ya(a){var b,c,d,e,f,g=(a.x-this.x0)/this.k0,h=this.rh-(a.y-this.y0)/this.k0;this.ns>0?(b=Math.sqrt(g*g+h*h),c=1):(b=-Math.sqrt(g*g+h*h),c=-1);var i=0;if(0!==b&&(i=Math.atan2(c*g,c*h)),0!==b||this.ns>0){if(c=1/this.ns,d=Math.pow(b/(this.a*this.f0),c),e=oc(this.e,d),e===-9999)return null}else e=-Jb;return f=mc(i/this.ns+this.long0),a.x=f,a.y=e,a}function za(){this.a=6377397.155,this.es=.006674372230614,this.e=Math.sqrt(this.es),this.lat0||(this.lat0=.863937979737193),this.long0||(this.long0=.4334234309119251),this.k0||(this.k0=.9999),this.s45=.785398163397448,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; +}function Aa(a){var b,c,d,e,f,g,h,i=a.x,j=a.y,k=mc(i-this.long0);return b=Math.pow((1+this.e*Math.sin(j))/(1-this.e*Math.sin(j)),this.alfa*this.e/2),c=2*(Math.atan(this.k*Math.pow(Math.tan(j/2+this.s45),this.alfa)/b)-this.s45),d=-k*this.alfa,e=Math.asin(Math.cos(this.ad)*Math.sin(c)+Math.sin(this.ad)*Math.cos(c)*Math.cos(d)),f=Math.asin(Math.cos(c)*Math.sin(d)/Math.cos(e)),g=this.n*f,h=this.ro0*Math.pow(Math.tan(this.s0/2+this.s45),this.n)/Math.pow(Math.tan(e/2+this.s45),this.n),a.y=h*Math.cos(g)/1,a.x=h*Math.sin(g)/1,this.czech||(a.y*=-1,a.x*=-1),a}function Ba(a){var b,c,d,e,f,g,h,i,j=a.x;a.x=a.y,a.y=j,this.czech||(a.y*=-1,a.x*=-1),g=Math.sqrt(a.x*a.x+a.y*a.y),f=Math.atan2(a.y,a.x),e=f/Math.sin(this.s0),d=2*(Math.atan(Math.pow(this.ro0/g,1/this.n)*Math.tan(this.s0/2+this.s45))-this.s45),b=Math.asin(Math.cos(this.ad)*Math.sin(d)-Math.sin(this.ad)*Math.cos(d)*Math.cos(e)),c=Math.asin(Math.cos(d)*Math.sin(e)/Math.cos(b)),a.x=this.long0-c/this.alfa,h=b,i=0;var k=0;do a.y=2*(Math.atan(Math.pow(this.k,-1/this.alfa)*Math.pow(Math.tan(b/2+this.s45),1/this.alfa)*Math.pow((1+this.e*Math.sin(h))/(1-this.e*Math.sin(h)),this.e/2))-this.s45),Math.abs(h-a.y)<1e-10&&(i=1),h=a.y,k+=1;while(0===i&&k<15);return k>=15?null:a}function Ca(){this.sphere||(this.e0=Jd(this.es),this.e1=Kd(this.es),this.e2=Ld(this.es),this.e3=Md(this.es),this.ml0=this.a*Id(this.e0,this.e1,this.e2,this.e3,this.lat0))}function Da(a){var b,c,d=a.x,e=a.y;if(d=mc(d-this.long0),this.sphere)b=this.a*Math.asin(Math.cos(e)*Math.sin(d)),c=this.a*(Math.atan2(Math.tan(e),Math.cos(d))-this.lat0);else{var f=Math.sin(e),g=Math.cos(e),h=Nd(this.a,this.e,f),i=Math.tan(e)*Math.tan(e),j=d*Math.cos(e),k=j*j,l=this.es*g*g/(1-this.es),m=this.a*Id(this.e0,this.e1,this.e2,this.e3,e);b=h*j*(1-k*i*(1/6-(8-i+8*l)*k/120)),c=m-this.ml0+h*f/g*k*(.5+(5-i+6*l)*k/24)}return a.x=b+this.x0,a.y=c+this.y0,a}function Ea(a){a.x-=this.x0,a.y-=this.y0;var b,c,d=a.x/this.a,e=a.y/this.a;if(this.sphere){var f=e+this.lat0;b=Math.asin(Math.sin(f)*Math.cos(d)),c=Math.atan2(Math.tan(d),Math.cos(f))}else{var g=this.ml0/this.a+e,h=Pd(g,this.e0,this.e1,this.e2,this.e3);if(Math.abs(Math.abs(h)-Jb)<=Nb)return a.x=this.long0,a.y=Jb,e<0&&(a.y*=-1),a;var i=Nd(this.a,this.e,Math.sin(h)),j=i*i*i/this.a/this.a*(1-this.es),k=Math.pow(Math.tan(h),2),l=d*this.a/i,m=l*l;b=h-i*Math.tan(h)/j*l*l*(.5-(1+3*k)*l*l/24),c=l*(1-m*(k/3+(1+3*k)*k*m/15))/Math.cos(h)}return a.x=mc(c+this.long0),a.y=Od(b),a}function Fa(){var a=Math.abs(this.lat0);if(Math.abs(a-Jb)0){var b;switch(this.qp=Sd(this.e,1),this.mmf=.5/(1-this.es),this.apa=Ia(this.es),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(.5*this.qp),this.dd=1/this.rq,this.xmf=1,this.ymf=.5*this.qp;break;case this.OBLIQ:this.rq=Math.sqrt(.5*this.qp),b=Math.sin(this.lat0),this.sinb1=Sd(this.e,b)/this.qp,this.cosb1=Math.sqrt(1-this.sinb1*this.sinb1),this.dd=Math.cos(this.lat0)/(Math.sqrt(1-this.es*b*b)*this.rq*this.cosb1),this.ymf=(this.xmf=this.rq)/this.dd,this.xmf*=this.dd}}else this.mode===this.OBLIQ&&(this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0))}function Ga(a){var b,c,d,e,f,g,h,i,j,k,l=a.x,m=a.y;if(l=mc(l-this.long0),this.sphere){if(f=Math.sin(m),k=Math.cos(m),d=Math.cos(l),this.mode===this.OBLIQ||this.mode===this.EQUIT){if(c=this.mode===this.EQUIT?1+k*d:1+this.sinph0*f+this.cosph0*k*d,c<=Nb)return null;c=Math.sqrt(2/c),b=c*k*Math.sin(l),c*=this.mode===this.EQUIT?f:this.cosph0*f-this.sinph0*k*d}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(d=-d),Math.abs(m+this.phi0)=0?(b=(j=Math.sqrt(g))*e,c=d*(this.mode===this.S_POLE?j:-j)):b=c=0}}return a.x=this.a*b+this.x0,a.y=this.a*c+this.y0,a}function Ha(a){a.x-=this.x0,a.y-=this.y0;var b,c,d,e,f,g,h,i=a.x/this.a,j=a.y/this.a;if(this.sphere){var k,l=0,m=0;if(k=Math.sqrt(i*i+j*j),c=.5*k,c>1)return null;switch(c=2*Math.asin(c),this.mode!==this.OBLIQ&&this.mode!==this.EQUIT||(m=Math.sin(c),l=Math.cos(c)),this.mode){case this.EQUIT:c=Math.abs(k)<=Nb?0:Math.asin(j*m/k),i*=m,j=l*k;break;case this.OBLIQ:c=Math.abs(k)<=Nb?this.phi0:Math.asin(l*this.sinph0+j*m*this.cosph0/k),i*=m*this.cosph0,j=(l-Math.sin(c)*this.sinph0)*k;break;case this.N_POLE:j=-j,c=Jb-c;break;case this.S_POLE:c-=Jb}b=0!==j||this.mode!==this.EQUIT&&this.mode!==this.OBLIQ?Math.atan2(i,j):0}else{if(h=0,this.mode===this.OBLIQ||this.mode===this.EQUIT){if(i/=this.dd,j*=this.dd,g=Math.sqrt(i*i+j*j),gNb?this.ns0=(this.ms1*this.ms1-this.ms2*this.ms2)/(this.qs2-this.qs1):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)}function La(a){var b=a.x,c=a.y;this.sin_phi=Math.sin(c),this.cos_phi=Math.cos(c);var d=Sd(this.e3,this.sin_phi,this.cos_phi),e=this.a*Math.sqrt(this.c-this.ns0*d)/this.ns0,f=this.ns0*mc(b-this.long0),g=e*Math.sin(f)+this.x0,h=this.rh-e*Math.cos(f)+this.y0;return a.x=g,a.y=h,a}function Ma(a){var b,c,d,e,f,g;return a.x-=this.x0,a.y=this.rh-a.y+this.y0,this.ns0>=0?(b=Math.sqrt(a.x*a.x+a.y*a.y),d=1):(b=-Math.sqrt(a.x*a.x+a.y*a.y),d=-1),e=0,0!==b&&(e=Math.atan2(d*a.x,d*a.y)),d=b*this.ns0/this.a,this.sphere?g=Math.asin((this.c-d*d)/(2*this.ns0)):(c=(this.c-d*d)/this.ns0,g=this.phi1z(this.e3,c)),f=mc(e/this.ns0+this.long0),a.x=f,a.y=g,a}function Na(a,b){var c,d,e,f,g,h=de(.5*b);if(a0||Math.abs(g)<=Nb?(h=this.x0+this.a*f*c*Math.sin(d)/g,i=this.y0+this.a*f*(this.cos_p14*b-this.sin_p14*c*e)/g):(h=this.x0+this.infinity_dist*c*Math.sin(d),i=this.y0+this.infinity_dist*(this.cos_p14*b-this.sin_p14*c*e)),a.x=h,a.y=i,a}function Qa(a){var b,c,d,e,f,g;return a.x=(a.x-this.x0)/this.a,a.y=(a.y-this.y0)/this.a,a.x/=this.k0,a.y/=this.k0,(b=Math.sqrt(a.x*a.x+a.y*a.y))?(e=Math.atan2(b,this.rc),c=Math.sin(e),d=Math.cos(e),g=de(d*this.sin_p14+a.y*c*this.cos_p14/b),f=Math.atan2(a.x*c,b*this.cos_p14*d-a.y*this.sin_p14*c),f=mc(this.long0+f)):(g=this.phic0,f=0),a.x=f,a.y=g,a}function Ra(){this.sphere||(this.k0=kc(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)))}function Sa(a){var b,c,d=a.x,e=a.y,f=mc(d-this.long0);if(this.sphere)b=this.x0+this.a*f*Math.cos(this.lat_ts),c=this.y0+this.a*Math.sin(e)/Math.cos(this.lat_ts);else{var g=Sd(this.e,Math.sin(e));b=this.x0+this.a*this.k0*f,c=this.y0+this.a*g*.5/this.k0}return a.x=b,a.y=c,a}function Ta(a){a.x-=this.x0,a.y-=this.y0;var b,c;return this.sphere?(b=mc(this.long0+a.x/this.a/Math.cos(this.lat_ts)),c=Math.asin(a.y/this.a*Math.cos(this.lat_ts))):(c=ie(this.e,2*a.y*this.k0/this.a),b=mc(this.long0+a.x/(this.a*this.k0))),a.x=b,a.y=c,a}function Ua(){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)}function Va(a){var b=a.x,c=a.y,d=mc(b-this.long0),e=Od(c-this.lat0);return a.x=this.x0+this.a*d*this.rc,a.y=this.y0+this.a*e,a}function Wa(a){var b=a.x,c=a.y;return a.x=mc(this.long0+(b-this.x0)/(this.a*this.rc)),a.y=Od(this.lat0+(c-this.y0)/this.a),a}function Xa(){this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e=Math.sqrt(this.es),this.e0=Jd(this.es),this.e1=Kd(this.es),this.e2=Ld(this.es),this.e3=Md(this.es),this.ml0=this.a*Id(this.e0,this.e1,this.e2,this.e3,this.lat0)}function Ya(a){var b,c,d,e=a.x,f=a.y,g=mc(e-this.long0);if(d=g*Math.sin(f),this.sphere)Math.abs(f)<=Nb?(b=this.a*g,c=-1*this.a*this.lat0):(b=this.a*Math.sin(d)/Math.tan(f),c=this.a*(Od(f-this.lat0)+(1-Math.cos(d))/Math.tan(f)));else if(Math.abs(f)<=Nb)b=this.a*g,c=-1*this.ml0;else{var h=Nd(this.a,this.e,Math.sin(f))/Math.tan(f);b=h*Math.sin(d),c=this.a*Id(this.e0,this.e1,this.e2,this.e3,f)-this.ml0+h*(1-Math.cos(d))}return a.x=b+this.x0,a.y=c+this.y0,a}function Za(a){var b,c,d,e,f,g,h,i,j;if(d=a.x-this.x0,e=a.y-this.y0,this.sphere)if(Math.abs(e+this.a*this.lat0)<=Nb)b=mc(d/this.a+this.long0),c=0;else{g=this.lat0+e/this.a,h=d*d/this.a/this.a+g*g,i=g;var k;for(f=ne;f;--f)if(k=Math.tan(i),j=-1*(g*(i*k+1)-i-.5*(i*i+h)*k)/((i-g)/k-1),i+=j,Math.abs(j)<=Nb){c=i;break}b=mc(this.long0+Math.asin(d*Math.tan(i)/this.a)/Math.sin(c))}else if(Math.abs(e+this.ml0)<=Nb)c=0,b=mc(this.long0+d/this.a);else{g=(this.ml0+e)/this.a,h=d*d/this.a/this.a+g*g,i=g;var l,m,n,o,p;for(f=ne;f;--f)if(p=this.e*Math.sin(i),l=Math.sqrt(1-p*p)*Math.tan(i),m=this.a*Id(this.e0,this.e1,this.e2,this.e3,i),n=this.e0-2*this.e1*Math.cos(2*i)+4*this.e2*Math.cos(4*i)-6*this.e3*Math.cos(6*i),o=m/this.a,j=(g*(l*o+1)-o-.5*l*(o*o+h))/(this.es*Math.sin(2*i)*(o*o+h-2*g*o)/(4*l)+(g-o)*(l*n-2/Math.sin(2*i))-n),i-=j,Math.abs(j)<=Nb){c=i;break}l=Math.sqrt(1-this.es*Math.pow(Math.sin(c),2))*Math.tan(c),b=mc(this.long0+Math.asin(d*l/this.a)/Math.sin(c))}return a.x=b,a.y=c,a}function $a(){this.A=[],this.A[1]=.6399175073,this.A[2]=-.1358797613,this.A[3]=.063294409,this.A[4]=-.02526853,this.A[5]=.0117879,this.A[6]=-.0055161,this.A[7]=.0026906,this.A[8]=-.001333,this.A[9]=67e-5,this.A[10]=-34e-5,this.B_re=[],this.B_im=[],this.B_re[1]=.7557853228,this.B_im[1]=0,this.B_re[2]=.249204646,this.B_im[2]=.003371507,this.B_re[3]=-.001541739,this.B_im[3]=.04105856,this.B_re[4]=-.10162907,this.B_im[4]=.01727609,this.B_re[5]=-.26623489,this.B_im[5]=-.36249218,this.B_re[6]=-.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]=-.577245789,this.C_im[2]=-.007809598,this.C_re[3]=.508307513,this.C_im[3]=-.112208952,this.C_re[4]=-.15094762,this.C_im[4]=.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]=.5185406398,this.D[3]=-.03333098,this.D[4]=-.1052906,this.D[5]=-.0368594,this.D[6]=.007317,this.D[7]=.0122,this.D[8]=.00394,this.D[9]=-.0013}function _a(a){var b,c=a.x,d=a.y,e=d-this.lat0,f=c-this.long0,g=e/Ib*1e-5,h=f,i=1,j=0;for(b=1;b<=10;b++)i*=g,j+=this.A[b]*i;var k,l,m=j,n=h,o=1,p=0,q=0,r=0;for(b=1;b<=6;b++)k=o*m-p*n,l=p*m+o*n,o=k,p=l,q=q+this.B_re[b]*o-this.B_im[b]*p,r=r+this.B_im[b]*o+this.B_re[b]*p;return a.x=r*this.a+this.x0,a.y=q*this.a+this.y0,a}function ab(a){var b,c,d,e=a.x,f=a.y,g=e-this.x0,h=f-this.y0,i=h/this.a,j=g/this.a,k=1,l=0,m=0,n=0;for(b=1;b<=6;b++)c=k*i-l*j,d=l*i+k*j,k=c,l=d,m=m+this.C_re[b]*k-this.C_im[b]*l,n=n+this.C_im[b]*k+this.C_re[b]*l;for(var o=0;o.999999999999&&(c=.999999999999),b=Math.asin(c);var d=mc(this.long0+a.x/(.900316316158*this.a*Math.cos(b)));d<-Math.PI&&(d=-Math.PI),d>Math.PI&&(d=Math.PI),c=(2*b+Math.sin(2*b))/Math.PI,Math.abs(c)>1&&(c=1);var e=Math.asin(c);return a.x=d,a.y=e,a}function kb(){Math.abs(this.lat1+this.lat2)=0?(c=Math.sqrt(a.x*a.x+a.y*a.y),b=1):(c=-Math.sqrt(a.x*a.x+a.y*a.y),b=-1);var f=0;if(0!==c&&(f=Math.atan2(b*a.x,b*a.y)),this.sphere)return e=mc(this.long0+f/this.ns),d=Od(this.g-c/this.a),a.x=e,a.y=d,a;var g=this.g-c/this.a;return d=Pd(g,this.e0,this.e1,this.e2,this.e3),e=mc(this.long0+f/this.ns),a.x=e,a.y=d,a}function nb(){this.R=this.a}function ob(a){var b,c,d=a.x,e=a.y,f=mc(d-this.long0);Math.abs(e)<=Nb&&(b=this.x0+this.R*f,c=this.y0);var g=de(2*Math.abs(e/Math.PI));(Math.abs(f)<=Nb||Math.abs(Math.abs(e)-Jb)<=Nb)&&(b=this.x0,c=e>=0?this.y0+Math.PI*this.R*Math.tan(.5*g):this.y0+Math.PI*this.R*-Math.tan(.5*g));var h=.5*Math.abs(Math.PI/f-f/Math.PI),i=h*h,j=Math.sin(g),k=Math.cos(g),l=k/(j+k-1),m=l*l,n=l*(2/j-1),o=n*n,p=Math.PI*this.R*(h*(l-o)+Math.sqrt(i*(l-o)*(l-o)-(o+i)*(m-o)))/(o+i);f<0&&(p=-p),b=this.x0+p;var q=i+l;return p=Math.PI*this.R*(n*q-h*Math.sqrt((o+i)*(i+1)-q*q))/(o+i),c=e>=0?this.y0+p:this.y0-p,a.x=b,a.y=c,a}function pb(a){var b,c,d,e,f,g,h,i,j,k,l,m,n;return a.x-=this.x0,a.y-=this.y0,l=Math.PI*this.R,d=a.x/l,e=a.y/l,f=d*d+e*e,g=-Math.abs(e)*(1+f),h=g-2*e*e+d*d,i=-2*g+1+2*e*e+f*f,n=e*e/i+(2*h*h*h/i/i/i-9*g*h/i/i)/27,j=(g-h*h/3/i)/i,k=2*Math.sqrt(-j/3),l=3*n/j/k,Math.abs(l)>1&&(l=l>=0?1:-1),m=Math.acos(l)/3,c=a.y>=0?(-k*Math.cos(m+Math.PI/3)-h/3/i)*Math.PI:-(-k*Math.cos(m+Math.PI/3)-h/3/i)*Math.PI,b=Math.abs(d)2*Jb*this.a)return;return c=b/this.a,d=Math.sin(c),e=Math.cos(c),f=this.long0,Math.abs(b)<=Nb?g=this.lat0:(g=de(e*this.sin_p12+a.y*d*this.cos_p12/b),h=Math.abs(this.lat0)-Jb,f=mc(Math.abs(h)<=Nb?this.lat0>=0?this.long0+Math.atan2(a.x,-a.y):this.long0-Math.atan2(-a.x,a.y):this.long0+Math.atan2(a.x*d,b*this.cos_p12*e-a.y*this.sin_p12*d))),a.x=f,a.y=g,a}return i=Jd(this.es),j=Kd(this.es),k=Ld(this.es),l=Md(this.es),Math.abs(this.sin_p12-1)<=Nb?(m=this.a*Id(i,j,k,l,Jb),b=Math.sqrt(a.x*a.x+a.y*a.y),n=m-b,g=Pd(n/this.a,i,j,k,l),f=mc(this.long0+Math.atan2(a.x,-1*a.y)),a.x=f,a.y=g,a):Math.abs(this.sin_p12+1)<=Nb?(m=this.a*Id(i,j,k,l,Jb),b=Math.sqrt(a.x*a.x+a.y*a.y),n=b-m,g=Pd(n/this.a,i,j,k,l),f=mc(this.long0+Math.atan2(a.x,a.y)),a.x=f,a.y=g,a):(b=Math.sqrt(a.x*a.x+a.y*a.y),q=Math.atan2(a.x,a.y),o=Nd(this.a,this.e,this.sin_p12),r=Math.cos(q),s=this.e*this.cos_p12*r,t=-s*s/(1-this.es),u=3*this.es*(1-t)*this.sin_p12*this.cos_p12*r/(1-this.es),v=b/o,w=v-t*(1+t)*Math.pow(v,3)/6-u*(1+3*t)*Math.pow(v,4)/24,x=1-t*w*w/2-v*w*w*w/6,p=Math.asin(this.sin_p12*Math.cos(w)+this.cos_p12*Math.sin(w)*r),f=mc(this.long0+Math.asin(Math.sin(q)*Math.sin(w)/Math.cos(p))),g=Math.atan((1-this.es*x*this.sin_p12/Math.sin(p))*Math.tan(p)/(1-this.es)),a.x=f,a.y=g,a)}function tb(){this.sin_p14=Math.sin(this.lat0),this.cos_p14=Math.cos(this.lat0)}function ub(a){var b,c,d,e,f,g,h,i,j=a.x,k=a.y;return d=mc(j-this.long0),b=Math.sin(k),c=Math.cos(k),e=Math.cos(d),g=this.sin_p14*b+this.cos_p14*c*e,f=1,(g>0||Math.abs(g)<=Nb)&&(h=this.a*f*c*Math.sin(d),i=this.y0+this.a*f*(this.cos_p14*b-this.sin_p14*c*e)),a.x=h,a.y=i,a}function vb(a){var b,c,d,e,f,g,h;return a.x-=this.x0,a.y-=this.y0,b=Math.sqrt(a.x*a.x+a.y*a.y),c=de(b/this.a),d=Math.sin(c),e=Math.cos(c),g=this.long0,Math.abs(b)<=Nb?(h=this.lat0,a.x=g,a.y=h,a):(h=de(e*this.sin_p14+a.y*d*this.cos_p14/b),f=Math.abs(this.lat0)-Jb,Math.abs(f)<=Nb?(g=mc(this.lat0>=0?this.long0+Math.atan2(a.x,-a.y):this.long0-Math.atan2(-a.x,a.y)),a.x=g,a.y=h,a):(g=mc(this.long0+Math.atan2(a.x*d,b*this.cos_p14*e-a.y*this.sin_p14*d)),a.x=g,a.y=h,a))}function wb(){this.isGeocent=!0}function xb(a){return a}function yb(){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||"Quadrilateralized Spherical Cube",this.face_enum={FRONT:1,RIGHT:2,BACK:3,LEFT:4,TOP:5,BOTTOM:6},this.area_enum={AREA_0:1,AREA_1:2,AREA_2:3,AREA_3:4},this.lat0>=Jb-Qb/2?this.face=this.face_enum.TOP:this.lat0<=-(Jb-Qb/2)?this.face=this.face_enum.BOTTOM:Math.abs(this.long0)<=Qb?this.face=this.face_enum.FRONT:Math.abs(this.long0)<=Jb+Qb?this.face=this.long0>0?this.face_enum.RIGHT:this.face_enum.LEFT:this.face=this.face_enum.BACK,0!==this.es&&(this.one_minus_f=1-(this.a-this.b)/this.a,this.one_minus_f_squared=this.one_minus_f*this.one_minus_f)}function zb(a){var b,c,d,e,f,g,h={x:0,y:0},i={value:0};if(a.x-=this.long0,b=0!==this.es?Math.atan(this.one_minus_f_squared*Math.tan(a.y)):a.y,c=a.x,this.face===this.face_enum.TOP)e=Jb-b,c>=Qb&&c<=Jb+Qb?(i.value=this.area_enum.AREA_0,d=c-Jb):c>Jb+Qb||c<=-(Jb+Qb)?(i.value=this.area_enum.AREA_1,d=c>0?c-Sb:c+Sb):c>-(Jb+Qb)&&c<=-Qb?(i.value=this.area_enum.AREA_2,d=c+Jb):(i.value=this.area_enum.AREA_3,d=c);else if(this.face===this.face_enum.BOTTOM)e=Jb+b,c>=Qb&&c<=Jb+Qb?(i.value=this.area_enum.AREA_0,d=-c+Jb):c=-Qb?(i.value=this.area_enum.AREA_1,d=-c):c<-Qb&&c>=-(Jb+Qb)?(i.value=this.area_enum.AREA_2,d=-c-Jb):(i.value=this.area_enum.AREA_3,d=c>0?-c+Sb:-c-Sb);else{var j,k,l,m,n,o,p;this.face===this.face_enum.RIGHT?c=this.qsc_shift_lon_origin(c,+Jb):this.face===this.face_enum.BACK?c=this.qsc_shift_lon_origin(c,+Sb):this.face===this.face_enum.LEFT&&(c=this.qsc_shift_lon_origin(c,-Jb)),m=Math.sin(b),n=Math.cos(b),o=Math.sin(c),p=Math.cos(c),j=n*p,k=n*o,l=m,this.face===this.face_enum.FRONT?(e=Math.acos(j),d=this.qsc_fwd_equat_face_theta(e,l,k,i)):this.face===this.face_enum.RIGHT?(e=Math.acos(k),d=this.qsc_fwd_equat_face_theta(e,l,-j,i)):this.face===this.face_enum.BACK?(e=Math.acos(-j),d=this.qsc_fwd_equat_face_theta(e,l,-k,i)):this.face===this.face_enum.LEFT?(e=Math.acos(-k),d=this.qsc_fwd_equat_face_theta(e,l,j,i)):(e=d=0,i.value=this.area_enum.AREA_0)}return g=Math.atan(12/Sb*(d+Math.acos(Math.sin(d)*Math.cos(Qb))-Jb)),f=Math.sqrt((1-Math.cos(e))/(Math.cos(g)*Math.cos(g))/(1-Math.cos(Math.atan(1/Math.cos(d))))),i.value===this.area_enum.AREA_1?g+=Jb:i.value===this.area_enum.AREA_2?g+=Sb:i.value===this.area_enum.AREA_3&&(g+=1.5*Sb),h.x=f*Math.cos(g),h.y=f*Math.sin(g),h.x=h.x*this.a+this.x0,h.y=h.y*this.a+this.y0,a.x=h.x,a.y=h.y,a}function Ab(a){var b,c,d,e,f,g,h,i,j,k={lam:0,phi:0},l={value:0};if(a.x=(a.x-this.x0)/this.a,a.y=(a.y-this.y0)/this.a,c=Math.atan(Math.sqrt(a.x*a.x+a.y*a.y)),b=Math.atan2(a.y,a.x),a.x>=0&&a.x>=Math.abs(a.y)?l.value=this.area_enum.AREA_0:a.y>=0&&a.y>=Math.abs(a.x)?(l.value=this.area_enum.AREA_1,b-=Jb):a.x<0&&-a.x>=Math.abs(a.y)?(l.value=this.area_enum.AREA_2,b=b<0?b+Sb:b-Sb):(l.value=this.area_enum.AREA_3,b+=Jb),j=Sb/12*Math.tan(b),f=Math.sin(j)/(Math.cos(j)-1/Math.sqrt(2)),g=Math.atan(f),d=Math.cos(b),e=Math.tan(c),h=1-d*d*e*e*(1-Math.cos(Math.atan(1/Math.cos(g)))),h<-1?h=-1:h>1&&(h=1),this.face===this.face_enum.TOP)i=Math.acos(h),k.phi=Jb-i,l.value===this.area_enum.AREA_0?k.lam=g+Jb:l.value===this.area_enum.AREA_1?k.lam=g<0?g+Sb:g-Sb:l.value===this.area_enum.AREA_2?k.lam=g-Jb:k.lam=g;else if(this.face===this.face_enum.BOTTOM)i=Math.acos(h),k.phi=i-Jb,l.value===this.area_enum.AREA_0?k.lam=-g+Jb:l.value===this.area_enum.AREA_1?k.lam=-g:l.value===this.area_enum.AREA_2?k.lam=-g-Jb:k.lam=g<0?-g-Sb:-g+Sb;else{var m,n,o;m=h,j=m*m,o=j>=1?0:Math.sqrt(1-j)*Math.sin(g),j+=o*o,n=j>=1?0:Math.sqrt(1-j),l.value===this.area_enum.AREA_1?(j=n,n=-o,o=j):l.value===this.area_enum.AREA_2?(n=-n,o=-o):l.value===this.area_enum.AREA_3&&(j=n,n=o,o=-j),this.face===this.face_enum.RIGHT?(j=m,m=-n,n=j):this.face===this.face_enum.BACK?(m=-m,n=-n):this.face===this.face_enum.LEFT&&(j=m,m=n,n=-j),k.phi=Math.acos(-o)-Jb,k.lam=Math.atan2(n,m),this.face===this.face_enum.RIGHT?k.lam=this.qsc_shift_lon_origin(k.lam,-Jb):this.face===this.face_enum.BACK?k.lam=this.qsc_shift_lon_origin(k.lam,-Sb):this.face===this.face_enum.LEFT&&(k.lam=this.qsc_shift_lon_origin(k.lam,+Jb))}if(0!==this.es){var p,q,r;p=k.phi<0?1:0,q=Math.tan(k.phi),r=this.b/Math.sqrt(q*q+this.one_minus_f_squared),k.phi=Math.atan(Math.sqrt(this.a*this.a-r*r)/(this.one_minus_f*r)),p&&(k.phi=-k.phi)}return k.lam+=this.long0,a.x=k.lam,a.y=k.phi,a}function Bb(a,b,c,d){var e;return aQb&&e<=Jb+Qb?(d.value=this.area_enum.AREA_1,e-=Jb):e>Jb+Qb||e<=-(Jb+Qb)?(d.value=this.area_enum.AREA_2,e=e>=0?e-Sb:e+Sb):(d.value=this.area_enum.AREA_3,e+=Jb)),e}function Cb(a,b){var c=a+b;return c<-Sb?c+=Rb:c>+Sb&&(c-=Rb),c}var Db=function(a){a("EPSG:4326","+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"),a("EPSG:4269","+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees"),a("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"),a.WGS84=a["EPSG:4326"],a["EPSG:3785"]=a["EPSG:3857"],a.GOOGLE=a["EPSG:3857"],a["EPSG:900913"]=a["EPSG:3857"],a["EPSG:102113"]=a["EPSG:3857"]},Eb=1,Fb=2,Gb=4,Hb=5,Ib=484813681109536e-20,Jb=Math.PI/2,Kb=.16666666666666666,Lb=.04722222222222222,Mb=.022156084656084655,Nb="undefined"==typeof Number.EPSILON?1e-10:Number.EPSILON,Ob=.017453292519943295,Pb=57.29577951308232,Qb=Math.PI/4,Rb=2*Math.PI,Sb=3.14159265359,Tb={};Tb.greenwich=0,Tb.lisbon=-9.131906111111,Tb.paris=2.337229166667,Tb.bogota=-74.080916666667,Tb.madrid=-3.687938888889,Tb.rome=12.452333333333,Tb.bern=7.439583333333,Tb.jakarta=106.807719444444,Tb.ferro=-17.666666666667,Tb.brussels=4.367975,Tb.stockholm=18.058277777778,Tb.athens=23.7163375,Tb.oslo=10.722916666667;var Ub={ft:{to_meter:.3048},"us-ft":{to_meter:1200/3937}},Vb=/[\s_\-\/\(\)]/g,Wb=function(b){var c,d,e,f={},g=b.split("+").map(function(a){return a.trim()}).filter(function(a){return a}).reduce(function(a,b){var c=b.split("=");return c.push(!0),a[c[0].toLowerCase()]=c[1],a},{}),h={proj:"projName",datum:"datumCode",rf:function(a){f.rf=parseFloat(a)},lat_0:function(a){f.lat0=a*Ob},lat_1:function(a){f.lat1=a*Ob},lat_2:function(a){f.lat2=a*Ob},lat_ts:function(a){f.lat_ts=a*Ob},lon_0:function(a){f.long0=a*Ob},lon_1:function(a){f.long1=a*Ob},lon_2:function(a){f.long2=a*Ob},alpha:function(a){f.alpha=parseFloat(a)*Ob},lonc:function(a){f.longc=a*Ob},x_0:function(a){f.x0=parseFloat(a)},y_0:function(a){f.y0=parseFloat(a)},k_0:function(a){f.k0=parseFloat(a)},k:function(a){f.k0=parseFloat(a)},a:function(a){f.a=parseFloat(a)},b:function(a){f.b=parseFloat(a)},r_a:function(){f.R_A=!0},zone:function(a){f.zone=parseInt(a,10)},south:function(){f.utmSouth=!0},towgs84:function(a){f.datum_params=a.split(",").map(function(a){return parseFloat(a)})},to_meter:function(a){f.to_meter=parseFloat(a)},units:function(b){f.units=b;var c=a(Ub,b);c&&(f.to_meter=c.to_meter)},from_greenwich:function(a){f.from_greenwich=a*Ob},pm:function(b){var c=a(Tb,b);f.from_greenwich=(c?c:parseFloat(b))*Ob},nadgrids:function(a){"@null"===a?f.datumCode="none":f.nadgrids=a},axis:function(a){var b="ewnsud";3===a.length&&b.indexOf(a.substr(0,1))!==-1&&b.indexOf(a.substr(1,1))!==-1&&b.indexOf(a.substr(2,1))!==-1&&(f.axis=a)}};for(c in g)d=g[c],c in h?(e=h[c],"function"==typeof e?e(d):f[e]=d):f[c]=d;return"string"==typeof f.datumCode&&"WGS84"!==f.datumCode&&(f.datumCode=f.datumCode.toLowerCase()),f},Xb=1,Yb=2,Zb=3,$b=4,_b=5,ac=-1,bc=/\s/,cc=/[A-Za-z]/,dc=/[A-Za-z84]/,ec=/[,\]]/,fc=/[\d\.E\-\+]/;b.prototype.readCharicter=function(){var a=this.text[this.place++];if(this.state!==$b)for(;bc.test(a);){if(this.place>=this.text.length)return;a=this.text[this.place++]}switch(this.state){case Xb:return this.neutral(a);case Yb:return this.keyword(a);case $b:return this.quoted(a);case _b:return this.afterquote(a);case Zb:return this.number(a);case ac:return}},b.prototype.afterquote=function(a){if('"'===a)return this.word+='"',void(this.state=$b);if(ec.test(a))return this.word=this.word.trim(),void this.afterItem(a);throw new Error("havn't handled \""+a+'" in afterquote yet, index '+this.place)},b.prototype.afterItem=function(a){return","===a?(null!==this.word&&this.currentObject.push(this.word),this.word=null,void(this.state=Xb)):"]"===a?(this.level--,null!==this.word&&(this.currentObject.push(this.word),this.word=null),this.state=Xb,this.currentObject=this.stack.pop(),void(this.currentObject||(this.state=ac))):void 0},b.prototype.number=function(a){if(fc.test(a))return void(this.word+=a);if(ec.test(a))return this.word=parseFloat(this.word),void this.afterItem(a);throw new Error("havn't handled \""+a+'" in number yet, index '+this.place)},b.prototype.quoted=function(a){return'"'===a?void(this.state=_b):void(this.word+=a)},b.prototype.keyword=function(a){if(dc.test(a))return void(this.word+=a);if("["===a){var b=[];return b.push(this.word),this.level++,null===this.root?this.root=b:this.currentObject.push(b),this.stack.push(this.currentObject),this.currentObject=b,void(this.state=Xb)}if(ec.test(a))return void this.afterItem(a);throw new Error("havn't handled \""+a+'" in keyword yet, index '+this.place)},b.prototype.neutral=function(a){if(cc.test(a))return this.word=a,void(this.state=Yb);if('"'===a)return this.word="",void(this.state=$b);if(fc.test(a))return this.word=a,void(this.state=Zb);if(ec.test(a))return void this.afterItem(a);throw new Error("havn't handled \""+a+'" in neutral yet, index '+this.place)},b.prototype.output=function(){for(;this.place2&&(b.z=a[2]),a.length>3&&(b.m=a[3]),b},Dc=z("WGS84"),Ec=6,Fc="AJSAJS",Gc="AFAFAF",Hc=65,Ic=73,Jc=79,Kc=86,Lc=90,Mc={forward:L,inverse:M,toPoint:N};Point.fromMGRS=function(a){return new Point(N(a))},Point.prototype.toMGRS=function(a){return L([this.x,this.y],a)};var Nc="2.4.4-alpha",Oc=1,Pc=.25,Qc=.046875,Rc=.01953125,Sc=.01068115234375,Tc=.75,Uc=.46875,Vc=.013020833333333334,Wc=.007120768229166667,Xc=.3645833333333333,Yc=.005696614583333333,Zc=.3076171875,$c=function(a){var b=[];b[0]=Oc-a*(Pc+a*(Qc+a*(Rc+a*Sc))),b[1]=a*(Tc-a*(Qc+a*(Rc+a*Sc)));var c=a*a;return b[2]=c*(Uc-a*(Vc+a*Wc)),c*=a,b[3]=c*(Xc-a*Yc),b[4]=c*a*Zc,b},_c=function(a,b,c,d){return c*=b,b*=b,d[0]*a-c*(d[1]+b*(d[2]+b*(d[3]+b*d[4])))},ad=20,bd=function(a,b,c){for(var d=1/(1-b),e=a,f=ad;f;--f){var g=Math.sin(e),h=1-b*g*g;if(h=(_c(e,g,Math.cos(e),c)-a)*(h*Math.sqrt(h))*d,e-=h,Math.abs(h)=0;)c=-g+d*f+a[e],g=f,f=c;return b+c*Math.sin(2*b)},jd=function(a,b){for(var c,d=2*Math.cos(b),e=a.length-1,f=a[e],g=0;--e>=0;)c=-g+d*f+a[e],g=f,f=c;return Math.sin(b)*c},kd=function(a){var b=Math.exp(a);return b=(b+1/b)/2},ld=function(a,b,c){for(var d,e,f=Math.sin(b),g=Math.cos(b),h=ed(c),i=kd(c),j=2*g*i,k=-2*f*h,l=a.length-1,m=a[l],n=0,o=0,p=0;--l>=0;)d=o,e=n,o=m,n=p,m=-d+j*o-k*n+a[l],p=-e+k*o+j*n;return j=f*i,k=g*h,[j*m-k*p,j*p+k*m]},md=["Extended_Transverse_Mercator","Extended Transverse Mercator","etmerc"],nd={init:ca,forward:da,inverse:ea,names:md},od=function(a,b){if(void 0===a){if(a=Math.floor(30*(mc(b)+Math.PI)/Math.PI)+1,a<0)return 0;if(a>60)return 60}return a},pd="etmerc",qd=["Universal Transverse Mercator System","utm"],rd={init:fa,names:qd,dependsOn:pd},sd=function(a,b){return Math.pow((1-a)/(1+a),b)},td=20,ud=["gauss"],vd={init:ga,forward:ha,inverse:ia,names:ud},wd=["Stereographic_North_Pole","Oblique_Stereographic","Polar_Stereographic","sterea","Oblique Stereographic Alternative"],xd={init:ja,forward:ka,inverse:la,names:wd},yd=["stere","Stereographic_South_Pole","Polar Stereographic (variant B)"],zd={init:na,forward:oa,inverse:pa,names:yd,ssfn_:ma},Ad=["somerc"],Bd={init:qa,forward:ra,inverse:sa,names:Ad},Cd=["Hotine_Oblique_Mercator","Hotine Oblique Mercator","Hotine_Oblique_Mercator_Azimuth_Natural_Origin","Hotine_Oblique_Mercator_Azimuth_Center","omerc"],Dd={init:ta,forward:ua,inverse:va,names:Cd},Ed=["Lambert Tangential Conformal Conic Projection","Lambert_Conformal_Conic","Lambert_Conformal_Conic_2SP","lcc"],Fd={init:wa,forward:xa,inverse:ya,names:Ed},Gd=["Krovak","krovak"],Hd={init:za,forward:Aa,inverse:Ba,names:Gd},Id=function(a,b,c,d,e){return a*e-b*Math.sin(2*e)+c*Math.sin(4*e)-d*Math.sin(6*e)},Jd=function(a){return 1-.25*a*(1+a/16*(3+1.25*a))},Kd=function(a){return.375*a*(1+.25*a*(1+.46875*a))},Ld=function(a){return.05859375*a*a*(1+.75*a)},Md=function(a){return a*a*a*(35/3072)},Nd=function(a,b,c){var d=b*c;return a/Math.sqrt(1-d*d)},Od=function(a){return Math.abs(a)1e-7?(c=a*b,(1-a*a)*(b/(1-c*c)-.5/a*Math.log((1-c)/(1+c)))):2*b},Td=1,Ud=2,Vd=3,Wd=4,Xd=.3333333333333333,Yd=.17222222222222222,Zd=.10257936507936508,$d=.06388888888888888,_d=.0664021164021164,ae=.016415012942191543,be=["Lambert Azimuthal Equal Area","Lambert_Azimuthal_Equal_Area","laea"],ce={init:Fa,forward:Ga,inverse:Ha,names:be,S_POLE:Td,N_POLE:Ud,EQUIT:Vd,OBLIQ:Wd},de=function(a){return Math.abs(a)>1&&(a=a>1?1:-1),Math.asin(a)},ee=["Albers_Conic_Equal_Area","Albers","aea"],fe={init:Ka,forward:La,inverse:Ma,names:ee,phi1z:Na},ge=["gnom"],he={init:Oa,forward:Pa,inverse:Qa,names:ge},ie=function(a,b){var c=1-(1-a*a)/(2*a)*Math.log((1-a)/(1+a));if(Math.abs(Math.abs(b)-c)<1e-6)return b<0?-1*Jb:Jb;for(var d,e,f,g,h=Math.asin(.5*b),i=0;i<30;i++)if(e=Math.sin(h),f=Math.cos(h),g=a*e,d=Math.pow(1-g*g,2)/(2*f)*(b/(1-a*a)-e/(1-g*g)+.5/a*Math.log((1-g)/(1+g))),h+=d,Math.abs(d)<=1e-10)return h;return NaN},je=["cea"],ke={init:Ra,forward:Sa,inverse:Ta,names:je},le=["Equirectangular","Equidistant_Cylindrical","eqc"],me={init:Ua,forward:Va,inverse:Wa,names:le},ne=20,oe=["Polyconic","poly"],pe={init:Xa,forward:Ya,inverse:Za,names:oe},qe=["New_Zealand_Map_Grid","nzmg"],re={init:$a,forward:_a,inverse:ab,names:qe},se=["Miller_Cylindrical","mill"],te={init:bb,forward:cb,inverse:db,names:se},ue=20,ve=["Sinusoidal","sinu"],we={init:eb,forward:fb,inverse:gb,names:ve},xe=["Mollweide","moll"],ye={init:hb,forward:ib,inverse:jb,names:xe},ze=["Equidistant_Conic","eqdc"],Ae={init:kb,forward:lb,inverse:mb,names:ze},Be=["Van_der_Grinten_I","VanDerGrinten","vandg"],Ce={init:nb,forward:ob,inverse:pb,names:Be},De=["Azimuthal_Equidistant","aeqd"],Ee={init:qb,forward:rb,inverse:sb,names:De},Fe=["ortho"],Ge={init:tb,forward:ub,inverse:vb,names:Fe},He=["geocent"],Ie={init:wb,forward:xb,inverse:xb,names:He},Je=["Quadrilateralized Spherical Cube","qsc"],Ke={init:yb,forward:zb,inverse:Ab,names:Je,qsc_fwd_equat_face_theta:Bb,qsc_shift_lon_origin:Cb},Le=function(_mproj4_){_mproj4_.Proj.projections.add(dd),_mproj4_.Proj.projections.add(nd),_mproj4_.Proj.projections.add(rd),_mproj4_.Proj.projections.add(xd),_mproj4_.Proj.projections.add(zd),_mproj4_.Proj.projections.add(Bd),_mproj4_.Proj.projections.add(Dd),_mproj4_.Proj.projections.add(Fd),_mproj4_.Proj.projections.add(Hd),_mproj4_.Proj.projections.add(Rd),_mproj4_.Proj.projections.add(ce),_mproj4_.Proj.projections.add(fe),_mproj4_.Proj.projections.add(he),_mproj4_.Proj.projections.add(ke),_mproj4_.Proj.projections.add(me),_mproj4_.Proj.projections.add(pe),_mproj4_.Proj.projections.add(re),_mproj4_.Proj.projections.add(te),_mproj4_.Proj.projections.add(we),_mproj4_.Proj.projections.add(ye),_mproj4_.Proj.projections.add(Ae),_mproj4_.Proj.projections.add(Ce),_mproj4_.Proj.projections.add(Ee),_mproj4_.Proj.projections.add(Ge),_mproj4_.Proj.projections.add(Ie),_mproj4_.Proj.projections.add(Ke)};return K.defaultDatum="WGS84",K.Proj=z,K.WGS84=new K.Proj("WGS84"),K.Point=Point,K.toPoint=Cc,K.defs=i,K.transform=H,K.mgrs=Mc,K.version=Nc,Le(K),K}); \ No newline at end of file diff --git a/src/core/utils/utils.js b/src/core/utils/utils.js index 1aa0812b..aa9db637 100755 --- a/src/core/utils/utils.js +++ b/src/core/utils/utils.js @@ -1 +1 @@ - Melown.isEqual = function(value_, value2_, delta_) { return (Math.abs(value_ - value2_) < delta_); }; Melown.clamp = function(value_, min_, max_) { if (value_ < min_) value_ = min_; else if (value_ > max_) value_ = max_; return value_; }; Melown.radians = function(degrees_) { return degrees_ * Math.PI / 180; }; Melown.degrees = function(radians_) { return (radians_ / Math.PI) * 180; }; Melown.mix = function(a, b, c) { return a + (b - a) * c; }; Melown.validateBool = function(value_, defaultValue_) { if (typeof value_ === "boolean") { return value_; } else { return defaultValue_; } }; Melown.validateNumber = function(value_, minValue, maxValue, defaultValue_) { if (typeof value_ === "number") { return Melown.clamp(value_, minValue, maxValue); } else { return defaultValue_; } }; Melown.validateString = function(value_, defaultValue_) { if (typeof value_ === "string") { return value_; } else { return defaultValue_; } }; Melown.padNumber = function(n, width_) { var z = '0'; if (n < 0) { n = (-n) + ''; width_--; //7 return n.length >= width_ ? ("-" + n) : "-" + (new Array(width_ - n.length + 1).join(z) + n); } else { n = n + ''; return n.length >= width_ ? n : new Array(width_ - n.length + 1).join(z) + n; } }; Melown.decodeFloat16 = function(binary) { var exponent = (binary & 0x7C00) >> 10; fraction = binary & 0x03FF; return (binary >> 15 ? -1 : 1) * ( exponent ? ( exponent === 0x1F ? fraction ? NaN : Infinity : Math.pow(2, exponent - 15) * (1 + fraction / 0x400) ) : 6.103515625e-5 * (fraction / 0x400) ); }; Melown.simpleFmtObj = (function obj(str, obj) { if (!str || str == "") { return ""; } return str.replace(/\{([_$a-zA-Z0-9][_$a-zA-Z0-9]*)\}/g, function(s, match) { return (match in obj ? obj[match] : s); }); }); Melown.simpleWikiLinks = (function obj(str_, plain_) { if (!str_ || str_ == "") { return ""; } var str2_ = Melown.simpleFmtObj(str_, {"copy":"©", "Y": (new Date().getFullYear())}); return str2_.replace(/\[([^\]]*)\]/g, function(s, match_) { match_ = match_.trim(); urls_ = match_.split(" ");//, 1); if (urls_[0].indexOf("//") != -1) { if (plain_) { if (urls_.length > 1) { return "" + match_.substring(urls_[0].length); } else { return "" + urls_[0]; } } else { if (urls_.length > 1) { return "" + match_.substring(urls_[0].length)+""; } else { return "" + urls_[0]+""; } } } return match_; }); }); Melown.simpleFmtObjOrCall = (function obj(str, obj, call) { if (!str || str == "") { return ""; } return str.replace(/\{([_$a-zA-Z(-9][_$a-zA-Z(-9]*)\}/g, function(s, match) { return (match in obj ? obj[match] : call(match)); }); }); Melown.getABGRFromHexaCode = (function(code_) { var result_ = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(code_); return result_ ? [ parseInt(result_[4], 16), parseInt(result_[3], 16), parseInt(result_[2], 16), parseInt(result_[1], 16)] : [0,0,0,255]; }); Melown.stringifyFunction = (function(function_) { // Stringify the code return '(' + function_ + ').call(self);'; }); Melown.loadJSON = function(path_, onLoaded_, onError_, skipParse_, withCredentials_, xhrParams_) { var xhr_ = new XMLHttpRequest(); //xhr_.onload = (function() { xhr_.onreadystatechange = (function (){ switch (xhr_.readyState) { case 0 : // UNINITIALIZED case 1 : // LOADING case 2 : // LOADED case 3 : // INTERACTIVE break; case 4 : // COMPLETED if (xhr_.status >= 400 || xhr_.status == 0) { if (onError_) { onError_(xhr_.status); } break; } var data_ = xhr_.response; var parsedData_ = data_; if (!skipParse_) { try { //var parsedData_ = skipParse_ ? data_ : eval("("+data_+")"); parsedData_ = JSON.parse(data_); } catch(e) { console.log("JSON Parse Error ("+path_+"): " + (e["message"] ? e["message"] : "")); if (onError_ ) { onError_(xhr_.status); } return; } } if (onLoaded_) { onLoaded_(parsedData_); } break; } }).bind(this); /* xhr_.onerror = (function() { if (onError_) { onError_(); } }).bind(this);*/ xhr_.open('GET', path_, true); xhr_.withCredentials = withCredentials_; if (xhrParams_ && xhrParams_["token"] /*&& xhrParams_["tokenHeader"]*/) { //xhr_.setRequestHeader(xhrParams_["tokenHeader"], xhrParams_["token"]); //old way xhr_.setRequestHeader("Accept", "token/" + xhrParams_["token"] + ", */*"); } xhr_.send(""); }; Melown.loadBinary = function(path_, onLoaded_, onError_, withCredentials_, xhrParams_, responseType_) { var xhr_ = new XMLHttpRequest(); xhr_.onreadystatechange = (function (){ switch (xhr_.readyState) { case 0 : // UNINITIALIZED case 1 : // LOADING case 2 : // LOADED case 3 : // INTERACTIVE break; case 4 : // COMPLETED if (xhr_.status >= 400 || xhr_.status == 0) { if (onError_) { onError_(xhr_.status); } break; } var abuffer_ = xhr_.response; if (!abuffer_) { if (onError_) { onError_(); } break; } //if (!responseType_ || responseType_ == "arraybuffer") { //var data_ = new DataView(abuffer_); //} else { // var data_ = abuffer_; //} if (onLoaded_) { onLoaded_(abuffer_); } break; default: if (onError_) { onError_(); } break; } }).bind(this); /* xhr_.onerror = (function() { if (onError_) { onError_(); } }).bind(this);*/ xhr_.open('GET', path_, true); xhr_.responseType = responseType_ ? responseType_ : "arraybuffer"; xhr_.withCredentials = withCredentials_; if (xhrParams_ && xhrParams_["token"] /*&& xhrParams_["tokenHeader"]*/) { //xhr_.setRequestHeader(xhrParams_["tokenHeader"], xhrParams_["token"]); //old way xhr_.setRequestHeader("Accept", "token/" + xhrParams_["token"] + ", */*"); } xhr_.send(""); }; window.performance = window.performance || {}; performance.now = (function() { return performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() { return new Date().getTime(); }; })(); //Provides requestAnimationFrame in a cross browser way. window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) { window.setTimeout(callback, 1000/60); }; })(); // only implement if no native implementation is available if (typeof Array.isArray === 'undefined') { Array.isArray = (function(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }); } Melown["isEqual"] = Melown.isEqual; Melown["clamp"] = Melown.clamp; Melown["mix"] = Melown.mix; Melown["radians"] = Melown.radians; Melown["degrees"] = Melown.degrees; Melown["loadJSON"] = Melown.loadJSON; Melown["loadBinary"] = Melown.loadBinary; \ No newline at end of file + Melown.isEqual = function(value_, value2_, delta_) { return (Math.abs(value_ - value2_) < delta_); }; Melown.clamp = function(value_, min_, max_) { if (value_ < min_) value_ = min_; else if (value_ > max_) value_ = max_; return value_; }; Melown.radians = function(degrees_) { return degrees_ * Math.PI / 180; }; Melown.degrees = function(radians_) { return (radians_ / Math.PI) * 180; }; Melown.mix = function(a, b, c) { return a + (b - a) * c; }; Melown.validateBool = function(value_, defaultValue_) { if (typeof value_ === "boolean") { return value_; } else { return defaultValue_; } }; Melown.validateNumber = function(value_, minValue, maxValue, defaultValue_) { if (typeof value_ === "number") { return Melown.clamp(value_, minValue, maxValue); } else { return defaultValue_; } }; Melown.validateNumberArray = function(array_, arraySize_, minValues_, maxValues_, defaultValues_) { if (Array.isArray(array_) && array_.length == arraySize_) { for (var i = 0; i < arraySize_; i++) { array_[i] = Melown.clamp(array_[i], minValues_[i], maxValues_[i]); } return array_; } else { return defaultValues_; } }; Melown.validateString = function(value_, defaultValue_) { if (typeof value_ === "string") { return value_; } else { return defaultValue_; } }; Melown.padNumber = function(n, width_) { var z = '0'; if (n < 0) { n = (-n) + ''; width_--; //7 return n.length >= width_ ? ("-" + n) : "-" + (new Array(width_ - n.length + 1).join(z) + n); } else { n = n + ''; return n.length >= width_ ? n : new Array(width_ - n.length + 1).join(z) + n; } }; Melown.decodeFloat16 = function(binary) { var exponent = (binary & 0x7C00) >> 10; fraction = binary & 0x03FF; return (binary >> 15 ? -1 : 1) * ( exponent ? ( exponent === 0x1F ? fraction ? NaN : Infinity : Math.pow(2, exponent - 15) * (1 + fraction / 0x400) ) : 6.103515625e-5 * (fraction / 0x400) ); }; Melown.simpleFmtObj = (function obj(str, obj) { if (!str || str == "") { return ""; } return str.replace(/\{([_$a-zA-Z0-9][_$a-zA-Z0-9]*)\}/g, function(s, match) { return (match in obj ? obj[match] : s); }); }); Melown.simpleWikiLinks = (function obj(str_, plain_) { if (!str_ || str_ == "") { return ""; } var str2_ = Melown.simpleFmtObj(str_, {"copy":"©", "Y": (new Date().getFullYear())}); return str2_.replace(/\[([^\]]*)\]/g, function(s, match_) { match_ = match_.trim(); urls_ = match_.split(" ");//, 1); if (urls_[0].indexOf("//") != -1) { if (plain_) { if (urls_.length > 1) { return "" + match_.substring(urls_[0].length); } else { return "" + urls_[0]; } } else { if (urls_.length > 1) { return "" + match_.substring(urls_[0].length)+""; } else { return "" + urls_[0]+""; } } } return match_; }); }); Melown.simpleFmtObjOrCall = (function obj(str, obj, call) { if (!str || str == "") { return ""; } return str.replace(/\{([_$a-zA-Z(-9][_$a-zA-Z(-9]*)\}/g, function(s, match) { return (match in obj ? obj[match] : call(match)); }); }); Melown.getABGRFromHexaCode = (function(code_) { var result_ = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(code_); return result_ ? [ parseInt(result_[4], 16), parseInt(result_[3], 16), parseInt(result_[2], 16), parseInt(result_[1], 16)] : [0,0,0,255]; }); Melown.stringifyFunction = (function(function_) { // Stringify the code return '(' + function_ + ').call(self);'; }); Melown.loadJSON = function(path_, onLoaded_, onError_, skipParse_, withCredentials_, xhrParams_) { var xhr_ = new XMLHttpRequest(); //xhr_.onload = (function() { xhr_.onreadystatechange = (function (){ switch (xhr_.readyState) { case 0 : // UNINITIALIZED case 1 : // LOADING case 2 : // LOADED case 3 : // INTERACTIVE break; case 4 : // COMPLETED if (xhr_.status >= 400 || xhr_.status == 0) { if (onError_) { onError_(xhr_.status); } break; } var data_ = xhr_.response; var parsedData_ = data_; if (!skipParse_) { try { //var parsedData_ = skipParse_ ? data_ : eval("("+data_+")"); parsedData_ = JSON.parse(data_); } catch(e) { console.log("JSON Parse Error ("+path_+"): " + (e["message"] ? e["message"] : "")); if (onError_ ) { onError_(xhr_.status); } return; } } if (onLoaded_) { onLoaded_(parsedData_); } break; } }).bind(this); /* xhr_.onerror = (function() { if (onError_) { onError_(); } }).bind(this);*/ xhr_.open('GET', path_, true); xhr_.withCredentials = withCredentials_; if (xhrParams_ && xhrParams_["token"] /*&& xhrParams_["tokenHeader"]*/) { //xhr_.setRequestHeader(xhrParams_["tokenHeader"], xhrParams_["token"]); //old way xhr_.setRequestHeader("Accept", "token/" + xhrParams_["token"] + ", */*"); } xhr_.send(""); }; Melown.loadBinary = function(path_, onLoaded_, onError_, withCredentials_, xhrParams_, responseType_) { var xhr_ = new XMLHttpRequest(); xhr_.onreadystatechange = (function (){ switch (xhr_.readyState) { case 0 : // UNINITIALIZED case 1 : // LOADING case 2 : // LOADED case 3 : // INTERACTIVE break; case 4 : // COMPLETED if (xhr_.status >= 400 || xhr_.status == 0) { if (onError_) { onError_(xhr_.status); } break; } var abuffer_ = xhr_.response; if (!abuffer_) { if (onError_) { onError_(); } break; } //if (!responseType_ || responseType_ == "arraybuffer") { //var data_ = new DataView(abuffer_); //} else { // var data_ = abuffer_; //} if (onLoaded_) { onLoaded_(abuffer_); } break; default: if (onError_) { onError_(); } break; } }).bind(this); /* xhr_.onerror = (function() { if (onError_) { onError_(); } }).bind(this);*/ xhr_.open('GET', path_, true); xhr_.responseType = responseType_ ? responseType_ : "arraybuffer"; xhr_.withCredentials = withCredentials_; if (xhrParams_ && xhrParams_["token"] /*&& xhrParams_["tokenHeader"]*/) { //xhr_.setRequestHeader(xhrParams_["tokenHeader"], xhrParams_["token"]); //old way xhr_.setRequestHeader("Accept", "token/" + xhrParams_["token"] + ", */*"); } xhr_.send(""); }; window.performance = window.performance || {}; performance.now = (function() { return performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() { return new Date().getTime(); }; })(); //Provides requestAnimationFrame in a cross browser way. window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) { window.setTimeout(callback, 1000/60); }; })(); // only implement if no native implementation is available if (typeof Array.isArray === 'undefined') { Array.isArray = (function(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }); } Melown["isEqual"] = Melown.isEqual; Melown["clamp"] = Melown.clamp; Melown["mix"] = Melown.mix; Melown["radians"] = Melown.radians; Melown["degrees"] = Melown.degrees; Melown["loadJSON"] = Melown.loadJSON; Melown["loadBinary"] = Melown.loadBinary; \ No newline at end of file