├── src ├── export_default.js ├── GeoConvert.js ├── ReadFile.js ├── KMZ.js ├── WKT.js ├── XML.js ├── GPX.js ├── ShapeFile.js ├── DXF.js └── KML.js ├── .gitignore ├── package.json ├── gulpfile.js ├── LICENSE ├── README.md ├── temp_lib └── leaflet.css ├── dist └── GeoConvert.min.js └── lib └── proj4.js /src/export_default.js: -------------------------------------------------------------------------------- 1 | export default GeoConvert -------------------------------------------------------------------------------- /src/GeoConvert.js: -------------------------------------------------------------------------------- 1 | var GeoConvert = {}; 2 | 3 | GeoConvert.emptyGeojson = function() { 4 | var geojson = {}; 5 | geojson.type = "FeatureCollection"; 6 | geojson.features = []; 7 | 8 | return geojson; 9 | }; 10 | 11 | GeoConvert.decode = {}; 12 | GeoConvert.decode.utf8 = new TextDecoder("utf-8"); 13 | GeoConvert.decode.big5 = new TextDecoder("big5"); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | **/test_files/ 35 | index.html 36 | /temp_lib 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GeoConvert", 3 | "version": "1.0.0", 4 | "description": "Converting between Geojson and GIS file formats", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "http-server -p 3000", 8 | "build": "gulp" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "babelify": "^7.2.0", 14 | "browserify": "^13.0.0", 15 | "gulp": "^3.9.1", 16 | "gulp-babel": "^6.1.2", 17 | "gulp-concat": "^2.6.0", 18 | "gulp-jasmine": "^2.3.0", 19 | "gulp-jshint": "^2.0.0", 20 | "gulp-rename": "^1.2.2", 21 | "gulp-uglify": "^1.5.3", 22 | "gulp-wrap": "^0.11.0", 23 | "jshint": "^2.9.2", 24 | "vinyl-buffer": "^1.0.0", 25 | "vinyl-source-stream": "^1.1.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var concat = require('gulp-concat'); 3 | var uglify = require("gulp-uglify"); 4 | var rename = require('gulp-rename'); 5 | 6 | 7 | gulp.task('default', ['scripts', 'watch']); 8 | //Map 9 | gulp.task('scripts', function() { 10 | gulp.src([ 11 | './src/GeoConvert.js', 12 | './src/XML.js', 13 | './src/KML.js', 14 | './src/KMZ.js', 15 | './src/GPX.js', 16 | './src/ShapeFile.js', 17 | './src/DXF.js', 18 | './src/WKT.js', 19 | './src/export_default.js' 20 | ]) 21 | .pipe(concat('GeoConvert.js')) 22 | .pipe(gulp.dest('dist')) 23 | .pipe(uglify()) 24 | .pipe(rename('GeoConvert.min.js')) 25 | .pipe(gulp.dest('dist')); 26 | }); 27 | 28 | gulp.task('watch', function() { 29 | gulp.watch('src/**/*.js', ['scripts']); 30 | }); -------------------------------------------------------------------------------- /src/ReadFile.js: -------------------------------------------------------------------------------- 1 | function file2ArrayBuffer(file, callback) { 2 | var reader = new FileReader(); 3 | 4 | // If we use onloadend, we need to check the readyState. 5 | reader.onloadend = function(evt) { 6 | if (evt.target.readyState == FileReader.DONE) { // DONE == 2 7 | callback(null, evt.target.result); 8 | } else { 9 | callback("error"); 10 | } 11 | }; 12 | 13 | // var blob = file.slice(0, file.size); 14 | // reader.readAsArrayBuffer(blob); 15 | reader.readAsArrayBuffer(file); 16 | } 17 | 18 | function file2Text(file, callback) { 19 | var reader = new FileReader(); 20 | 21 | // If we use onloadend, we need to check the readyState. 22 | reader.onloadend = function(evt) { 23 | if (evt.target.readyState == FileReader.DONE) { // DONE == 2 24 | callback(null, evt.target.result); 25 | } else { 26 | callback("error"); 27 | } 28 | }; 29 | 30 | reader.readAsText(file); 31 | } 32 | 33 | function fileExtName(fileName) { 34 | return fileName.split(".").pop(); 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 kobesin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeoConvert 2 | 3 | Converting between Geojson and GIS file formats 4 | 5 | KML(KMZ), GPX, Shapefile, DXF(unfinished), WKT(unfinished) 6 | 7 | Rreference the JavaScript file manually: 8 | ```html 9 | 10 | ``` 11 | Note that coordinate transformations depend on proj4.js (this means proj4.js must be included before including the file). 12 | ```html 13 | 14 | ``` 15 | 16 | Usage 17 | ----- 18 | kml to geojson 19 | ```javascript 20 | GeoConvert.kml2Geojson(kml); 21 | ``` 22 | 23 | geojson to kml 24 | ```javascript 25 | GeoConvert.geojson2Kml(geojson); 26 | ``` 27 | 28 | gpx to geojson 29 | ```javascript 30 | GeoConvert.gpx2Geojson(kml); 31 | ``` 32 | 33 | geojson to gpx 34 | ```javascript 35 | GeoConvert.geojson2Gpx(geojson); 36 | ``` 37 | 38 | shapefile to geojson 39 | ```javascript 40 | //shapefile is a object that contain shp, dbf [arrayBuffer], prj? [string] 41 | var shapefile = {}; 42 | shapefile.shp = arrayBuffer_shp; 43 | shapefile.dbf = arrayBuffer_dbf; 44 | 45 | //optional 46 | shapefile.prj = string_prj; 47 | 48 | GeoConvert.shapefile2Geojson(shapefile); 49 | ``` 50 | 51 | wkt to geojson 52 | ```javascript 53 | GeoConvert.wkt2Geojson(wkt); 54 | ``` 55 | -------------------------------------------------------------------------------- /src/KMZ.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //kmz2geojsons. Depends on JSZip. 4 | GeoConvert.kmz2Geojsons = function(kmz, callback) { 5 | if (JSZip) { 6 | var count = 0; 7 | var zip = new JSZip(); 8 | 9 | var kmls = []; 10 | var imgs = {}; 11 | 12 | zip.loadAsync(kmz) 13 | .then(function(result) { 14 | // for (var f in zip.files) { 15 | Object.keys(zip.files).forEach(function(f){ 16 | count++; 17 | 18 | var ext = zip.file(f).name.split(".").pop(); 19 | if (ext === "kml") { 20 | // you now have every files contained in the loaded zip 21 | result.file(f).async("string").then(function success(content) { 22 | kmls.push(content); 23 | finishUnzip(); 24 | }, function error(e) { 25 | // handle the error 26 | count--; 27 | }); 28 | } else if (ext === "png" || ext === "jpg") { 29 | result.file(f).async("base64").then(function success(content) { 30 | var base64 = "data:image/" + ext + ";base64,"; 31 | imgs[f] = base64 + content; 32 | 33 | finishUnzip(); 34 | }, function error(e) { 35 | // handle the error 36 | count--; 37 | }); 38 | } else { 39 | count--; 40 | } 41 | }); 42 | // } 43 | }); 44 | } 45 | 46 | function finishUnzip() { 47 | count--; 48 | if (count === 0) { 49 | var geojsons = []; 50 | kmls.forEach(function(kml){ 51 | var geojson = GeoConvert.kml2Geojson(kml); 52 | geojson.features.forEach(function(feature){ 53 | if (feature.style && feature.style.iconUrl && imgs[feature.style.iconUrl]) { 54 | feature.style.iconUrl = imgs[feature.style.iconUrl]; 55 | } 56 | }); 57 | 58 | geojsons.push(geojson); 59 | }); 60 | 61 | callback && callback(geojsons); 62 | } 63 | } 64 | }; 65 | })(window, document); -------------------------------------------------------------------------------- /src/WKT.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //wkt2geojson 4 | GeoConvert.wkt2Geojson = function(wkt, toString) { 5 | var geojson = wktHandle(wkt); 6 | 7 | if (toString) { 8 | var jsonString = JSON.stringify(geojson); 9 | return jsonString; 10 | } else { 11 | return geojson; 12 | } 13 | }; 14 | 15 | function wktHandle(wkt) { 16 | if (typeof wkt === "string") { 17 | var geojson = GeoConvert.emptyGeojson(); 18 | 19 | wkt = wkt.trim(); 20 | var geometryType = wkt.split('(').shift().trim(); 21 | 22 | var readRecord; 23 | switch (geometryType) { 24 | case 'POINT': 25 | readRecord = readPointRecord; 26 | break; 27 | 28 | case 'LINESTRING': 29 | readRecord = readLineStringRecord; 30 | break; 31 | 32 | case 'POLYGON': 33 | readRecord = readPolygonRecord; 34 | break; 35 | 36 | default: 37 | break; 38 | } 39 | 40 | if (readRecord) { 41 | var feature = {}; 42 | var geometry = readRecord(wkt); 43 | 44 | feature.type = "Feature"; 45 | feature.properties = {}; 46 | feature.geometry = geometry; 47 | 48 | geojson.features.push(feature); 49 | } 50 | 51 | return geojson; 52 | } else { 53 | throw new Error("need wkt"); 54 | } 55 | } 56 | 57 | function xy2Array(xy) { 58 | var xySplit = xy.trim().split(' '); 59 | return [parseFloat(xySplit[0]), parseFloat(xySplit[1])]; 60 | } 61 | 62 | //point type 63 | function readPointRecord(wkt) { 64 | var geometry = {}; 65 | var parentheses1 = wkt.indexOf('('); 66 | var parentheses2 = wkt.lastIndexOf(')'); 67 | 68 | var wGeometry = wkt.slice(parentheses1 + 1, parentheses2); 69 | 70 | geometry.type = "Point"; 71 | geometry.coordinates = xy2Array(wGeometry) 72 | 73 | return geometry; 74 | } 75 | 76 | //lineString type 77 | function readLineStringRecord(wkt) { 78 | var geometry = {}; 79 | var parentheses1 = wkt.indexOf('('); 80 | var parentheses2 = wkt.lastIndexOf(')'); 81 | 82 | var wGeometry = wkt.slice(parentheses1 + 1, parentheses2); 83 | 84 | geometry.type = "LineString"; 85 | geometry.coordinates = wGeometry.split(',').map(xy2Array); 86 | 87 | return geometry; 88 | } 89 | 90 | //polygon type 91 | function readPolygonRecord(wkt) { 92 | var geometry = {}; 93 | var parentheses1 = wkt.indexOf('('); 94 | var parentheses2 = wkt.lastIndexOf(')'); 95 | 96 | var wGeometry = wkt.slice(parentheses1 + 1, parentheses2); 97 | 98 | geometry.type = "Polygon"; 99 | geometry.coordinates = wGeometry.split('),').map(function(rings) { 100 | rings = rings.indexOf(')') !== -1 ? rings : rings + ')'; 101 | return readLineStringRecord(rings).coordinates; 102 | }); 103 | 104 | return geometry; 105 | } 106 | })(window, document); -------------------------------------------------------------------------------- /src/XML.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | 4 | //xml2json 5 | GeoConvert.xml2Json = function(xml, toString) { 6 | //xml string parser 7 | var parseXml; 8 | 9 | if (window.DOMParser) { 10 | parseXml = function(xmlStr) { 11 | return (new window.DOMParser()).parseFromString(xmlStr, "text/xml"); 12 | }; 13 | } else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) { 14 | parseXml = function(xmlStr) { 15 | var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); 16 | xmlDoc.async = "false"; 17 | xmlDoc.loadXML(xmlStr); 18 | return xmlDoc; 19 | }; 20 | } else { 21 | parseXml = function() { 22 | return null; 23 | } 24 | } 25 | 26 | //check string? 27 | var xmlDoc; 28 | 29 | if (typeof xml === "string") { 30 | xmlDoc = parseXml(xml); 31 | } else if (typeof xml === "object" && xml.xmlVersion) { 32 | xmlDoc = xml; 33 | } else { 34 | throw new Error("Unsupported input type"); 35 | } 36 | 37 | var json = xmlElement2JsonObject(xmlDoc); 38 | 39 | if (toString) { 40 | var jsonString = JSON.stringify(json); 41 | return jsonString; 42 | } else { 43 | return json; 44 | } 45 | }; 46 | 47 | function xmlElement2JsonObject(xmlElement) { 48 | var json = {}; 49 | 50 | if (xmlElement.attributes) { 51 | for (var i = 0, imax = xmlElement.attributes.length; i < imax; i++) { 52 | var attribute = xmlElement.attributes[i]; 53 | var nodeValue = attribute.nodeValue; 54 | var value = (!isNaN(parseFloat(nodeValue)) && isFinite(nodeValue)) ? parseFloat(nodeValue) : nodeValue; 55 | json["@" + attribute.nodeName] = value; 56 | } 57 | } 58 | 59 | if (xmlElement.children.length > 0) { 60 | var sameNameArray = {}; 61 | for (var i = 0, imax = xmlElement.children.length; i < imax; i++) { 62 | var children = xmlElement.children[i]; 63 | 64 | if (children.tagName[0] !== "_") { 65 | if (json[children.tagName]) { 66 | if (!sameNameArray[children.tagName]) { 67 | json[children.tagName] = [json[children.tagName]]; 68 | sameNameArray[children.tagName] = true; 69 | } 70 | json[children.tagName].push(xmlElement2JsonObject(children)); 71 | } else { 72 | json[children.tagName] = xmlElement2JsonObject(children); 73 | sameNameArray[children.tagName] = false; 74 | } 75 | } else { 76 | if (!sameNameArray[children.tagName]) { 77 | json = [xmlElement2JsonObject(children)]; 78 | sameNameArray[children.tagName] = true; 79 | } else { 80 | json.push(xmlElement2JsonObject(children)); 81 | } 82 | } 83 | } 84 | } else { 85 | var textContent = xmlElement.textContent; 86 | var value = (!isNaN(parseFloat(textContent)) && isFinite(textContent)) ? parseFloat(textContent) : textContent; 87 | 88 | if (Object.keys(json).length > 0) { 89 | json["#"] = value; 90 | } else { 91 | json = value; 92 | } 93 | } 94 | 95 | return json; 96 | } 97 | 98 | //json2xml 99 | GeoConvert.json2Xml = function(json, xmlName, toString) { 100 | //check string? 101 | var jsonDoc; 102 | 103 | if (typeof json === "string") { 104 | jsonDoc = JSON.parse(json); 105 | } else { 106 | jsonDoc = json; 107 | } 108 | 109 | var docName = xmlName.trim() ? xmlName : 'root'; 110 | var xmlDoc = document.implementation.createDocument(null, "create"); 111 | var xml; 112 | xml = jsonObject2XmlElement(docName, jsonDoc, xmlDoc); 113 | 114 | if (toString) { 115 | var xmlString = "" + (new XMLSerializer()).serializeToString(xml); 116 | return xmlString; 117 | } else { 118 | return xml; 119 | } 120 | }; 121 | 122 | function jsonObject2XmlElement(name, json, xmlDoc) { 123 | var xml = xmlDoc.createElement(name); 124 | 125 | if (json.forEach) { 126 | json.forEach(function(child) { 127 | var element = jsonObject2XmlElement('_array', child, xmlDoc); 128 | xml.appendChild(element); 129 | }); 130 | } else if (typeof json === "object") { 131 | for (var key in json) { 132 | if (key[0] === "@") { 133 | var name = key.replace("@", ""); 134 | 135 | xml.setAttribute(name, json[key]); 136 | } else if (key === "#") { 137 | xml.textContent = json[key]; 138 | } else { 139 | if (typeof json[key] !== "object") { 140 | var element = xmlDoc.createElement(key); 141 | element.textContent = json[key]; 142 | xml.appendChild(element); 143 | } else { 144 | if (json[key].forEach && json[key].sameName) { 145 | json[key].forEach(function(child) { 146 | var element = jsonObject2XmlElement(key, child, xmlDoc); 147 | xml.appendChild(element); 148 | }); 149 | } else { 150 | var element = jsonObject2XmlElement(key, json[key], xmlDoc); 151 | xml.appendChild(element); 152 | } 153 | } 154 | } 155 | } 156 | } else { 157 | xml.textContent = json; 158 | } 159 | 160 | return xml; 161 | } 162 | })(window, document); -------------------------------------------------------------------------------- /src/GPX.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //gpx2geojson 4 | GeoConvert.gpx2Geojson = function(gpx, toString) { 5 | var json; 6 | 7 | if (typeof gpx === "string") { 8 | json = GeoConvert.xml2Json(gpx); 9 | } else if (typeof gpx === "object" && gpx.xmlVersion) { 10 | json = GeoConvert.xml2Json(gpx); 11 | } else { 12 | throw new Error("Unsupported input type"); 13 | } 14 | 15 | var geojson = GeoConvert.emptyGeojson(); 16 | gpxElementHandle("gpx", json.gpx, geojson); 17 | 18 | if (toString) { 19 | var jsonString = JSON.stringify(geojson); 20 | return jsonString; 21 | } else { 22 | return geojson; 23 | } 24 | }; 25 | 26 | function gpxElementHandle(tag, contain, geojson) { 27 | if (tag === "gpx") { 28 | for (var c in contain) { 29 | gpxElementHandle(c, contain[c], geojson); 30 | } 31 | } else { 32 | var gpxDataHandle; 33 | switch (tag) { 34 | case "wpt": 35 | gpxDataHandle = waypoint2Features; 36 | break; 37 | case "trk": 38 | gpxDataHandle = trackpoint2Features; 39 | break; 40 | case "rte": 41 | gpxDataHandle = route2Features; 42 | break; 43 | } 44 | 45 | if (gpxDataHandle) { 46 | if (contain.forEach) { 47 | contain.forEach(function(c) { 48 | geojson.features.push(gpxDataHandle(c)); 49 | }); 50 | } else { 51 | geojson.features.push(gpxDataHandle(contain)); 52 | } 53 | } 54 | } 55 | } 56 | 57 | function waypoint2Features(contain) { 58 | var feature = {}; 59 | feature.type = "Feature"; 60 | feature.properties = {}; 61 | feature.properties.name = contain.name; 62 | feature.properties.cmt = contain.cmt; 63 | feature.properties.desc = contain.desc; 64 | feature.properties.time = contain.time; 65 | 66 | feature.geometry = {}; 67 | feature.geometry.type = "Point"; 68 | 69 | var coordinates = [contain["@lon"], contain["@lat"]]; 70 | feature.geometry.coordinates = coordinates; 71 | 72 | return feature; 73 | } 74 | 75 | function trackpoint2Features(contain) { 76 | var feature = {}; 77 | feature.type = "Feature"; 78 | feature.properties = {}; 79 | feature.properties.name = contain.name; 80 | 81 | feature.geometry = {}; 82 | var coordinates; 83 | if (contain.trkseg && contain.trkseg.trkpt) { 84 | var trkpts = contain.trkseg.trkpt; 85 | if (trkpts.forEach) { 86 | feature.geometry.type = "LineString"; 87 | coordinates = []; 88 | trkpts.forEach(function(trkpt) { 89 | var point = [trkpt["@lon"], trkpt["@lat"]]; 90 | coordinates.push(point); 91 | }); 92 | } else { 93 | feature.geometry.type = "Point"; 94 | coordinates = [trkpts["@lon"], trkpts["@lat"]]; 95 | } 96 | } 97 | feature.geometry.coordinates = coordinates; 98 | 99 | return feature; 100 | } 101 | 102 | function route2Features(contain) { 103 | var feature = {}; 104 | feature.type = "Feature"; 105 | feature.properties = {}; 106 | feature.properties.name = contain.name; 107 | 108 | feature.geometry = {}; 109 | var coordinates; 110 | if (contain.rtept) { 111 | var rtepts = contain.rtept; 112 | if (rtepts.forEach) { 113 | feature.geometry.type = "LineString"; 114 | coordinates = []; 115 | rtepts.forEach(function(trkpt) { 116 | var point = [trkpt["@lon"], trkpt["@lat"]]; 117 | coordinates.push(point); 118 | }); 119 | } else { 120 | feature.geometry.type = "Point"; 121 | coordinates = [rtepts["@lon"], rtepts["@lat"]]; 122 | } 123 | } 124 | feature.geometry.coordinates = coordinates; 125 | 126 | return feature; 127 | } 128 | 129 | //geojson2kml 130 | GeoConvert.geojson2Gpx = function(json, toString) { 131 | //check string? 132 | var geojson; 133 | 134 | if (typeof json === "string") { 135 | geojson = JSON.parse(json); 136 | } else { 137 | geojson = json; 138 | } 139 | 140 | var gpxjson = emptyGpxjson(); 141 | var waypoint = []; 142 | var route = []; 143 | waypoint.sameName = true; 144 | route.sameName = true; 145 | 146 | if (geojson.type !== "Feature" && geojson.type !== "FeatureCollection") { 147 | geojson = { 148 | type: "Feature", 149 | geometry: geojson, 150 | properties: {} 151 | }; 152 | } 153 | 154 | geojsonElementHandle(geojson, waypoint, route); 155 | gpxjson.wpt = waypoint; 156 | gpxjson.rte = route; 157 | 158 | var gpx = GeoConvert.json2Xml(gpxjson, 'gpx'); 159 | 160 | if (toString) { 161 | var gpxString = "" + (new XMLSerializer()).serializeToString(gpx); 162 | return gpxString; 163 | } else { 164 | return gpx; 165 | } 166 | }; 167 | 168 | function emptyGpxjson() { 169 | var gpxjson = {}; 170 | gpxjson["@xmlns"] = "http://www.topografix.com/GPX/1/1"; 171 | gpxjson["@version"] = "1.1"; 172 | gpxjson["@creator"] = "GeoConvert"; 173 | 174 | gpxjson.metadata = {}; 175 | gpxjson.metadata.name = "Geojson to GPX"; 176 | 177 | return gpxjson; 178 | } 179 | 180 | function geojsonElementHandle(gObject, waypoint, route, properties) { 181 | switch (gObject.type) { 182 | case "Point": 183 | var wpt = point2Waypoint(gObject.coordinates); 184 | wpt.name = properties.name ? properties.name : ""; 185 | waypoint.push(wpt); 186 | break; 187 | case "LineString": 188 | var rte = lineString2Route(gObject.coordinates); 189 | rte.name = properties.name ? properties.name : ""; 190 | route.push(rte); 191 | break; 192 | case "MultiPoint": 193 | case "MultiLineString": 194 | var type = gObject.type.replace("Multi", ""); 195 | gObject.coordinates.forEach(function(coordinates) { 196 | geojsonElementHandle({ 197 | type: type, 198 | coordinates: coordinates 199 | }, waypoint, route, properties); 200 | }); 201 | break; 202 | case "GeometryCollection": 203 | gObject.geometries.forEach(function(geometry) { 204 | geojsonElementHandle(geometry, waypoint, route, properties); 205 | }); 206 | break; 207 | case "Feature": 208 | geojsonElementHandle(gObject.geometry, waypoint, route, gObject.properties); 209 | break; 210 | case "FeatureCollection": 211 | gObject.features.forEach(function(feature) { 212 | geojsonElementHandle(feature, waypoint, route); 213 | }); 214 | break; 215 | } 216 | } 217 | 218 | function point2Waypoint(coordinates) { 219 | var waypoint = {}; 220 | waypoint["@lon"] = coordinates[0]; 221 | waypoint["@lat"] = coordinates[1]; 222 | 223 | return waypoint; 224 | } 225 | 226 | function lineString2Route(coordinates) { 227 | var route = {}; 228 | route.rtept = []; 229 | route.rtept.sameName = true; 230 | coordinates.forEach(function(coordinates) { 231 | var rtept = {}; 232 | rtept["@lon"] = coordinates[0]; 233 | rtept["@lat"] = coordinates[1]; 234 | route.rtept.push(rtept); 235 | }); 236 | 237 | return route; 238 | } 239 | })(window, document); -------------------------------------------------------------------------------- /temp_lib/leaflet.css: -------------------------------------------------------------------------------- 1 | /* required styles */ 2 | 3 | .leaflet-map-pane, 4 | .leaflet-tile, 5 | .leaflet-marker-icon, 6 | .leaflet-marker-shadow, 7 | .leaflet-tile-pane, 8 | .leaflet-tile-container, 9 | .leaflet-overlay-pane, 10 | .leaflet-shadow-pane, 11 | .leaflet-marker-pane, 12 | .leaflet-popup-pane, 13 | .leaflet-overlay-pane svg, 14 | .leaflet-zoom-box, 15 | .leaflet-image-layer, 16 | .leaflet-layer { 17 | position: absolute; 18 | left: 0; 19 | top: 0; 20 | } 21 | .leaflet-container { 22 | overflow: hidden; 23 | -ms-touch-action: none; 24 | touch-action: none; 25 | } 26 | .leaflet-tile, 27 | .leaflet-marker-icon, 28 | .leaflet-marker-shadow { 29 | -webkit-user-select: none; 30 | -moz-user-select: none; 31 | user-select: none; 32 | -webkit-user-drag: none; 33 | } 34 | .leaflet-marker-icon, 35 | .leaflet-marker-shadow { 36 | display: block; 37 | } 38 | /* map is broken in FF if you have max-width: 100% on tiles */ 39 | .leaflet-container img { 40 | max-width: none !important; 41 | } 42 | /* stupid Android 2 doesn't understand "max-width: none" properly */ 43 | .leaflet-container img.leaflet-image-layer { 44 | max-width: 15000px !important; 45 | } 46 | .leaflet-tile { 47 | filter: inherit; 48 | visibility: hidden; 49 | } 50 | .leaflet-tile-loaded { 51 | visibility: inherit; 52 | } 53 | .leaflet-zoom-box { 54 | width: 0; 55 | height: 0; 56 | } 57 | /* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */ 58 | .leaflet-overlay-pane svg { 59 | -moz-user-select: none; 60 | } 61 | 62 | .leaflet-tile-pane { z-index: 2; } 63 | .leaflet-objects-pane { z-index: 3; } 64 | .leaflet-overlay-pane { z-index: 4; } 65 | .leaflet-shadow-pane { z-index: 5; } 66 | .leaflet-marker-pane { z-index: 6; } 67 | .leaflet-popup-pane { z-index: 7; } 68 | 69 | .leaflet-vml-shape { 70 | width: 1px; 71 | height: 1px; 72 | } 73 | .lvml { 74 | behavior: url(#default#VML); 75 | display: inline-block; 76 | position: absolute; 77 | } 78 | 79 | 80 | /* control positioning */ 81 | 82 | .leaflet-control { 83 | position: relative; 84 | z-index: 7; 85 | pointer-events: auto; 86 | } 87 | .leaflet-top, 88 | .leaflet-bottom { 89 | position: absolute; 90 | z-index: 1000; 91 | pointer-events: none; 92 | } 93 | .leaflet-top { 94 | top: 0; 95 | } 96 | .leaflet-right { 97 | right: 0; 98 | } 99 | .leaflet-bottom { 100 | bottom: 0; 101 | } 102 | .leaflet-left { 103 | left: 0; 104 | } 105 | .leaflet-control { 106 | float: left; 107 | clear: both; 108 | } 109 | .leaflet-right .leaflet-control { 110 | float: right; 111 | } 112 | .leaflet-top .leaflet-control { 113 | margin-top: 10px; 114 | } 115 | .leaflet-bottom .leaflet-control { 116 | margin-bottom: 10px; 117 | } 118 | .leaflet-left .leaflet-control { 119 | margin-left: 10px; 120 | } 121 | .leaflet-right .leaflet-control { 122 | margin-right: 10px; 123 | } 124 | 125 | 126 | /* zoom and fade animations */ 127 | 128 | .leaflet-fade-anim .leaflet-tile, 129 | .leaflet-fade-anim .leaflet-popup { 130 | opacity: 0; 131 | -webkit-transition: opacity 0.2s linear; 132 | -moz-transition: opacity 0.2s linear; 133 | -o-transition: opacity 0.2s linear; 134 | transition: opacity 0.2s linear; 135 | } 136 | .leaflet-fade-anim .leaflet-tile-loaded, 137 | .leaflet-fade-anim .leaflet-map-pane .leaflet-popup { 138 | opacity: 1; 139 | } 140 | 141 | .leaflet-zoom-anim .leaflet-zoom-animated { 142 | -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1); 143 | -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1); 144 | -o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1); 145 | transition: transform 0.25s cubic-bezier(0,0,0.25,1); 146 | } 147 | .leaflet-zoom-anim .leaflet-tile, 148 | .leaflet-pan-anim .leaflet-tile, 149 | .leaflet-touching .leaflet-zoom-animated { 150 | -webkit-transition: none; 151 | -moz-transition: none; 152 | -o-transition: none; 153 | transition: none; 154 | } 155 | 156 | .leaflet-zoom-anim .leaflet-zoom-hide { 157 | visibility: hidden; 158 | } 159 | 160 | 161 | /* cursors */ 162 | 163 | .leaflet-clickable { 164 | cursor: pointer; 165 | } 166 | .leaflet-container { 167 | cursor: -webkit-grab; 168 | cursor: -moz-grab; 169 | } 170 | .leaflet-popup-pane, 171 | .leaflet-control { 172 | cursor: auto; 173 | } 174 | .leaflet-dragging .leaflet-container, 175 | .leaflet-dragging .leaflet-clickable { 176 | cursor: move; 177 | cursor: -webkit-grabbing; 178 | cursor: -moz-grabbing; 179 | } 180 | 181 | 182 | /* visual tweaks */ 183 | 184 | .leaflet-container { 185 | background: #ddd; 186 | outline: 0; 187 | } 188 | .leaflet-container a { 189 | color: #0078A8; 190 | } 191 | .leaflet-container a.leaflet-active { 192 | outline: 2px solid orange; 193 | } 194 | .leaflet-zoom-box { 195 | border: 2px dotted #38f; 196 | background: rgba(255,255,255,0.5); 197 | } 198 | 199 | 200 | /* general typography */ 201 | .leaflet-container { 202 | font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif; 203 | } 204 | 205 | 206 | /* general toolbar styles */ 207 | 208 | .leaflet-bar { 209 | box-shadow: 0 1px 5px rgba(0,0,0,0.65); 210 | border-radius: 4px; 211 | } 212 | .leaflet-bar a, 213 | .leaflet-bar a:hover { 214 | background-color: #fff; 215 | border-bottom: 1px solid #ccc; 216 | width: 26px; 217 | height: 26px; 218 | line-height: 26px; 219 | display: block; 220 | text-align: center; 221 | text-decoration: none; 222 | color: black; 223 | } 224 | .leaflet-bar a, 225 | .leaflet-control-layers-toggle { 226 | background-position: 50% 50%; 227 | background-repeat: no-repeat; 228 | display: block; 229 | } 230 | .leaflet-bar a:hover { 231 | background-color: #f4f4f4; 232 | } 233 | .leaflet-bar a:first-child { 234 | border-top-left-radius: 4px; 235 | border-top-right-radius: 4px; 236 | } 237 | .leaflet-bar a:last-child { 238 | border-bottom-left-radius: 4px; 239 | border-bottom-right-radius: 4px; 240 | border-bottom: none; 241 | } 242 | .leaflet-bar a.leaflet-disabled { 243 | cursor: default; 244 | background-color: #f4f4f4; 245 | color: #bbb; 246 | } 247 | 248 | .leaflet-touch .leaflet-bar a { 249 | width: 30px; 250 | height: 30px; 251 | line-height: 30px; 252 | } 253 | 254 | 255 | /* zoom control */ 256 | 257 | .leaflet-control-zoom-in, 258 | .leaflet-control-zoom-out { 259 | font: bold 18px 'Lucida Console', Monaco, monospace; 260 | text-indent: 1px; 261 | } 262 | .leaflet-control-zoom-out { 263 | font-size: 20px; 264 | } 265 | 266 | .leaflet-touch .leaflet-control-zoom-in { 267 | font-size: 22px; 268 | } 269 | .leaflet-touch .leaflet-control-zoom-out { 270 | font-size: 24px; 271 | } 272 | 273 | 274 | /* layers control */ 275 | 276 | .leaflet-control-layers { 277 | box-shadow: 0 1px 5px rgba(0,0,0,0.4); 278 | background: #fff; 279 | border-radius: 5px; 280 | } 281 | .leaflet-control-layers-toggle { 282 | background-image: url(images/layers.png); 283 | width: 36px; 284 | height: 36px; 285 | } 286 | .leaflet-retina .leaflet-control-layers-toggle { 287 | background-image: url(images/layers-2x.png); 288 | background-size: 26px 26px; 289 | } 290 | .leaflet-touch .leaflet-control-layers-toggle { 291 | width: 44px; 292 | height: 44px; 293 | } 294 | .leaflet-control-layers .leaflet-control-layers-list, 295 | .leaflet-control-layers-expanded .leaflet-control-layers-toggle { 296 | display: none; 297 | } 298 | .leaflet-control-layers-expanded .leaflet-control-layers-list { 299 | display: block; 300 | position: relative; 301 | } 302 | .leaflet-control-layers-expanded { 303 | padding: 6px 10px 6px 6px; 304 | color: #333; 305 | background: #fff; 306 | } 307 | .leaflet-control-layers-selector { 308 | margin-top: 2px; 309 | position: relative; 310 | top: 1px; 311 | } 312 | .leaflet-control-layers label { 313 | display: block; 314 | } 315 | .leaflet-control-layers-separator { 316 | height: 0; 317 | border-top: 1px solid #ddd; 318 | margin: 5px -10px 5px -6px; 319 | } 320 | 321 | 322 | /* attribution and scale controls */ 323 | 324 | .leaflet-container .leaflet-control-attribution { 325 | background: #fff; 326 | background: rgba(255, 255, 255, 0.7); 327 | margin: 0; 328 | } 329 | .leaflet-control-attribution, 330 | .leaflet-control-scale-line { 331 | padding: 0 5px; 332 | color: #333; 333 | } 334 | .leaflet-control-attribution a { 335 | text-decoration: none; 336 | } 337 | .leaflet-control-attribution a:hover { 338 | text-decoration: underline; 339 | } 340 | .leaflet-container .leaflet-control-attribution, 341 | .leaflet-container .leaflet-control-scale { 342 | font-size: 11px; 343 | } 344 | .leaflet-left .leaflet-control-scale { 345 | margin-left: 5px; 346 | } 347 | .leaflet-bottom .leaflet-control-scale { 348 | margin-bottom: 5px; 349 | } 350 | .leaflet-control-scale-line { 351 | border: 2px solid #777; 352 | border-top: none; 353 | line-height: 1.1; 354 | padding: 2px 5px 1px; 355 | font-size: 11px; 356 | white-space: nowrap; 357 | overflow: hidden; 358 | -moz-box-sizing: content-box; 359 | box-sizing: content-box; 360 | 361 | background: #fff; 362 | background: rgba(255, 255, 255, 0.5); 363 | } 364 | .leaflet-control-scale-line:not(:first-child) { 365 | border-top: 2px solid #777; 366 | border-bottom: none; 367 | margin-top: -2px; 368 | } 369 | .leaflet-control-scale-line:not(:first-child):not(:last-child) { 370 | border-bottom: 2px solid #777; 371 | } 372 | 373 | .leaflet-touch .leaflet-control-attribution, 374 | .leaflet-touch .leaflet-control-layers, 375 | .leaflet-touch .leaflet-bar { 376 | box-shadow: none; 377 | } 378 | .leaflet-touch .leaflet-control-layers, 379 | .leaflet-touch .leaflet-bar { 380 | border: 2px solid rgba(0,0,0,0.2); 381 | background-clip: padding-box; 382 | } 383 | 384 | 385 | /* popup */ 386 | 387 | .leaflet-popup { 388 | position: absolute; 389 | text-align: center; 390 | } 391 | .leaflet-popup-content-wrapper { 392 | padding: 1px; 393 | text-align: left; 394 | border-radius: 12px; 395 | } 396 | .leaflet-popup-content { 397 | margin: 13px 19px; 398 | line-height: 1.4; 399 | } 400 | .leaflet-popup-content p { 401 | margin: 18px 0; 402 | } 403 | .leaflet-popup-tip-container { 404 | margin: 0 auto; 405 | width: 40px; 406 | height: 20px; 407 | position: relative; 408 | overflow: hidden; 409 | } 410 | .leaflet-popup-tip { 411 | width: 17px; 412 | height: 17px; 413 | padding: 1px; 414 | 415 | margin: -10px auto 0; 416 | 417 | -webkit-transform: rotate(45deg); 418 | -moz-transform: rotate(45deg); 419 | -ms-transform: rotate(45deg); 420 | -o-transform: rotate(45deg); 421 | transform: rotate(45deg); 422 | } 423 | .leaflet-popup-content-wrapper, 424 | .leaflet-popup-tip { 425 | background: white; 426 | 427 | box-shadow: 0 3px 14px rgba(0,0,0,0.4); 428 | } 429 | .leaflet-container a.leaflet-popup-close-button { 430 | position: absolute; 431 | top: 0; 432 | right: 0; 433 | padding: 4px 4px 0 0; 434 | text-align: center; 435 | width: 18px; 436 | height: 14px; 437 | font: 16px/14px Tahoma, Verdana, sans-serif; 438 | color: #c3c3c3; 439 | text-decoration: none; 440 | font-weight: bold; 441 | background: transparent; 442 | } 443 | .leaflet-container a.leaflet-popup-close-button:hover { 444 | color: #999; 445 | } 446 | .leaflet-popup-scrolled { 447 | overflow: auto; 448 | border-bottom: 1px solid #ddd; 449 | border-top: 1px solid #ddd; 450 | } 451 | 452 | .leaflet-oldie .leaflet-popup-content-wrapper { 453 | zoom: 1; 454 | } 455 | .leaflet-oldie .leaflet-popup-tip { 456 | width: 24px; 457 | margin: 0 auto; 458 | 459 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)"; 460 | filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678); 461 | } 462 | .leaflet-oldie .leaflet-popup-tip-container { 463 | margin-top: -1px; 464 | } 465 | 466 | .leaflet-oldie .leaflet-control-zoom, 467 | .leaflet-oldie .leaflet-control-layers, 468 | .leaflet-oldie .leaflet-popup-content-wrapper, 469 | .leaflet-oldie .leaflet-popup-tip { 470 | border: 1px solid #999; 471 | } 472 | 473 | 474 | /* div icon */ 475 | 476 | .leaflet-div-icon { 477 | background: #fff; 478 | border: 1px solid #666; 479 | } 480 | -------------------------------------------------------------------------------- /src/ShapeFile.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //dbase field type 4 | var dBaseFieldType = { 5 | "N": "Number", 6 | "C": "Character", // binary 7 | "L": "Logical", 8 | "D": "Date", 9 | "M": "Memo", // binary 10 | "F": "Floating point", 11 | "B": "Binary", 12 | "G": "General", 13 | "P": "Picture", 14 | "Y": "Currency", 15 | "T": "DateTime", 16 | "I": "Integer", 17 | "V": "VariField", 18 | "X": "Variant", 19 | "@": "Timestamp", 20 | "O": "Double", 21 | "+": "Autoincrement" 22 | }; 23 | 24 | //shapefile2Geojson. shapefile need contain .shp, .dbf. 25 | //shp & dbf are arrayBuffer. 26 | GeoConvert.shapefile2Geojson = function(file, toString) { 27 | var geojson = shapefileHandle(file); 28 | 29 | if (toString) { 30 | var jsonString = JSON.stringify(geojson); 31 | return jsonString; 32 | } else { 33 | return geojson; 34 | } 35 | }; 36 | 37 | function shapefileHandle(file) { 38 | if (file.shp && file.dbf) { 39 | var geojson = GeoConvert.emptyGeojson(); 40 | 41 | //prj 42 | var projection = file.prj; 43 | 44 | //encoding 45 | var encoding = file.encoding; 46 | 47 | //shp 48 | readShpBuffer(file.shp, geojson, projection); 49 | //dbf 50 | readDbfBuffer(file.dbf, geojson, encoding); 51 | 52 | return geojson; 53 | } else { 54 | throw new Error("need complete shapefile"); 55 | } 56 | } 57 | 58 | function Transitions(fromProjection, toProjection) { 59 | this.fromProjection = fromProjection; 60 | this.toProjection = toProjection; 61 | } 62 | 63 | Transitions.prototype.trans = function(coordinates) { 64 | return proj4(this.fromProjection, this.toProjection, coordinates); 65 | } 66 | 67 | function readShpBuffer(arrayBuffer, geojson, projection) { 68 | var dataView = new DataView(arrayBuffer); 69 | var byteLength = dataView.byteLength; 70 | 71 | //Main File Header 72 | //File Length 73 | var fileLength = dataView.getInt32(24); 74 | 75 | //Shape Type 76 | var shapeType = dataView.getInt32(32, true); 77 | 78 | //Bounding Box 79 | var xmin = dataView.getFloat64(36, true); 80 | var ymin = dataView.getFloat64(44, true); 81 | var xmax = dataView.getFloat64(52, true); 82 | var ymax = dataView.getFloat64(60, true); 83 | 84 | // var zmin = dataView.getFloat64(68, true); 85 | // var zmax = dataView.getFloat64(76, true); 86 | // var mmin = dataView.getFloat64(84, true); 87 | // var mmax = dataView.getFloat64(92, true); 88 | 89 | var transitions = projection && !/GCS_WGS_1984|WGS84/g.test(projection) ? new Transitions(projection, proj4.WGS84) : transitions; 90 | geojson.bbox = readBoxRecord(dataView, 36, transitions); 91 | 92 | //Record 93 | var byteOffset = 100; 94 | while (byteOffset < byteLength) { 95 | var result = readShpFileRecord(dataView, byteOffset, transitions); 96 | geojson.features.push(result.feature); 97 | byteOffset = result.byteOffset; 98 | } 99 | } 100 | 101 | function readShpFileRecord(dataView, byteOffset, transitions) { 102 | var result = {}; 103 | var feature = {}; 104 | feature.type = "Feature"; 105 | 106 | //Record Number 107 | var recordNumber = dataView.getInt32(byteOffset); 108 | 109 | //Content Length 110 | var contentLength = dataView.getInt32(byteOffset + 4); 111 | 112 | //Shape Type 113 | var shapeType = dataView.getInt32(byteOffset + 8, true); 114 | 115 | byteOffset += 12; 116 | 117 | var readRecord; 118 | switch (shapeType) { 119 | case 0: //Null Shape 120 | break; 121 | 122 | case 1: //Point 123 | case 11: //PointZ 124 | case 21: //PointM 125 | readRecord = readPointRecord; 126 | break; 127 | 128 | case 3: //PolyLine 129 | case 13: //PolyLineZ 130 | case 23: //PolyLineM 131 | readRecord = readPolylineRecord; 132 | break; 133 | 134 | case 5: //Polygon 135 | case 15: //PolygonZ 136 | case 25: //PolygonM 137 | readRecord = readPolygonRecord; 138 | break; 139 | 140 | case 8: //MultiPoint 141 | case 18: //MultiPointZ 142 | readRecord = readMultiPointRecord; 143 | break; 144 | 145 | case 28: //MultiPointM 146 | break; 147 | 148 | case 31: //MultiPatch 149 | break; 150 | default: 151 | break; 152 | } 153 | 154 | if (readRecord) { 155 | var geometry = {}; 156 | var record = readRecord(dataView, byteOffset, transitions); 157 | geometry.type = record.type; 158 | geometry.coordinates = record.coordinates; 159 | 160 | if (record.box) feature.bbox = record.box; 161 | feature.geometry = geometry; 162 | } 163 | 164 | result.feature = feature; 165 | 166 | //The content length for a record is the length of the record contents section measured in 167 | //16-bit words. Each record, therefore, contributes (4 + content length) 16-bit words 168 | //toward the total length of the file, as stored at Byte 24 in the file header. 169 | result.byteOffset = byteOffset + contentLength * 2 - 4; 170 | return result; 171 | } 172 | 173 | //box type 174 | function readBoxRecord(dataView, byteOffset, transitions) { 175 | var xmin = dataView.getFloat64(byteOffset, true); 176 | var ymin = dataView.getFloat64(byteOffset + 8, true); 177 | var xmax = dataView.getFloat64(byteOffset + 16, true); 178 | var ymax = dataView.getFloat64(byteOffset + 24, true); 179 | 180 | var box; 181 | if (transitions) { 182 | box = transitions.trans([xmin, ymin]).concat(transitions.trans([xmax, ymax])); 183 | } else { 184 | box = [xmin, ymin, xmax, ymax]; 185 | } 186 | 187 | return box; 188 | } 189 | 190 | //point type 191 | function readPointRecord(dataView, byteOffset, transitions) { 192 | var record = {}; 193 | 194 | var x = dataView.getFloat64(byteOffset, true); 195 | var y = dataView.getFloat64(byteOffset + 8, true); 196 | byteOffset += 16; 197 | record.type = "Point"; 198 | record.coordinates = transitions ? transitions.trans([x, y]) : [x, y]; 199 | 200 | return record; 201 | } 202 | 203 | //multipoint type 204 | function readMultiPointRecord(dataView, byteOffset, transitions) { 205 | var record = {}; 206 | 207 | var box = readBoxRecord(dataView, byteOffset, transitions); 208 | var numPoints = dataView.getInt32(byteOffset + 32, true); 209 | var points = []; 210 | var coordinates = []; 211 | 212 | byteOffset = byteOffset + 36; 213 | for (var i = 0; i < numPoints; i++) { 214 | var x = dataView.getFloat64(byteOffset, true); 215 | var y = dataView.getFloat64(byteOffset + 8, true); 216 | 217 | var point = transitions ? transitions.trans([x, y]) : [x, y]; 218 | points.push(point); 219 | byteOffset += 16; 220 | } 221 | 222 | record.type = "MultiPoint"; 223 | record.box = box; 224 | record.coordinates = points; 225 | 226 | return record; 227 | } 228 | 229 | //pointM type 230 | function readPointMRecord(dataView, byteOffset, transitions) { 231 | var record = {}; 232 | 233 | var x = dataView.getFloat64(byteOffset, true); 234 | var y = dataView.getFloat64(byteOffset + 8, true); 235 | // var m = dataView.getFloat64(byteOffset + 16, true); 236 | byteOffset += 24; 237 | record.type = "Point"; 238 | record.coordinates = transitions ? transitions.trans([x, y]) : [x, y]; 239 | 240 | return record; 241 | } 242 | 243 | //pointZ type 244 | function readPointZRecord(dataView, byteOffset, transitions) { 245 | var record = {}; 246 | 247 | var x = dataView.getFloat64(byteOffset, true); 248 | var y = dataView.getFloat64(byteOffset + 8, true); 249 | // var z = dataView.getFloat64(byteOffset + 16, true); 250 | // var m = dataView.getFloat64(byteOffset + 24, true); 251 | byteOffset += 32; 252 | record.type = "Point"; 253 | record.coordinates = transitions ? transitions.trans([x, y]) : [x, y]; 254 | 255 | return record; 256 | } 257 | 258 | //polyline type 259 | function readPolylineRecord(dataView, byteOffset, transitions) { 260 | var record = {}; 261 | 262 | var box = readBoxRecord(dataView, byteOffset, transitions); 263 | var numParts = dataView.getInt32(byteOffset + 32, true); 264 | var numPoints = dataView.getInt32(byteOffset + 36, true); 265 | var parts = []; 266 | var points = []; 267 | var coordinates = []; 268 | 269 | for (var i = 0; i < numParts; i++) { 270 | var part = dataView.getInt32(byteOffset + 40 + 4 * i, true) - 1; 271 | parts.push(part); 272 | } 273 | parts.push(numPoints - 1); 274 | 275 | byteOffset = byteOffset + 40 + 4 * numParts; 276 | for (var i = 0; i < numPoints; i++) { 277 | var x = dataView.getFloat64(byteOffset, true); 278 | var y = dataView.getFloat64(byteOffset + 8, true); 279 | 280 | var point = transitions ? transitions.trans([x, y]) : [x, y]; 281 | points.push(point); 282 | byteOffset += 16; 283 | 284 | if (parts.indexOf(i) !== -1) { 285 | coordinates.push(points); 286 | points = []; 287 | } 288 | } 289 | 290 | record.box = box; 291 | record.numPoints = numPoints; 292 | 293 | if (numParts === 1) { 294 | record.type = "LineString"; 295 | record.coordinates = coordinates[0]; 296 | } else { 297 | record.type = "MultiLineString"; 298 | record.coordinates = coordinates; 299 | } 300 | 301 | return record; 302 | } 303 | 304 | //polygon type 305 | function readPolygonRecord(dataView, byteOffset, transitions) { 306 | var record = {}; 307 | 308 | var box = readBoxRecord(dataView, byteOffset, transitions); 309 | var numParts = dataView.getInt32(byteOffset + 32, true); 310 | var numPoints = dataView.getInt32(byteOffset + 36, true); 311 | var parts = []; 312 | var points = []; 313 | var coordinates = []; 314 | var rings = []; 315 | 316 | var prevX = null; 317 | var prevY = null; 318 | var checkCounterClockwise = 0; 319 | 320 | for (var i = 0; i < numParts; i++) { 321 | var part = dataView.getInt32(byteOffset + 40 + 4 * i, true) - 1; 322 | parts.push(part); 323 | } 324 | parts.push(numPoints - 1); 325 | 326 | byteOffset = byteOffset + 40 + 4 * numParts; 327 | for (var i = 0; i < numPoints; i++) { 328 | var x = dataView.getFloat64(byteOffset, true); 329 | var y = dataView.getFloat64(byteOffset + 8, true); 330 | 331 | var point = transitions ? transitions.trans([x, y]) : [x, y]; 332 | points.push(point); 333 | byteOffset += 16; 334 | 335 | //check polygon is hole? 336 | //http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order 337 | if (!prevX || !prevY) { 338 | [prevX, prevY] = [x, y]; 339 | } 340 | checkCounterClockwise = checkCounterClockwise + (x - prevX) * (y + prevY); 341 | [prevX, prevY] = [x, y]; 342 | 343 | if (parts.indexOf(i) !== -1) { 344 | coordinates.push(points); 345 | 346 | if (checkCounterClockwise >= 0) { 347 | rings.push(coordinates); 348 | } else { 349 | rings[rings.length - 1] = rings[rings.length - 1].concat(coordinates); 350 | } 351 | 352 | points = []; 353 | coordinates = []; 354 | checkCounterClockwise = 0; 355 | [prevX, prevY] = [null, null]; 356 | } 357 | } 358 | 359 | record.box = box; 360 | record.numPoints = numPoints; 361 | 362 | if (numParts === 1) { 363 | record.type = "Polygon"; 364 | record.coordinates = rings[0]; 365 | } else { 366 | record.type = "MultiPolygon"; 367 | record.coordinates = rings; 368 | } 369 | 370 | return record; 371 | } 372 | 373 | function readDbfBuffer(arrayBuffer, geojson, encoding) { 374 | var dataView = new DataView(arrayBuffer); 375 | var byteLength = dataView.byteLength; 376 | 377 | //Main File Header 378 | var type = dataView.getInt8(0); 379 | var numRecords = dataView.getInt32(4, true); 380 | var headerLength = dataView.getInt16(8, true); 381 | var recordLength = dataView.getInt16(10, true); 382 | 383 | var decode; 384 | var codePage = encoding || dataView.getInt8(29); 385 | switch (codePage) { 386 | case 0x4F: //big-5 387 | case "0x4F": 388 | decode = GeoConvert.decode.big5; 389 | break; 390 | default: //utf-8 391 | decode = GeoConvert.decode.utf8; 392 | break; 393 | } 394 | 395 | if (type !== 0x03) { 396 | throw new Error("File has unknown/unsupported dBase version:" + type); 397 | } 398 | 399 | //Fidld Descriptions 400 | var byteOffset = 32; 401 | var fields = []; 402 | while (dataView.getUint8(byteOffset) !== 0x0D) { 403 | var field = {}; 404 | field.name = decode.decode(arrayBuffer.slice(byteOffset, byteOffset + 10)).replace(/\u0000/g, ""); 405 | field.type = dBaseFieldType[decode.decode(arrayBuffer.slice(byteOffset + 11, byteOffset + 12))]; 406 | field.fieldLength = dataView.getUint8(byteOffset + 16); 407 | field.decimals = dataView.getUint8(byteOffset + 17); 408 | fields.push(field); 409 | 410 | byteOffset += 32; 411 | } 412 | 413 | //Record 414 | var numFields = fields.length; 415 | for (var i = 0; i < numRecords; i++) { 416 | var record = {}; 417 | byteOffset = headerLength + i * recordLength; 418 | //skip delete code 419 | byteOffset += 1; 420 | for (var j = 0; j < numFields; j++) { 421 | var recordField = fields[j]; 422 | var value = decode.decode(arrayBuffer.slice(byteOffset, byteOffset + recordField.fieldLength)).trim(); 423 | record[recordField.name] = value; 424 | byteOffset += recordField.fieldLength; 425 | } 426 | geojson.features[i].properties = record; 427 | } 428 | } 429 | })(window, document); -------------------------------------------------------------------------------- /src/DXF.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //code index 4 | var codeIndex = { 5 | "1": "text", 6 | "2": "name", 7 | "5": "handle", 8 | "6": "linetypeName", 9 | "7": "textStyleName", 10 | "8": "layerName", 11 | "10": "lowerLeftCorner", 12 | "11": "upperRightCorner", 13 | "12": "centerDcs", 14 | "13": "snapBasePoint", 15 | "14": "snapSpacing", 16 | "15": "gridSpacing", 17 | "16": "viewDirectionFromTarget", 18 | "17": "viewTarget", 19 | "39": "thickness", 20 | "48": "linetypeScale", 21 | "50": "textRotation", 22 | "51": "textOblique", 23 | "60": "visibility", 24 | "62": "colorNumber", 25 | "70": "closed" 26 | }; 27 | 28 | var segmentizeStepAngleInDegrees = 10; 29 | 30 | //dxf2Geojson. file is dxf text. 31 | GeoConvert.dxf2Geojson = function(file, toString) { 32 | var geojson = dxfHandle(file); 33 | 34 | if (toString) { 35 | var jsonString = JSON.stringify(geojson); 36 | return jsonString; 37 | } else { 38 | return geojson; 39 | } 40 | }; 41 | 42 | function Transitions(fromProjection, toProjection) { 43 | this.fromProjection = fromProjection; 44 | this.toProjection = toProjection; 45 | } 46 | 47 | Transitions.prototype.trans = function(coordinates) { 48 | return proj4(this.fromProjection, this.toProjection, coordinates); 49 | } 50 | 51 | function dxfHandle(file) { 52 | if (file.dxf !== undefined) { 53 | var geojson = GeoConvert.emptyGeojson(); 54 | 55 | //prj 56 | var projection = file.prj; 57 | var transitions = projection && !/GCS_WGS_1984|WGS84/g.test(projection) ? new Transitions(projection, proj4.WGS84) : transitions; 58 | 59 | //dxf 60 | var dxf = readDxfText(file.dxf); 61 | 62 | //geojson 63 | var geojson = dxfObject2Geojson(dxf, transitions); 64 | 65 | return geojson; 66 | } else { 67 | throw new Error("need dxf file"); 68 | } 69 | } 70 | 71 | function readDxfText(dxfText) { 72 | var dxfArray = dxfText.split(/\r\n|\r|\n/g); 73 | var dxf = {}; 74 | 75 | // HEADER 76 | var headerStart = dxfArray.indexOf("HEADER"); 77 | var headerEnd = dxfArray.indexOf("ENDSEC", headerStart) + 1; 78 | var headerArray = dxfArray.slice(headerStart, headerEnd); 79 | dxf.header = readDxfHeader(headerArray); 80 | 81 | // TABLES 82 | var tablesStart = dxfArray.indexOf("TABLES"); 83 | var tablesEnd = dxfArray.indexOf("ENDSEC", tablesStart) + 1; 84 | var tablesArray = dxfArray.slice(tablesStart, tablesEnd); 85 | dxf.tables = readDxfTables(tablesArray); 86 | 87 | // BLOCKS 88 | var blocksStart = dxfArray.indexOf("BLOCKS"); 89 | var blocksEnd = dxfArray.indexOf("ENDSEC", blocksStart) + 1; 90 | var blocksArray = dxfArray.slice(blocksStart, blocksEnd); 91 | dxf.blocks = readDxfBlocks(blocksArray); 92 | 93 | // ENTITIES 94 | var entitiesStart = dxfArray.indexOf("ENTITIES"); 95 | var entitiesEnd = dxfArray.indexOf("ENDSEC", entitiesStart) + 1; 96 | var entitiesArray = dxfArray.slice(entitiesStart, entitiesEnd); 97 | dxf.entities = readDxfEntities(entitiesArray); 98 | 99 | return dxf; 100 | } 101 | 102 | //origin point of dxf 103 | function readDxfPoints(data, start, x, y, z) { 104 | var points = {}; 105 | points.x = readGroupValue(x, data[start]); 106 | points.y = readGroupValue(y, data[start + 2]); 107 | 108 | if (z !== undefined) { 109 | if (data[start + 3] == z) { 110 | points.z = readGroupValue(z, data[start + 4]); 111 | } else { 112 | points.z = undefined 113 | } 114 | 115 | } 116 | return points; 117 | } 118 | 119 | // //point of geojson 120 | // function readDxfPoints(data, start, x, y, z) { 121 | // var x = readGroupValue(x, data[start]); 122 | // var y = readGroupValue(y, data[start + 2]); 123 | // var points = [x, y]; 124 | 125 | // return points; 126 | // } 127 | 128 | function readDxfHeader(headerArray) { 129 | var imax = headerArray.length; 130 | var i = 0; 131 | var header = {}; 132 | 133 | while (i < imax) { 134 | var code = headerArray[i].trim(); 135 | if (code === "9") { 136 | var key = headerArray[i + 1]; 137 | var valueCode = headerArray[i + 2].trim(); 138 | if (valueCode === "10") { 139 | var points = {}; 140 | var start = i + 3; 141 | if (headerArray[i + 6].trim() === "30") { 142 | points = readDxfPoints(headerArray, start, 10, 20, 30);; 143 | i = i + 8; 144 | } else { 145 | points = readDxfPoints(headerArray, start, 10, 20); 146 | i = i + 6; 147 | } 148 | header[key] = points; 149 | } else { 150 | header[key] = readGroupValue(parseInt(valueCode), headerArray[i + 3]); 151 | i = i + 4; 152 | } 153 | } else { 154 | i++; 155 | } 156 | } 157 | 158 | return header; 159 | } 160 | 161 | function readDxfTable(tableArray, index) { 162 | var length = tableArray.length - 2; 163 | var table = {}; 164 | var code, value, name; 165 | 166 | while (index < length) { 167 | code = tableArray[index].trim(); 168 | value = tableArray[index + 1].trim(); 169 | 170 | switch (code) { 171 | case "0": 172 | var start = index + 2; 173 | var end = tableArray.indexOf(name, start) + 1 || length; 174 | var children = tableArray.slice(start, end - 2); 175 | table[value] = table[value] || []; 176 | table[value].push(readDxfTable(children, 0)); 177 | index = end - 4; 178 | break; 179 | case "2": 180 | name = value; 181 | table.name = value; 182 | break; 183 | case "3": 184 | table.description = value; 185 | break; 186 | case "5": 187 | table.handle = value; 188 | break; 189 | case "10": 190 | case "11": 191 | case "12": 192 | case "13": 193 | case "14": 194 | case "15": 195 | var start = index + 1; 196 | var x = parseInt(code); 197 | table[codeIndex[code]] = readDxfPoints(tableArray, start, x, x + 10); 198 | break; 199 | case "16": 200 | case "17": 201 | var start = index + 1; 202 | var x = parseInt(code); 203 | table[codeIndex[code]] = readDxfPoints(tableArray, start, x, x + 10, x + 20); 204 | break; 205 | case "40": 206 | table.patternLength = parseFloat(value); 207 | break; 208 | case "49": 209 | if (table.elements == undefined) { 210 | // librecad compatibility 211 | table.elements = []; 212 | } 213 | table.elements.push(parseFloat(value)); 214 | break; 215 | case "62": 216 | table.color = parseInt(value); 217 | break; 218 | case "73": 219 | table.elements = []; 220 | break; 221 | case "330": 222 | case "360": 223 | table.ownerHandle = value; 224 | break; 225 | } 226 | index = index + 2; 227 | } 228 | return table; 229 | } 230 | 231 | function readDxfTables(tablesArray) { 232 | var imax = tablesArray.length; 233 | var i = 0; 234 | var tables = {}; 235 | 236 | while (i < imax) { 237 | var tableStart = tablesArray.indexOf("TABLE", i); 238 | var tableEnd = tablesArray.indexOf("ENDTAB", tableStart) + 1; 239 | 240 | if (tableEnd !== 0) { 241 | var tableArray = tablesArray.slice(tableStart, tableEnd); 242 | tables[tablesArray[tableStart + 2]] = readDxfTable(tableArray, 1); 243 | i = tableEnd; 244 | } else { 245 | i = imax + 1; 246 | } 247 | } 248 | 249 | return tables; 250 | } 251 | 252 | function readDxfBlock(blockArray, index) { 253 | var length = blockArray.length - 2; 254 | var block = {}; 255 | var code, value; 256 | 257 | while (index < length) { 258 | code = blockArray[index].trim(); 259 | value = blockArray[index + 1].trim(); 260 | 261 | switch (code) { 262 | case "0": 263 | var end = blockArray.indexOf(" 0", index + 2) + 1 || length; 264 | var children = blockArray.slice(index, end - 1); 265 | 266 | block.entities = block.entities || []; 267 | block.entities.push(readDxfEntity(children, 0)); 268 | index = end - 3; 269 | break; 270 | case "1": 271 | block.xrefName = value; 272 | break; 273 | case "2": 274 | block.name = value; 275 | break; 276 | case "3": 277 | block.blockName = value; 278 | break; 279 | case "5": 280 | block.handle = value; 281 | break; 282 | case "8": 283 | block.layerName = value; 284 | break; 285 | case "10": 286 | var start = index + 1; 287 | block.basePoint = readDxfPoints(blockArray, start, 10, 20, 30); 288 | break; 289 | case "330": 290 | block.ownerHandle = value; 291 | break; 292 | case "360": 293 | table.ownerHandle = value; 294 | break; 295 | } 296 | 297 | index = index + 2; 298 | } 299 | return block; 300 | } 301 | 302 | function readDxfBlocks(blocksArray) { 303 | var imax = blocksArray.length; 304 | var i = 0; 305 | var blocks = {}; 306 | 307 | while (i < imax) { 308 | var blockStart = blocksArray.indexOf("BLOCK", i); 309 | var blockEnd = blocksArray.indexOf("ENDBLK", blockStart) + 1; 310 | 311 | if (blockEnd !== 0) { 312 | var blockArray = blocksArray.slice(blockStart, blockEnd); 313 | 314 | var block = readDxfBlock(blockArray, 1); 315 | blocks[block.blockName] = block; 316 | i = blockEnd; 317 | } else { 318 | i = imax + 1; 319 | } 320 | } 321 | 322 | return blocks; 323 | } 324 | 325 | function readDxfEntity(entityArray, index) { 326 | var length = entityArray.length; 327 | var entity = {}; 328 | var code, value, type, bypassCoords; 329 | var edgeType = false; 330 | var vertx, vertxPrevious; 331 | 332 | while (index < length) { 333 | code = entityArray[index].trim(); 334 | value = entityArray[index + 1].trim(); 335 | 336 | switch (code) { 337 | case "0": 338 | if (value != 'VERTEX') { 339 | type = value; 340 | entity.entityType = value; 341 | bypassCoords = true 342 | } else { 343 | type = "POLYLINE" 344 | } 345 | break; 346 | case "1": 347 | case "5": 348 | case "6": 349 | case "7": 350 | case "8": 351 | entity[codeIndex[code]] = value; 352 | break; 353 | case "10": 354 | var start = index + 1; 355 | switch (type) { 356 | case "HATCH": 357 | if (edgeType) { 358 | var vertices = entity.multiVertices[entity.multiVertices.length - 1]; 359 | if (entity.verticesNumber > vertices.length) { 360 | var point = readDxfPoints(entityArray, start, 10, 20); 361 | var lastPoint = vertices[vertices.length - 1]; 362 | if (lastPoint === undefined || (lastPoint.x !== point.x && lastPoint.y !== point.y)) { 363 | vertices.push(point); 364 | } 365 | } 366 | } 367 | break; 368 | case "POLYLINE": 369 | if (bypassCoords) { 370 | bypassCoords = false 371 | break; 372 | } 373 | case "LWPOLYLINE": 374 | entity.vertices = entity.vertices || []; 375 | vertx = readDxfPoints(entityArray, start, 10, 20, 42) 376 | if ( vertxPrevious ) { 377 | entity.vertices = entity.vertices.concat(bulge2arc(vertxPrevious.x,vertxPrevious.y,vertxPrevious.z,vertx.x,vertx.y,segmentizeStepAngleInDegrees)) 378 | } else { 379 | entity.vertices.push({x:vertx.x,y:vertx.y}) 380 | } 381 | if (vertx.z) { 382 | vertxPrevious = vertx 383 | } else { 384 | vertxPrevious = undefined 385 | } 386 | break; 387 | case "ARC": 388 | case "CIRCLE": 389 | case "POINT": 390 | case "MTEXT": 391 | case "XLINE": 392 | entity.point = readDxfPoints(entityArray, start, 10, 20, 30); 393 | break; 394 | case "TEXT": 395 | case "LINE": 396 | entity.startPoint = readDxfPoints(entityArray, start, 10, 20, 30); 397 | break; 398 | } 399 | 400 | break; 401 | case "11": 402 | var start = index + 1; 403 | switch (type) { 404 | case "HATCH": 405 | if (edgeType) { 406 | var vertices = entity.multiVertices[entity.multiVertices.length - 1]; 407 | vertices.push(readDxfPoints(entityArray, start, 11, 21)); 408 | } 409 | edgeType = false; 410 | break; 411 | case "TEXT": 412 | case "LINE": 413 | entity.endPoint = readDxfPoints(entityArray, start, 10, 20, 30); 414 | break; 415 | } 416 | 417 | break; 418 | case "39": 419 | case "48": 420 | case "50": 421 | case "ARC": 422 | entity.startAngle = parseFloat(value) 423 | case "51": 424 | case "ARC": 425 | entity.endAngle = parseFloat(value) 426 | entity[codeIndex[code]] = parseFloat(value); 427 | break; 428 | case "40": 429 | switch (type) { 430 | case "TEXT": 431 | entity.textHeight = parseFloat(value); 432 | break; 433 | case "ARC": 434 | case "CIRCLE": 435 | entity.radius = parseFloat(value); 436 | break; 437 | } 438 | break; 439 | case "60": 440 | case "62": 441 | case "70": 442 | var flags = parseInt(value).toString(2) 443 | var ClosedMdir = parseInt(flags.charAt(flags.length-1)) || 0; 444 | var ClosedNdir = parseInt(flags.charAt(flags.length-6)) || 0; 445 | entity[codeIndex[code]] = ClosedMdir || ClosedNdir; 446 | break; 447 | case "72": 448 | if (value === "1" || value === "0") { 449 | edgeType = true; 450 | } 451 | break; 452 | case "91": 453 | entity.multiVertices = []; 454 | break; 455 | case "93": 456 | entity.verticesNumber = parseInt(value); 457 | entity.multiVertices.push([]); 458 | break; 459 | case "330": 460 | entity.ownerHandle = value; 461 | break; 462 | } 463 | 464 | index = index + 2; 465 | } 466 | return entity; 467 | } 468 | 469 | function readDxfEntities(entitiesArray) { 470 | var imax = entitiesArray.length; 471 | var i = 0; 472 | var entities = []; 473 | var entityEnd; 474 | 475 | while (i < imax) { 476 | var entityStart = entitiesArray.indexOf(" 0", i); 477 | if ( entitiesArray[entityStart+1] == "POLYLINE") { 478 | entityEnd = entitiesArray.indexOf("SEQEND", entityStart + 1); 479 | entityEnd -= 1; 480 | } else { 481 | entityEnd = entitiesArray.indexOf(" 0", entityStart + 1); 482 | } 483 | 484 | if (entityEnd !== -1) { 485 | var entityArray = entitiesArray.slice(entityStart, entityEnd); 486 | var entity = readDxfEntity(entityArray, 0); 487 | entities.push(entity); 488 | i = entityEnd; 489 | } else { 490 | i = imax + 1; 491 | } 492 | } 493 | 494 | return entities; 495 | } 496 | 497 | function readGroupValue(code, value) { 498 | if (code <= 9) { 499 | return value; 500 | } else if (code >= 10 && code <= 59) { 501 | return parseFloat(value); 502 | } else if (code >= 60 && code <= 99) { 503 | return parseInt(value); 504 | } else if (code >= 100 && code <= 109) { 505 | return value; 506 | } else if (code >= 110 && code <= 149) { 507 | return parseFloat(value); 508 | } else if (code >= 160 && code <= 179) { 509 | return parseInt(value); 510 | } else if (code >= 210 && code <= 239) { 511 | return parseFloat(value); 512 | } else if (code >= 270 && code <= 289) { 513 | return parseInt(value); 514 | } else if (code >= 290 && code <= 299) { 515 | return !!parseInt(value); 516 | } else if (code >= 300 && code <= 369) { 517 | return value; 518 | } else if (code >= 370 && code <= 389) { 519 | return parseInt(value); 520 | } else if (code >= 390 && code <= 399) { 521 | return value; 522 | } else if (code >= 400 && code <= 409) { 523 | return parseInt(value); 524 | } else if (code >= 410 && code <= 419) { 525 | return value; 526 | } else if (code >= 420 && code <= 429) { 527 | return parseInt(value); 528 | } else if (code >= 430 && code <= 439) { 529 | return value; 530 | } else if (code >= 440 && code <= 459) { 531 | return parseInt(value); 532 | } else if (code >= 460 && code <= 469) { 533 | return parseFloat(value); 534 | } else if (code >= 470 && code <= 481) { 535 | return value; 536 | } else if (code === 999) { 537 | return value; 538 | } else if (code >= 1000 && code <= 1009) { 539 | return value; 540 | } else if (code >= 1010 && code <= 1059) { 541 | return parseFloat(value); 542 | } else if (code >= 1060 && code <= 1071) { 543 | return parseInt(value); 544 | } else { 545 | return value; 546 | } 547 | } 548 | 549 | function dxf2GeojsonPoint(point, transitions) { 550 | var point = transitions ? transitions.trans([point.x, point.y]) : [point.x, point.y]; 551 | return point; 552 | } 553 | 554 | function dxf2GeojsonPolyline(polyline, transitions) { 555 | var lineString = []; 556 | if (polyline === undefined) { 557 | var cc = 123; 558 | } else { 559 | polyline.forEach(function(point) { 560 | lineString.push(dxf2GeojsonPoint(point, transitions)); 561 | }); 562 | } 563 | return lineString; 564 | } 565 | 566 | function angle(x1,y1, x2,y2) { 567 | return Math.atan2(y2-y1, x2-x1) 568 | } 569 | 570 | function polar(x1,y1, phi, dist) { 571 | return [x1 + dist * Math.cos(phi), y1 + dist * Math.sin(phi)] 572 | } 573 | 574 | function bulge2arc(x1,y1,bulge,x2,y2,stepAngle) { 575 | 576 | var dist = Math.sqrt((x2-x1)**2+(y2-y1)**2) 577 | var a = Math.atan(bulge) * 4.0 578 | 579 | var theta = 4.0 * Math.atan(Math.abs(bulge)) 580 | var radius = (dist/2)/Math.sin(theta/2) 581 | var gamma = (Math.PI - theta) / 2.0 582 | var phi = angle(x1,y1, x2,y2) + gamma * Math.sign(bulge) 583 | 584 | 585 | var center = polar(x1,y1, phi, radius) 586 | 587 | var startAngle = Math.acos((x1 - center[0]) / radius) 588 | if (Math.sign(y1 - center[1]) < 0) { 589 | startAngle = (2.0 * Math.PI) - startAngle 590 | } 591 | var endAngle = startAngle + a 592 | 593 | return segmentize(center[0], center[1], radius, 180*startAngle/Math.PI, 180*endAngle/Math.PI, stepAngle) 594 | 595 | } 596 | 597 | function getSegment(centerx,centery,angle,radius) { 598 | return { 599 | x: centerx + Math.cos(angle*Math.PI/180)*radius, 600 | y: centery + Math.sin(angle*Math.PI/180)*radius 601 | } 602 | } 603 | 604 | function segmentize(centerx,centery,radius,startAngle,endAngle,stepAngle) { 605 | var p, test 606 | var v = [] 607 | if (endAngle < startAngle) { 608 | stepAngle = -stepAngle 609 | test = function(a,b) {return a > b} 610 | } else { 611 | test = function(a,b) {return a < b} 612 | } 613 | for (var a = startAngle; test(a, endAngle); a += stepAngle){ 614 | v.push(getSegment(centerx,centery,a,radius)) 615 | } 616 | v.push(getSegment(centerx,centery, endAngle,radius)) 617 | return v 618 | } 619 | 620 | function dxfEntity2Feature(entity, transitions) { 621 | var geometry = {}; 622 | switch (entity.entityType) { 623 | case "ARC": 624 | geometry.type = "LineString"; 625 | geometry.coordinates = dxf2GeojsonPolyline(segmentize(entity.point.x, entity.point.y, entity.radius, entity.startAngle, entity.endAngle, segmentizeStepAngleInDegrees), transitions); 626 | break; 627 | case "CIRCLE": 628 | geometry.type = "LineString"; 629 | geometry.coordinates = dxf2GeojsonPolyline(segmentize(entity.point.x, entity.point.y, entity.radius, 0, 360, segmentizeStepAngleInDegrees), transitions); 630 | geometry.coordinates.push(geometry.coordinates[0]); 631 | entity.closed = 1 632 | break; 633 | case "INSERT": 634 | break; 635 | case "TEXT": 636 | geometry.type = "Point"; 637 | geometry.coordinates = dxf2GeojsonPoint(entity.startPoint, transitions); 638 | break; 639 | case "LINE": 640 | geometry.type = "LineString"; 641 | geometry.coordinates = dxf2GeojsonPolyline([entity.startPoint, entity.endPoint], transitions); 642 | break; 643 | case "POLYLINE": 644 | case "LWPOLYLINE": 645 | geometry.type = "LineString"; 646 | geometry.coordinates = dxf2GeojsonPolyline(entity.vertices, transitions); 647 | if (entity.closed === 1) { 648 | geometry.coordinates.push(geometry.coordinates[0]); 649 | } 650 | break; 651 | case "HATCH": 652 | geometry.type = "Polygon"; 653 | geometry.coordinates = []; 654 | entity.multiVertices.forEach(function(vertices) { 655 | var coordinates = dxf2GeojsonPolyline(vertices, transitions); 656 | coordinates.push(coordinates[0]); 657 | geometry.coordinates.push(coordinates); 658 | }); 659 | break; 660 | default: 661 | break; 662 | } 663 | 664 | if (geometry.type !== undefined) { 665 | var feature = {}; 666 | feature.type = "Feature"; 667 | feature.geometry = geometry; 668 | feature.properties = {}; 669 | feature.style = {}; 670 | 671 | [ 672 | "text", 673 | "textHeight", 674 | "textStyleName", 675 | "layerName", 676 | "entityType", 677 | "closed" 678 | ].forEach(function(name) { 679 | if (entity[name] !== undefined) { 680 | feature.properties[name] = entity[name]; 681 | } 682 | }); 683 | 684 | return feature; 685 | } 686 | } 687 | 688 | function dxfObject2Geojson(dxf, transitions) { 689 | var geojson = GeoConvert.emptyGeojson(); 690 | 691 | //blocks 692 | for (var key in dxf.blocks) { 693 | var block = dxf.blocks[key]; 694 | var entities = block.entities; 695 | 696 | if (entities !== undefined) { 697 | entities.forEach(function(entity) { 698 | var feature = dxfEntity2Feature(entity, transitions); 699 | if (feature !== undefined) { 700 | geojson.features.push(feature); 701 | } 702 | }); 703 | } 704 | } 705 | 706 | //entities 707 | dxf.entities.forEach(function(entity) { 708 | var feature = dxfEntity2Feature(entity, transitions); 709 | if (feature !== undefined) { 710 | geojson.features.push(feature); 711 | } 712 | }); 713 | 714 | return geojson; 715 | } 716 | })(window, document); 717 | -------------------------------------------------------------------------------- /src/KML.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function(window, document, undefined) { 3 | //kml2geojson 4 | GeoConvert.kml2Geojson = function(kml, toString) { 5 | var json; 6 | 7 | if (typeof kml === "string") { 8 | if (kml.indexOf("kml:") !== -1) { 9 | var tempKml = kml.replace(/\kml:/gi, ""); 10 | json = GeoConvert.xml2Json(tempKml); 11 | } else { 12 | json = GeoConvert.xml2Json(kml); 13 | } 14 | } else if (typeof kml === "object" && kml.xmlVersion) { 15 | json = GeoConvert.xml2Json(kml); 16 | } else { 17 | throw new Error("Unsupported input type"); 18 | } 19 | 20 | var geojson = GeoConvert.emptyGeojson(); 21 | var style = {}; 22 | 23 | kmlElementHandle("kml", json.kml, geojson, style); 24 | 25 | if (toString) { 26 | var jsonString = JSON.stringify(geojson); 27 | return jsonString; 28 | } else { 29 | return geojson; 30 | } 31 | }; 32 | 33 | function kmlElementHandle(tag, contain, geojson, style) { 34 | switch (tag) { 35 | case "kml": 36 | case "Document": 37 | case "Folder": 38 | if (!contain.forEach) { 39 | var keys = Object.keys(contain); 40 | 41 | var styleIndex = keys.indexOf("Style"); 42 | if (styleMapIndex > -1) { 43 | keys.splice(styleMapIndex, 1); 44 | kmlElementHandle("StyleMap", contain.StyleMap, geojson, style); 45 | } 46 | 47 | var styleMapIndex = keys.indexOf("StyleMap"); 48 | if (styleIndex > -1) { 49 | keys.splice(styleIndex, 1); 50 | kmlElementHandle("Style", contain.Style, geojson, style); 51 | } 52 | 53 | keys.forEach(function(c) { 54 | kmlElementHandle(c, contain[c], geojson, style); 55 | }); 56 | } else { 57 | contain.forEach(function(c) { 58 | kmlElementHandle(tag, c, geojson, style); 59 | }); 60 | } 61 | break; 62 | case "Placemark": 63 | if (contain.forEach) { 64 | contain.forEach(function(placemark) { 65 | geojson.features.push(placemark2Feature(placemark, style)); 66 | }); 67 | } else { 68 | geojson.features.push(placemark2Feature(contain, style)); 69 | } 70 | break; 71 | case "Style": 72 | case "StyleMap": 73 | if (contain.forEach) { 74 | contain.forEach(function(styleContain) { 75 | if (styleContain["@id"]) { 76 | style[styleContain["@id"]] = styleContain; 77 | } 78 | }); 79 | } else { 80 | if (contain["@id"]) { 81 | style[contain["@id"]] = contain; 82 | } 83 | } 84 | break; 85 | case "GroundOverlay": 86 | if (contain.forEach) { 87 | contain.forEach(function(groundOverlay) { 88 | geojson.features.push(groundOverlay2Feature(groundOverlay)); 89 | }); 90 | } else { 91 | geojson.features.push(groundOverlay2Feature(contain)); 92 | } 93 | break; 94 | } 95 | } 96 | 97 | function groundOverlay2Feature(groundOverlay) { 98 | var feature = {}; 99 | feature.type = "Feature"; 100 | feature.properties = {}; 101 | feature.geometry = null; 102 | 103 | if (groundOverlay.name) { 104 | feature.properties.name = groundOverlay.name; 105 | } 106 | if (groundOverlay.description) { 107 | feature.properties.description = groundOverlay.description; 108 | } 109 | 110 | if (groundOverlay.Icon && groundOverlay.Icon.href) { 111 | feature.properties.iconUrl = groundOverlay.Icon.href; 112 | } 113 | if (groundOverlay.visibility) { 114 | feature.properties.opacity = parseFloat(groundOverlay.visibility); 115 | } 116 | 117 | if (groundOverlay.LatLonBox) { 118 | latLonBox = groundOverlay.LatLonBox; 119 | var southWest = [parseFloat(latLonBox.south), parseFloat(latLonBox.west)]; 120 | var northEast = [parseFloat(latLonBox.north), parseFloat(latLonBox.east)]; 121 | var latLngBounds = [southWest, northEast]; 122 | 123 | feature.properties.latLngBounds = latLngBounds; 124 | } 125 | 126 | return feature; 127 | } 128 | 129 | function placemark2Feature(placemark, style) { 130 | var feature = {}; 131 | feature.type = "Feature"; 132 | feature.properties = {}; 133 | feature.style = {}; 134 | 135 | if (placemark.name) { 136 | feature.properties.name = placemark.name; 137 | } 138 | if (placemark.description) { 139 | feature.properties.description = placemark.description; 140 | } 141 | 142 | if (placemark["gx:Track"] || placemark["gx:MultiTrack"]) { 143 | var geometry = {}; 144 | var coordinates = []; 145 | 146 | var multiTrack = placemark["gx:MultiTrack"]; 147 | var track = multiTrack ? multiTrack["gx:Track"] : placemark["gx:Track"]; 148 | var gxCoord = track["gx:coord"]; 149 | 150 | if (gxCoord) { 151 | gxCoord.forEach(function(pointString) { 152 | if (pointString.trim() !== "") { 153 | var point = pointString.split(" "); 154 | coordinates.push([parseFloat(point[0]), parseFloat(point[1])]); 155 | } 156 | }); 157 | } 158 | 159 | if (track.when) { 160 | feature.properties.when = track.when; 161 | } 162 | 163 | if (track.ExtendedData && track.ExtendedData.SchemaData && track.ExtendedData.SchemaData["gx:SimpleArrayData"]) { 164 | track.ExtendedData.SchemaData["gx:SimpleArrayData"].forEach(function(data) { 165 | feature.properties[data["@name"]] = data["gx:value"]; 166 | }); 167 | } 168 | 169 | geometry.type = "LineString"; 170 | geometry.coordinates = coordinates; 171 | 172 | feature.geometry = geometry; 173 | } else { 174 | feature.geometry = placemark2Geometry(placemark); 175 | } 176 | 177 | var geojsonStyle = placemark.Style || {}; 178 | if (placemark.styleUrl) { 179 | var styleId = placemark.styleUrl.replace("#", ""); 180 | 181 | if (style[styleId]) { 182 | var mStyle; 183 | var styleId2; 184 | 185 | if (style[styleId].Pair) { 186 | style[styleId].Pair.forEach(function(style2) { 187 | if (style2.key && style2.key === "normal") { 188 | styleId2 = style2.styleUrl.replace("#", ""); 189 | } 190 | }); 191 | mStyle = style[styleId2]; 192 | } else { 193 | mStyle = style[styleId]; 194 | } 195 | 196 | var tempKeys = Object.keys(Object.assign({}, geojsonStyle, mStyle)); 197 | tempKeys.forEach(function(tk) { 198 | var type = typeof geojsonStyle[tk]; 199 | if (type === "object") { 200 | geojsonStyle[tk] = Object.assign({}, geojsonStyle[tk], mStyle[tk]); 201 | } else if (type === "undefined") { 202 | geojsonStyle[tk] = mStyle[tk]; 203 | } 204 | }); 205 | } 206 | } 207 | 208 | for (var styleKey in geojsonStyle) { 209 | switch (styleKey) { 210 | case "IconStyle": 211 | var iconUrl = geojsonStyle.IconStyle.Icon.href; 212 | var scale = geojsonStyle.IconStyle.scale; 213 | var color = geojsonStyle.IconStyle.color; 214 | 215 | if (iconUrl) { 216 | feature.style.iconUrl = iconUrl; 217 | } 218 | if (scale) { 219 | feature.style.scale = parseFloat(scale); 220 | } 221 | if (color) { 222 | color = abgr2Color(color); 223 | feature.style.color = color.hex; 224 | feature.style.opacity = color.opacity; 225 | } 226 | if (geojsonStyle.IconStyle.hotSpot) { 227 | var hotSpotX = parseFloat(geojsonStyle.IconStyle.hotSpot["@x"]); 228 | var hotSpotY = parseFloat(geojsonStyle.IconStyle.hotSpot["@y"]); 229 | feature.style.iconAnchor = [hotSpotX, hotSpotY]; 230 | } 231 | break; 232 | case "LineStyle": 233 | var color = abgr2Color(geojsonStyle.LineStyle.color); 234 | var width = parseFloat(geojsonStyle.LineStyle.width); 235 | 236 | if (color) { 237 | feature.style.color = color.hex; 238 | feature.style.opacity = color.opacity; 239 | } 240 | if (width) { 241 | feature.style.weight = width; 242 | } 243 | break; 244 | case "PolyStyle": 245 | var color = abgr2Color(geojsonStyle.PolyStyle.color); 246 | var fill = parseInt(fill); 247 | var stroke = parseInt(geojsonStyle.PolyStyle.outline); 248 | 249 | if (color) { 250 | feature.style.fillColor = color.hex; 251 | feature.style.fillOpacity = color.opacity; 252 | } 253 | if (fill) { 254 | feature.style.fill = fill; 255 | } 256 | if (stroke) { 257 | feature.style.stroke = stroke; 258 | } 259 | break; 260 | } 261 | } 262 | 263 | return feature; 264 | } 265 | 266 | function placemark2Geometry(placemark) { 267 | var geometry = {}; 268 | 269 | if (placemark.Point) { 270 | if (placemark.Point.forEach) { 271 | var coordinates = []; 272 | placemark.Point.forEach(function(p) { 273 | var coordinates2 = []; 274 | var pointString = p.coordinates.replace(/\t|\n/gi, ''); 275 | 276 | if (pointString.trim() !== "") { 277 | var point = pointString.split(","); 278 | coordinates2 = [parseFloat(point[0]), parseFloat(point[1])]; 279 | } 280 | coordinates.push(coordinates2); 281 | }); 282 | 283 | geometry.type = "MultiPoint"; 284 | geometry.coordinates = coordinates; 285 | } else { 286 | var coordinates = []; 287 | var pointString = placemark.Point.coordinates.replace(/\t|\n/gi, ''); 288 | 289 | if (pointString.trim() !== "") { 290 | var point = pointString.split(","); 291 | coordinates = [parseFloat(point[0]), parseFloat(point[1])]; 292 | } 293 | 294 | geometry.type = "Point"; 295 | geometry.coordinates = coordinates; 296 | } 297 | } else if (placemark.LineString) { 298 | if (placemark.LineString.forEach) { 299 | var coordinates = []; 300 | placemark.LineString.forEach(function(l) { 301 | var coordinates2 = []; 302 | // var coordinatesString = l.coordinates.replace(/\t|\n/gi, ''); 303 | var coordinatesString = l.coordinates.trim(); 304 | 305 | coordinatesString.split(/\t|\n|\s/g).forEach(function(pointString) { 306 | if (pointString.trim() !== "") { 307 | var point = pointString.split(","); 308 | coordinates2.push([parseFloat(point[0]), parseFloat(point[1])]); 309 | } 310 | }); 311 | coordinates.push(coordinates2); 312 | }); 313 | 314 | geometry.type = "MultiLineString"; 315 | geometry.coordinates = coordinates; 316 | } else { 317 | var coordinates = []; 318 | // var coordinatesString = placemark.LineString.coordinates.replace(/\t|\n/gi, ''); 319 | var coordinatesString = placemark.LineString.coordinates.trim(); 320 | 321 | coordinatesString.split(/\t|\n|\s/g).forEach(function(pointString) { 322 | if (pointString.trim() !== "") { 323 | var point = pointString.split(","); 324 | coordinates.push([parseFloat(point[0]), parseFloat(point[1])]); 325 | } 326 | }); 327 | 328 | geometry.type = "LineString"; 329 | geometry.coordinates = coordinates; 330 | } 331 | } else if (placemark.Polygon) { 332 | if (placemark.Polygon.forEach) { 333 | var coordinates = []; 334 | 335 | placemark.Polygon.forEach(function(polygon) { 336 | var coordinates2 = boundarys2Coordinates(polygon); 337 | coordinates.push(coordinates2); 338 | }); 339 | 340 | geometry.type = "MultiPolygon"; 341 | geometry.coordinates = coordinates; 342 | } else { 343 | var coordinates = boundarys2Coordinates(placemark.Polygon); 344 | 345 | geometry.type = "Polygon"; 346 | geometry.coordinates = coordinates; 347 | } 348 | } else if (placemark.MultiGeometry) { 349 | var multiGeometry = placemark.MultiGeometry; 350 | if (Object.keys(multiGeometry).length > 1) { 351 | var geometries = []; 352 | 353 | for (var type in multiGeometry) { 354 | if (multiGeometry[type].forEach) { 355 | multiGeometry[type].forEach(function(tempGeometry) { 356 | var tempPlacemark = {}; 357 | tempPlacemark[type] = tempGeometry; 358 | geometries.push(placemark2Geometry(tempPlacemark)); 359 | }); 360 | } else { 361 | var tempPlacemark = {}; 362 | tempPlacemark[type] = multiGeometry[type]; 363 | geometries.push(placemark2Geometry(tempPlacemark)); 364 | } 365 | } 366 | 367 | geometry.type = "GeometryCollection"; 368 | geometry.geometries = geometries; 369 | } else { 370 | geometry = placemark2Geometry(multiGeometry); 371 | } 372 | } 373 | 374 | return geometry; 375 | } 376 | 377 | function boundary2Coordinates(boundary) { 378 | var boundaryCoordinates = []; 379 | // var coordinatesString = boundary.LinearRing.coordinates.replace(/\t|\n/gi, ''); 380 | var coordinatesString = boundary.LinearRing.coordinates.trim(); 381 | 382 | coordinatesString.split(/\t|\n|\s/g).forEach(function(pointString) { 383 | if (pointString.trim() !== "") { 384 | var point = pointString.split(","); 385 | boundaryCoordinates.push([parseFloat(point[0]), parseFloat(point[1])]); 386 | } 387 | }); 388 | return boundaryCoordinates; 389 | } 390 | 391 | function boundarys2Coordinates(polygon) { 392 | var coordinates = []; 393 | 394 | ['outerBoundaryIs', 'innerBoundaryIs'].forEach(function(boundaryIs) { 395 | var boundarys = polygon[boundaryIs]; 396 | if (boundarys) { 397 | var boundaryCoordinates; 398 | if (boundarys.forEach) { 399 | boundarys.forEach(function(boundary) { 400 | boundaryCoordinates = boundary2Coordinates(boundary); 401 | coordinates.push(boundaryCoordinates); 402 | }); 403 | } else { 404 | boundaryCoordinates = boundary2Coordinates(boundarys); 405 | coordinates.push(boundaryCoordinates); 406 | } 407 | } 408 | }); 409 | return coordinates; 410 | } 411 | 412 | function abgr2Color(abgr) { 413 | var color = {}; 414 | if (typeof abgr === "string" && abgr.length === 8) { 415 | color.hex = "#" + abgr.slice(6, 8) + abgr.slice(4, 6) + abgr.slice(2, 4); 416 | color.opacity = Math.round(parseInt(abgr.slice(0, 2), 16) / 255 * 100) / 100; 417 | } else { 418 | color.hex = "#000"; 419 | color.opacity = 1; 420 | } 421 | return color; 422 | } 423 | 424 | //geojson2kml 425 | GeoConvert.geojson2Kml = function(json, toString) { 426 | //check string? 427 | var geojson; 428 | 429 | if (typeof json === "string") { 430 | geojson = JSON.parse(json); 431 | } else { 432 | geojson = json; 433 | } 434 | 435 | var kmljson = emptyKmljson(); 436 | var placemark = []; 437 | var style = []; 438 | placemark.sameName = true; 439 | 440 | if (geojson.type !== "Feature" && geojson.type !== "FeatureCollection") { 441 | geojson = { 442 | type: "Feature", 443 | geometry: geojson, 444 | properties: {} 445 | }; 446 | } 447 | 448 | geojsonElementHandle(geojson, placemark, style); 449 | kmljson.Document.Style = geojsonStyle2KmlStyle(style); 450 | kmljson.Document.Placemark = placemark; 451 | 452 | var kml = GeoConvert.json2Xml(kmljson, 'kml'); 453 | 454 | if (toString) { 455 | var kmlString = "" + (new XMLSerializer()).serializeToString(kml); 456 | return kmlString; 457 | } else { 458 | return kml; 459 | } 460 | }; 461 | 462 | function emptyKmljson() { 463 | var kmljson = {}; 464 | kmljson["@xmlns"] = "http://www.opengis.net/kml/2.2"; 465 | kmljson["@xmlns:gx"] = "http://www.google.com/kml/ext/2.2"; 466 | kmljson["@xmlns:kml"] = "http://www.opengis.net/kml/2.2"; 467 | kmljson["@xmlns:atom"] = "http://www.w3.org/2005/Atom"; 468 | kmljson.Document = {}; 469 | 470 | return kmljson; 471 | } 472 | 473 | function geojsonElementHandle(gObject, placemark, style) { 474 | switch (gObject.type) { 475 | case "Point": 476 | case "LineString": 477 | case "Polygon": 478 | var type = gObject.type; 479 | if (placemark[type]) { 480 | var tempPlacemark = geometry2Placemark(type, gObject.coordinates); 481 | 482 | if (!placemark[type].push) { 483 | placemark[type] = [placemark[type]]; 484 | placemark[type].sameName = true; 485 | } 486 | placemark[type].push(tempPlacemark); 487 | } else { 488 | placemark[type] = geometry2Placemark(type, gObject.coordinates); 489 | } 490 | break; 491 | case "MultiPoint": 492 | case "MultiLineString": 493 | case "MultiPolygon": 494 | var type = gObject.type.replace("Multi", ""); 495 | placemark.MultiGeometry = {}; 496 | gObject.coordinates.forEach(function(coordinates) { 497 | geojsonElementHandle({ 498 | type: type, 499 | coordinates: coordinates 500 | }, placemark.MultiGeometry); 501 | }); 502 | break; 503 | case "GeometryCollection": 504 | placemark.MultiGeometry = {}; 505 | gObject.geometries.forEach(function(geometry) { 506 | geojsonElementHandle(geometry, placemark.MultiGeometry); 507 | }); 508 | break; 509 | case "Feature": 510 | var tempPlacemark = {}; 511 | geojsonElementHandle(gObject.geometry, tempPlacemark); 512 | if (gObject.properties.name) { 513 | tempPlacemark.name = gObject.properties.name; 514 | } 515 | if (gObject.properties.description) { 516 | tempPlacemark.description = gObject.properties.description; 517 | } 518 | var styleId = featureStyle(gObject, style); 519 | tempPlacemark.styleUrl = styleId; 520 | placemark.push(tempPlacemark); 521 | break; 522 | case "FeatureCollection": 523 | gObject.features.forEach(function(feature) { 524 | geojsonElementHandle(feature, placemark, style); 525 | }); 526 | break; 527 | } 528 | } 529 | 530 | function featureStyle(gObject, style) { 531 | var tempStyle = Object.assign({}, gObject.style); 532 | var styleId = 0; 533 | 534 | style.forEach(function(s, index) { 535 | var addStyle = false; 536 | for (var t in tempStyle) { 537 | if (tempStyle[t] !== s[t]) { 538 | addStyle = true; 539 | } 540 | } 541 | 542 | if (!addStyle) { 543 | styleId = (index + 1); 544 | } 545 | }); 546 | 547 | if (styleId === 0) { 548 | style.push(tempStyle); 549 | styleId = style.length; 550 | } 551 | 552 | return "custom" + styleId; 553 | } 554 | 555 | function geometry2Placemark(type, coordinates) { 556 | var placemark = {}; 557 | switch (type) { 558 | case "Point": 559 | placemark = {}; 560 | placemark.coordinates = coordinates.join(); 561 | break; 562 | case "LineString": 563 | placemark = {}; 564 | placemark.tessellate = 1; 565 | placemark.coordinates = coordinates.join(' '); 566 | break; 567 | case "Polygon": 568 | placemark = {}; 569 | placemark.tessellate = 1; 570 | placemark.outerBoundaryIs = {}; 571 | placemark.outerBoundaryIs.LinearRing = {}; 572 | placemark.outerBoundaryIs.LinearRing.coordinates = coordinates[0].join(' '); 573 | 574 | coordinates.shift(); 575 | coordinates.forEach(function(coordinates) { 576 | placemark.innerBoundaryIs = {}; 577 | placemark.innerBoundaryIs.LinearRing = {}; 578 | placemark.innerBoundaryIs.LinearRing.coordinates = coordinates.join(' '); 579 | }); 580 | break; 581 | } 582 | return placemark; 583 | } 584 | 585 | function geojsonStyle2KmlStyle(style) { 586 | var chart = {}; 587 | chart.stroke = "outline"; 588 | chart.fill = "fill"; 589 | 590 | var kStyle = style.map(function(style1, index) { 591 | var tempStyle = {}; 592 | tempStyle["@id"] = "custom" + (index + 1); 593 | 594 | for (var s in style1) { 595 | switch (s) { 596 | case "iconUrl": 597 | case "iconAnchor": 598 | case "scale": 599 | if (!tempStyle.IconStyle) { 600 | tempStyle.IconStyle = {}; 601 | } 602 | break; 603 | case "color": 604 | case "weight": 605 | if (!tempStyle.LineStyle) { 606 | tempStyle.LineStyle = {}; 607 | } 608 | break; 609 | case "stroke": 610 | case "fill": 611 | case "fillColor": 612 | if (!tempStyle.PolyStyle) { 613 | tempStyle.PolyStyle = {}; 614 | } 615 | break; 616 | } 617 | 618 | switch (s) { 619 | case "iconUrl": 620 | tempStyle.IconStyle.Icon = {}; 621 | tempStyle.IconStyle.Icon.href = style1.iconUrl; 622 | break; 623 | case "iconAnchor": 624 | tempStyle.IconStyle.hotSpot = {}; 625 | tempStyle.IconStyle.hotSpot["@x"] = style1.iconAnchor[0]; 626 | tempStyle.IconStyle.hotSpot["@y"] = style1.iconAnchor[1]; 627 | tempStyle.IconStyle.hotSpot["@xunits"] = "pixels"; 628 | tempStyle.IconStyle.hotSpot["@yunits"] = "pixels"; 629 | break; 630 | case "scale": 631 | tempStyle.IconStyle.scale = style1.scale; 632 | break; 633 | case "color": 634 | tempStyle.LineStyle.color = color2Abgr(style1.color, style1.opacity); 635 | break; 636 | case "weight": 637 | tempStyle.LineStyle.width = style1.weight; 638 | break; 639 | case "stroke": 640 | tempStyle.PolyStyle.outline = style1.stroke; 641 | case "fill": 642 | tempStyle.PolyStyle.fill = style1.fill; 643 | break; 644 | case "fillColor": 645 | tempStyle.PolyStyle.color = color2Abgr(style1.fillColor, style1.fillOpacity); 646 | break; 647 | } 648 | } 649 | return tempStyle; 650 | }); 651 | 652 | kStyle.sameName = true; 653 | return kStyle; 654 | } 655 | 656 | function color2Abgr(color, opacity) { 657 | color = color.replace("#", ""); 658 | opacity = opacity ? opacity : 1; 659 | var a = parseInt(opacity * 255).toString(16); 660 | var abgr = a + color.slice(4, 6) + color.slice(2, 4) + color.slice(0, 2); 661 | return abgr; 662 | } 663 | })(window, document); -------------------------------------------------------------------------------- /dist/GeoConvert.min.js: -------------------------------------------------------------------------------- 1 | var GeoConvert={};GeoConvert.emptyGeojson=function(){var e={};return e.type="FeatureCollection",e.features=[],e},GeoConvert.decode={},GeoConvert.decode.utf8=new TextDecoder("utf-8"),GeoConvert.decode.big5=new TextDecoder("big5"),function(e,t,r){function n(e){var t={};if(e.attributes)for(var r=0,a=e.attributes.length;r0)for(var c={},r=0,a=e.children.length;r0?t["#"]=s:t=s}return t}function a(e,t,r){var n=r.createElement(e);if(t.forEach)t.forEach(function(e){var t=a("_array",e,r);n.appendChild(t)});else if("object"==typeof t)for(var o in t)if("@"===o[0]){var e=o.replace("@","");n.setAttribute(e,t[o])}else if("#"===o)n.textContent=t[o];else if("object"!=typeof t[o]){var i=r.createElement(o);i.textContent=t[o],n.appendChild(i)}else if(t[o].forEach&&t[o].sameName)t[o].forEach(function(e){var t=a(o,e,r);n.appendChild(t)});else{var i=a(o,t[o],r);n.appendChild(i)}else n.textContent=t;return n}GeoConvert.xml2Json=function(t,r){var a;a=e.DOMParser?function(t){return(new e.DOMParser).parseFromString(t,"text/xml")}:"undefined"!=typeof e.ActiveXObject&&new e.ActiveXObject("Microsoft.XMLDOM")?function(t){var r=new e.ActiveXObject("Microsoft.XMLDOM");return r.async="false",r.loadXML(t),r}:function(){return null};var o;if("string"==typeof t)o=a(t);else{if("object"!=typeof t||!t.xmlVersion)throw new Error("Unsupported input type");o=t}var i=n(o);if(r){var s=JSON.stringify(i);return s}return i},GeoConvert.json2Xml=function(e,r,n){var o;o="string"==typeof e?JSON.parse(e):e;var i,s=r.trim()?r:"root",c=t.implementation.createDocument(null,"create");if(i=a(s,o,c),n){var l=""+(new XMLSerializer).serializeToString(i);return l}return i}}(window,document),function(e,t,r){function n(e,t,r,i){switch(e){case"kml":case"Document":case"Folder":if(t.forEach)t.forEach(function(t){n(e,t,r,i)});else{var s=Object.keys(t),c=s.indexOf("Style");l>-1&&(s.splice(l,1),n("StyleMap",t.StyleMap,r,i));var l=s.indexOf("StyleMap");c>-1&&(s.splice(c,1),n("Style",t.Style,r,i)),s.forEach(function(e){n(e,t[e],r,i)})}break;case"Placemark":t.forEach?t.forEach(function(e){r.features.push(o(e,i))}):r.features.push(o(t,i));break;case"Style":case"StyleMap":t.forEach?t.forEach(function(e){e["@id"]&&(i[e["@id"]]=e)}):t["@id"]&&(i[t["@id"]]=t);break;case"GroundOverlay":t.forEach?t.forEach(function(e){r.features.push(a(e))}):r.features.push(a(t))}}function a(e){var t={};if(t.type="Feature",t.properties={},t.geometry=null,e.name&&(t.properties.name=e.name),e.description&&(t.properties.description=e.description),e.Icon&&e.Icon.href&&(t.properties.iconUrl=e.Icon.href),e.visibility&&(t.properties.opacity=parseFloat(e.visibility)),e.LatLonBox){latLonBox=e.LatLonBox;var r=[parseFloat(latLonBox.south),parseFloat(latLonBox.west)],n=[parseFloat(latLonBox.north),parseFloat(latLonBox.east)],a=[r,n];t.properties.latLngBounds=a}return t}function o(e,t){var r={};if(r.type="Feature",r.properties={},r.style={},e.name&&(r.properties.name=e.name),e.description&&(r.properties.description=e.description),e["gx:Track"]||e["gx:MultiTrack"]){var n={},a=[],o=e["gx:MultiTrack"],s=o?o["gx:Track"]:e["gx:Track"],c=s["gx:coord"];c&&c.forEach(function(e){if(""!==e.trim()){var t=e.split(" ");a.push([parseFloat(t[0]),parseFloat(t[1])])}}),s.when&&(r.properties.when=s.when),s.ExtendedData&&s.ExtendedData.SchemaData&&s.ExtendedData.SchemaData["gx:SimpleArrayData"]&&s.ExtendedData.SchemaData["gx:SimpleArrayData"].forEach(function(e){r.properties[e["@name"]]=e["gx:value"]}),n.type="LineString",n.coordinates=a,r.geometry=n}else r.geometry=i(e);var p=e.Style||{};if(e.styleUrl){var u=e.styleUrl.replace("#","");if(t[u]){var f,y;t[u].Pair?(t[u].Pair.forEach(function(e){e.key&&"normal"===e.key&&(y=e.styleUrl.replace("#",""))}),f=t[y]):f=t[u];var v=Object.keys(Object.assign({},p,f));v.forEach(function(e){var t=typeof p[e];"object"===t?p[e]=Object.assign({},p[e],f[e]):"undefined"===t&&(p[e]=f[e])})}}for(var h in p)switch(h){case"IconStyle":var m=p.IconStyle.Icon.href,g=p.IconStyle.scale,d=p.IconStyle.color;if(m&&(r.style.iconUrl=m),g&&(r.style.scale=parseFloat(g)),d&&(d=l(d),r.style.color=d.hex,r.style.opacity=d.opacity),p.IconStyle.hotSpot){var b=parseFloat(p.IconStyle.hotSpot["@x"]),k=parseFloat(p.IconStyle.hotSpot["@y"]);r.style.iconAnchor=[b,k]}break;case"LineStyle":var d=l(p.LineStyle.color),x=parseFloat(p.LineStyle.width);d&&(r.style.color=d.hex,r.style.opacity=d.opacity),x&&(r.style.weight=x);break;case"PolyStyle":var d=l(p.PolyStyle.color),S=parseInt(S),w=parseInt(p.PolyStyle.outline);d&&(r.style.fillColor=d.hex,r.style.fillOpacity=d.opacity),S&&(r.style.fill=S),w&&(r.style.stroke=w)}return r}function i(e){var t={};if(e.Point)if(e.Point.forEach){var r=[];e.Point.forEach(function(e){var t=[],n=e.coordinates.replace(/\t|\n/gi,"");if(""!==n.trim()){var a=n.split(",");t=[parseFloat(a[0]),parseFloat(a[1])]}r.push(t)}),t.type="MultiPoint",t.coordinates=r}else{var r=[],n=e.Point.coordinates.replace(/\t|\n/gi,"");if(""!==n.trim()){var a=n.split(",");r=[parseFloat(a[0]),parseFloat(a[1])]}t.type="Point",t.coordinates=r}else if(e.LineString)if(e.LineString.forEach){var r=[];e.LineString.forEach(function(e){var t=[],n=e.coordinates.trim();n.split(/\t|\n|\s/g).forEach(function(e){if(""!==e.trim()){var r=e.split(",");t.push([parseFloat(r[0]),parseFloat(r[1])])}}),r.push(t)}),t.type="MultiLineString",t.coordinates=r}else{var r=[],o=e.LineString.coordinates.trim();o.split(/\t|\n|\s/g).forEach(function(e){if(""!==e.trim()){var t=e.split(",");r.push([parseFloat(t[0]),parseFloat(t[1])])}}),t.type="LineString",t.coordinates=r}else if(e.Polygon)if(e.Polygon.forEach){var r=[];e.Polygon.forEach(function(e){var t=c(e);r.push(t)}),t.type="MultiPolygon",t.coordinates=r}else{var r=c(e.Polygon);t.type="Polygon",t.coordinates=r}else if(e.MultiGeometry){var s=e.MultiGeometry;if(Object.keys(s).length>1){var l=[];for(var p in s)if(s[p].forEach)s[p].forEach(function(e){var t={};t[p]=e,l.push(i(t))});else{var u={};u[p]=s[p],l.push(i(u))}t.type="GeometryCollection",t.geometries=l}else t=i(s)}return t}function s(e){var t=[],r=e.LinearRing.coordinates.trim();return r.split(/\t|\n|\s/g).forEach(function(e){if(""!==e.trim()){var r=e.split(",");t.push([parseFloat(r[0]),parseFloat(r[1])])}}),t}function c(e){var t=[];return["outerBoundaryIs","innerBoundaryIs"].forEach(function(r){var n=e[r];if(n){var a;n.forEach?n.forEach(function(e){a=s(e),t.push(a)}):(a=s(n),t.push(a))}}),t}function l(e){var t={};return"string"==typeof e&&8===e.length?(t.hex="#"+e.slice(6,8)+e.slice(4,6)+e.slice(2,4),t.opacity=Math.round(parseInt(e.slice(0,2),16)/255*100)/100):(t.hex="#000",t.opacity=1),t}function p(){var e={};return e["@xmlns"]="http://www.opengis.net/kml/2.2",e["@xmlns:gx"]="http://www.google.com/kml/ext/2.2",e["@xmlns:kml"]="http://www.opengis.net/kml/2.2",e["@xmlns:atom"]="http://www.w3.org/2005/Atom",e.Document={},e}function u(e,t,r){switch(e.type){case"Point":case"LineString":case"Polygon":var n=e.type;if(t[n]){var a=y(n,e.coordinates);t[n].push||(t[n]=[t[n]],t[n].sameName=!0),t[n].push(a)}else t[n]=y(n,e.coordinates);break;case"MultiPoint":case"MultiLineString":case"MultiPolygon":var n=e.type.replace("Multi","");t.MultiGeometry={},e.coordinates.forEach(function(e){u({type:n,coordinates:e},t.MultiGeometry)});break;case"GeometryCollection":t.MultiGeometry={},e.geometries.forEach(function(e){u(e,t.MultiGeometry)});break;case"Feature":var a={};u(e.geometry,a),e.properties.name&&(a.name=e.properties.name),e.properties.description&&(a.description=e.properties.description);var o=f(e,r);a.styleUrl=o,t.push(a);break;case"FeatureCollection":e.features.forEach(function(e){u(e,t,r)})}}function f(e,t){var r=Object.assign({},e.style),n=0;return t.forEach(function(e,t){var a=!1;for(var o in r)r[o]!==e[o]&&(a=!0);a||(n=t+1)}),0===n&&(t.push(r),n=t.length),"custom"+n}function y(e,t){var r={};switch(e){case"Point":r={},r.coordinates=t.join();break;case"LineString":r={},r.tessellate=1,r.coordinates=t.join(" ");break;case"Polygon":r={},r.tessellate=1,r.outerBoundaryIs={},r.outerBoundaryIs.LinearRing={},r.outerBoundaryIs.LinearRing.coordinates=t[0].join(" "),t.shift(),t.forEach(function(e){r.innerBoundaryIs={},r.innerBoundaryIs.LinearRing={},r.innerBoundaryIs.LinearRing.coordinates=e.join(" ")})}return r}function v(e){var t={};t.stroke="outline",t.fill="fill";var r=e.map(function(e,t){var r={};r["@id"]="custom"+(t+1);for(var n in e){switch(n){case"iconUrl":case"iconAnchor":case"scale":r.IconStyle||(r.IconStyle={});break;case"color":case"weight":r.LineStyle||(r.LineStyle={});break;case"stroke":case"fill":case"fillColor":r.PolyStyle||(r.PolyStyle={})}switch(n){case"iconUrl":r.IconStyle.Icon={},r.IconStyle.Icon.href=e.iconUrl;break;case"iconAnchor":r.IconStyle.hotSpot={},r.IconStyle.hotSpot["@x"]=e.iconAnchor[0],r.IconStyle.hotSpot["@y"]=e.iconAnchor[1],r.IconStyle.hotSpot["@xunits"]="pixels",r.IconStyle.hotSpot["@yunits"]="pixels";break;case"scale":r.IconStyle.scale=e.scale;break;case"color":r.LineStyle.color=h(e.color,e.opacity);break;case"weight":r.LineStyle.width=e.weight;break;case"stroke":r.PolyStyle.outline=e.stroke;case"fill":r.PolyStyle.fill=e.fill;break;case"fillColor":r.PolyStyle.color=h(e.fillColor,e.fillOpacity)}}return r});return r.sameName=!0,r}function h(e,t){e=e.replace("#",""),t=t?t:1;var r=parseInt(255*t).toString(16),n=r+e.slice(4,6)+e.slice(2,4)+e.slice(0,2);return n}GeoConvert.kml2Geojson=function(e,t){var r;if("string"==typeof e)if(e.indexOf("kml:")!==-1){var a=e.replace(/\kml:/gi,"");r=GeoConvert.xml2Json(a)}else r=GeoConvert.xml2Json(e);else{if("object"!=typeof e||!e.xmlVersion)throw new Error("Unsupported input type");r=GeoConvert.xml2Json(e)}var o=GeoConvert.emptyGeojson(),i={};if(n("kml",r.kml,o,i),t){var s=JSON.stringify(o);return s}return o},GeoConvert.geojson2Kml=function(e,t){var r;r="string"==typeof e?JSON.parse(e):e;var n=p(),a=[],o=[];a.sameName=!0,"Feature"!==r.type&&"FeatureCollection"!==r.type&&(r={type:"Feature",geometry:r,properties:{}}),u(r,a,o),n.Document.Style=v(o),n.Document.Placemark=a;var i=GeoConvert.json2Xml(n,"kml");if(t){var s=""+(new XMLSerializer).serializeToString(i);return s}return i}}(window,document),function(e,t,r){GeoConvert.kmz2Geojsons=function(e,t){function r(){if(n--,0===n){var e=[];o.forEach(function(t){var r=GeoConvert.kml2Geojson(t);r.features.forEach(function(e){e.style&&e.style.iconUrl&&i[e.style.iconUrl]&&(e.style.iconUrl=i[e.style.iconUrl])}),e.push(r)}),t&&t(e)}}if(JSZip){var n=0,a=new JSZip,o=[],i={};a.loadAsync(e).then(function(e){Object.keys(a.files).forEach(function(t){n++;var s=a.file(t).name.split(".").pop();"kml"===s?e.file(t).async("string").then(function(e){o.push(e),r()},function(e){n--}):"png"===s||"jpg"===s?e.file(t).async("base64").then(function(e){var n="data:image/"+s+";base64,";i[t]=n+e,r()},function(e){n--}):n--})})}}}(window,document),function(e,t,r){function n(e,t,r){if("gpx"===e)for(var s in t)n(s,t[s],r);else{var c;switch(e){case"wpt":c=a;break;case"trk":c=o;break;case"rte":c=i}c&&(t.forEach?t.forEach(function(e){r.features.push(c(e))}):r.features.push(c(t)))}}function a(e){var t={};t.type="Feature",t.properties={},t.properties.name=e.name,t.properties.cmt=e.cmt,t.properties.desc=e.desc,t.properties.time=e.time,t.geometry={},t.geometry.type="Point";var r=[e["@lon"],e["@lat"]];return t.geometry.coordinates=r,t}function o(e){var t={};t.type="Feature",t.properties={},t.properties.name=e.name,t.geometry={};var r;if(e.trkseg&&e.trkseg.trkpt){var n=e.trkseg.trkpt;n.forEach?(t.geometry.type="LineString",r=[],n.forEach(function(e){var t=[e["@lon"],e["@lat"]];r.push(t)})):(t.geometry.type="Point",r=[n["@lon"],n["@lat"]])}return t.geometry.coordinates=r,t}function i(e){var t={};t.type="Feature",t.properties={},t.properties.name=e.name,t.geometry={};var r;if(e.rtept){var n=e.rtept;n.forEach?(t.geometry.type="LineString",r=[],n.forEach(function(e){var t=[e["@lon"],e["@lat"]];r.push(t)})):(t.geometry.type="Point",r=[n["@lon"],n["@lat"]])}return t.geometry.coordinates=r,t}function s(){var e={};return e["@xmlns"]="http://www.topografix.com/GPX/1/1",e["@version"]="1.1",e["@creator"]="GeoConvert",e.metadata={},e.metadata.name="Geojson to GPX",e}function c(e,t,r,n){switch(e.type){case"Point":var a=l(e.coordinates);a.name=n.name?n.name:"",t.push(a);break;case"LineString":var o=p(e.coordinates);o.name=n.name?n.name:"",r.push(o);break;case"MultiPoint":case"MultiLineString":var i=e.type.replace("Multi","");e.coordinates.forEach(function(e){c({type:i,coordinates:e},t,r,n)});break;case"GeometryCollection":e.geometries.forEach(function(e){c(e,t,r,n)});break;case"Feature":c(e.geometry,t,r,e.properties);break;case"FeatureCollection":e.features.forEach(function(e){c(e,t,r)})}}function l(e){var t={};return t["@lon"]=e[0],t["@lat"]=e[1],t}function p(e){var t={};return t.rtept=[],t.rtept.sameName=!0,e.forEach(function(e){var r={};r["@lon"]=e[0],r["@lat"]=e[1],t.rtept.push(r)}),t}GeoConvert.gpx2Geojson=function(e,t){var r;if("string"==typeof e)r=GeoConvert.xml2Json(e);else{if("object"!=typeof e||!e.xmlVersion)throw new Error("Unsupported input type");r=GeoConvert.xml2Json(e)}var a=GeoConvert.emptyGeojson();if(n("gpx",r.gpx,a),t){var o=JSON.stringify(a);return o}return a},GeoConvert.geojson2Gpx=function(e,t){var r;r="string"==typeof e?JSON.parse(e):e;var n=s(),a=[],o=[];a.sameName=!0,o.sameName=!0,"Feature"!==r.type&&"FeatureCollection"!==r.type&&(r={type:"Feature",geometry:r,properties:{}}),c(r,a,o),n.wpt=a,n.rte=o;var i=GeoConvert.json2Xml(n,"gpx");if(t){var l=""+(new XMLSerializer).serializeToString(i);return l}return i}}(window,document),function(e,t,r){function n(e){if(e.shp&&e.dbf){var t=GeoConvert.emptyGeojson(),r=e.prj,n=e.encoding;return o(e.shp,t,r),f(e.dbf,t,n),t}throw new Error("need complete shapefile")}function a(e,t){this.fromProjection=e,this.toProjection=t}function o(e,t,r){var n=new DataView(e),o=n.byteLength,c=(n.getInt32(24),n.getInt32(32,!0),n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0),r&&!/GCS_WGS_1984|WGS84/g.test(r)?new a(r,proj4.WGS84):c);t.bbox=s(n,36,c);for(var l=100;l=0?u.push(p):u[u.length-1]=u[u.length-1].concat(p),l=[],p=[],v=0,[f,y]=[null,null])}return n.box=a,n.numPoints=i,1===o?(n.type="Polygon",n.coordinates=u[0]):(n.type="MultiPolygon",n.coordinates=u),n}function f(e,t,r){var n,a=new DataView(e),o=(a.byteLength,a.getInt8(0)),i=a.getInt32(4,!0),s=a.getInt16(8,!0),c=a.getInt16(10,!0),l=r||a.getInt8(29);switch(l){case 79:case"0x4F":n=GeoConvert.decode.big5;break;default:n=GeoConvert.decode.utf8}if(3!==o)throw new Error("File has unknown/unsupported dBase version:"+o);for(var p=32,u=[];13!==a.getUint8(p);){var f={};f.name=n.decode(e.slice(p,p+10)).replace(/\u0000/g,""),f.type=y[n.decode(e.slice(p+11,p+12))],f.fieldLength=a.getUint8(p+16),f.decimals=a.getUint8(p+17),u.push(f),p+=32}for(var v=u.length,h=0;hu.length){var f=i(e,p,10,20),y=u[u.length-1];(y===r||y.x!==f.x&&y.y!==f.y)&&u.push(f)}}break;case"LWPOLYLINE":c.vertices=c.vertices||[],c.vertices.push(i(e,p,10,20));break;case"POINT":case"MTEXT":case"XLINE":c.point=i(e,p,10,20,30);break;case"TEXT":case"LINE":c.startPoint=i(e,p,10,20,30)}break;case"11":var p=t+1;switch(o){case"HATCH":if(l){var u=c.multiVertices[c.multiVertices.length-1];u.push(i(e,p,11,21))}l=!1;break;case"TEXT":case"LINE":c.endPoint=i(e,p,10,20,30)}break;case"39":case"48":case"50":case"51":c[b[n]]=parseFloat(a);break;case"40":switch(o){case"TEXT":c.textHeight=parseFloat(a);break;case"ARC":case"CIRCLE":c.radius=parseFloat(a)}break;case"60":case"62":case"70":c[b[n]]=parseInt(a);break;case"72":"1"!==a&&"0"!==a||(l=!0);break;case"91":c.multiVertices=[];break;case"93":c.verticesNumber=parseInt(a),c.multiVertices.push([]);break;case"330":c.ownerHandle=a}t+=2}return c}function y(e){for(var t=e.length,r=0,n=[];r=10&&e<=59?parseFloat(t):e>=60&&e<=99?parseInt(t):e>=100&&e<=109?t:e>=110&&e<=149?parseFloat(t):e>=160&&e<=179?parseInt(t):e>=210&&e<=239?parseFloat(t):e>=270&&e<=289?parseInt(t):e>=290&&e<=299?!!parseInt(t):e>=300&&e<=369?t:e>=370&&e<=389?parseInt(t):e>=390&&e<=399?t:e>=400&&e<=409?parseInt(t):e>=410&&e<=419?t:e>=420&&e<=429?parseInt(t):e>=430&&e<=439?t:e>=440&&e<=459?parseInt(t):e>=460&&e<=469?parseFloat(t):e>=470&&e<=481?t:999===e?t:e>=1e3&&e<=1009?t:e>=1010&&e<=1059?parseFloat(t):e>=1060&&e<=1071?parseInt(t):t}function h(e,t){var e=t?t.trans([e.x,e.y]):[e.x,e.y];return e}function m(e,t){var n=[];if(e===r);return e.forEach(function(e){n.push(h(e,t))}),n}function g(e,t){var n={};switch(e.entityType){case"ARC":break;case"CIRCLE":break;case"INSERT":break;case"TEXT":n.type="Point",n.coordinates=h(e.startPoint,t);break;case"LINE":n.type="LineString",n.coordinates=m([e.startPoint,e.endPoint],t);break;case"LWPOLYLINE":n.type="LineString",n.coordinates=m(e.vertices,t),1===e.closed&&n.coordinates.push(n.coordinates[0]);break;case"HATCH":n.type="Polygon",n.coordinates=[],e.multiVertices.forEach(function(e){var r=m(e,t);r.push(r[0]),n.coordinates.push(r)})}if(n.type!==r){var a={};return a.type="Feature",a.geometry=n,a.properties={},a.style={},["text","textHeight","textStyleName","layerName","entityType"].forEach(function(t){e[t]!==r&&(a.properties[t]=e[t])}),a}}function d(e,t){var n=GeoConvert.emptyGeojson();for(var a in e.blocks){var o=e.blocks[a],i=o.entities;i!==r&&i.forEach(function(e){var a=g(e,t);a!==r&&n.features.push(a)})}return e.entities.forEach(function(e){var a=g(e,t);a!==r&&n.features.push(a)}),n}var b={1:"text",2:"name",5:"handle",6:"linetypeName",7:"textStyleName",8:"layerName",10:"lowerLeftCorner",11:"upperRightCorner",12:"centerDcs",13:"snapBasePoint",14:"snapSpacing",15:"gridSpacing",16:"viewDirectionFromTarget",17:"viewTarget",39:"thickness",48:"linetypeScale",50:"textRotation",51:"textOblique",60:"visibility",62:"colorNumber",70:"closed"};GeoConvert.dxf2Geojson=function(e,t){var r=a(e);if(t){var n=JSON.stringify(r);return n}return r},n.prototype.trans=function(e){return proj4(this.fromProjection,this.toProjection,e)}}(window,document),function(e,t,r){function n(e){if("string"==typeof e){var t=GeoConvert.emptyGeojson();e=e.trim();var r,n=e.split("(").shift().trim();switch(n){case"POINT":r=o;break;case"LINESTRING":r=i;break;case"POLYGON":r=s}if(r){var a={},c=r(e);a.type="Feature",a.properties={},a.geometry=c,t.features.push(a)}return t}throw new Error("need wkt")}function a(e){var t=e.trim().split(" ");return[parseFloat(t[0]),parseFloat(t[1])]}function o(e){var t={},r=e.indexOf("("),n=e.lastIndexOf(")"),o=e.slice(r+1,n);return t.type="Point",t.coordinates=a(o),t}function i(e){var t={},r=e.indexOf("("),n=e.lastIndexOf(")"),o=e.slice(r+1,n);return t.type="LineString",t.coordinates=o.split(",").map(a),t}function s(e){var t={},r=e.indexOf("("),n=e.lastIndexOf(")"),a=e.slice(r+1,n);return t.type="Polygon",t.coordinates=a.split("),").map(function(e){return e=e.indexOf(")")!==-1?e:e+")",i(e).coordinates}),t}GeoConvert.wkt2Geojson=function(e,t){var r=n(e);if(t){var a=JSON.stringify(r);return a}return r}}(window,document); -------------------------------------------------------------------------------- /lib/proj4.js: -------------------------------------------------------------------------------- 1 | !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.proj4=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 proj4(a,b,c){a=e(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)}},g&&(f.oProj=b),f)}var f=a("./Proj"),g=a("./transform"),h=f("WGS84");b.exports=proj4},{"./Proj":2,"./transform":65}],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){return this instanceof m?(this.datum_type=h,void(a&&(a.datumCode&&"none"===a.datumCode&&(this.datum_type=i),a.datum_params&&(this.datum_params=a.datum_params.map(parseFloat),(0!==this.datum_params[0]||0!==this.datum_params[1]||0!==this.datum_params[2])&&(this.datum_type=e),this.datum_params.length>3&&(0!==this.datum_params[3]||0!==this.datum_params[4]||0!==this.datum_params[5]||0!==this.datum_params[6])&&(this.datum_type=f,this.datum_params[3]*=j,this.datum_params[4]*=j,this.datum_params[5]*=j,this.datum_params[6]=this.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_type===g&&(this.grids=a.grids)))):new m(a)};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":66}],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}],48:[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}],49:[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}],50:[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}],51:[function(a,b,c){function d(a){return a}c.init=function(){},c.forward=d,c.inverse=d,c.names=["longlat","identity"]},{}],52:[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}],53:[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}],54:[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}],55:[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"]},{}],56:[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}],59:[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"]},{}],60:[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}],61:[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}],62:[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"), 3 | a.UNIT.convert&&("GEOGCS"===a.type?a.DATUM&&a.DATUM.SPHEROID&&(a.to_meter=parseFloat(a.UNIT.convert,10)*a.DATUM.SPHEROID.a):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}],67:[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="00000"+a.easting,d="00000"+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.lat&&b.lon?[b.lon,b.lat,b.lon,b.lat]:[b.left,b.bottom,b.right,b.top]},c.toPoint=function(a){var b=g(m(a.toUpperCase()));return b.lat&&b.lon?[b.lon,b.lat]:[(b.left+b.right)/2,(b.top+b.bottom)/2]}},{}],68:[function(a,b,c){b.exports={name:"proj4",version:"2.3.14",description:"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",main:"lib/index.js",directories:{test:"test",doc:"docs"},scripts:{test:"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},repository:{type:"git",url:"git://github.com/proj4js/proj4js.git"},author:"",license:"MIT",jam:{main:"dist/proj4.js",include:["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},devDependencies:{"grunt-cli":"~0.1.13",grunt:"~0.4.2","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0",chai:"~1.8.1",mocha:"~1.17.1","grunt-mocha-phantomjs":"~0.4.0",browserify:"~12.0.1","grunt-browserify":"~4.0.1","grunt-contrib-uglify":"~0.11.1",curl:"git://github.com/cujojs/curl.git",istanbul:"~0.2.4",tin:"~0.4.0"},dependencies:{mgrs:"~0.0.2"}}},{}],"./includedProjections":[function(a,b,c){b.exports=a("hTEDpn")},{}],hTEDpn:[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")];b.exports=function(proj4){d.forEach(function(a){proj4.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/gnom":47,"./lib/projections/krovak":48,"./lib/projections/laea":49,"./lib/projections/lcc":50,"./lib/projections/mill":53,"./lib/projections/moll":54,"./lib/projections/nzmg":55,"./lib/projections/omerc":56,"./lib/projections/poly":57,"./lib/projections/sinu":58,"./lib/projections/somerc":59,"./lib/projections/stere":60,"./lib/projections/sterea":61,"./lib/projections/tmerc":62,"./lib/projections/utm":63,"./lib/projections/vandg":64}]},{},[36])(36)}); --------------------------------------------------------------------------------