diff --git a/docs/users.rst b/docs/users.rst index 5e02f77bad..eee8a410ae 100644 --- a/docs/users.rst +++ b/docs/users.rst @@ -23,7 +23,7 @@ list of libraries used by GeoJS. +---------------------------+------------+---------------------------+ | Library | Version | Component | +===========================+============+===========================+ - | `proj4`_ | 2.3 | Core | + | `proj4`_ | 2.4 | Core | +---------------------------+------------+---------------------------+ | `GL matrix`_ | 2.1 | Core, GL renderer | +---------------------------+------------+---------------------------+ diff --git a/package-lock.json b/package-lock.json index 65114b8c9f..f8eae414a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -249,7 +249,7 @@ "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", "dev": true, "requires": { - "mime-types": "2.1.18", + "mime-types": "2.1.19", "negotiator": "0.6.1" } }, @@ -723,7 +723,7 @@ "dev": true, "requires": { "browserslist": "1.7.7", - "caniuse-db": "1.0.30000865", + "caniuse-db": "1.0.30000870", "normalize-range": "0.1.2", "num2fraction": "1.2.2", "postcss": "5.2.18", @@ -2078,7 +2078,7 @@ "integrity": "sha1-C9dnBCWL6CmyOYu1Dkti0aFmsLk=", "dev": true, "requires": { - "caniuse-db": "1.0.30000865", + "caniuse-db": "1.0.30000870", "electron-to-chromium": "1.3.52" } }, @@ -2192,12 +2192,12 @@ } }, "cache-content-type": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.0.tgz", - "integrity": "sha512-cVbmz0rAnsK3jPcQAlK4IDUUPaYAe4yl7MAfiKftHAcrW/azF1yikn2wE/8VAcC3yWtXi3lvXwsF1akK27Vo7w==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", + "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", "dev": true, "requires": { - "mime-types": "2.1.18", + "mime-types": "2.1.19", "ylru": "1.2.1" } }, @@ -2328,15 +2328,15 @@ "dev": true, "requires": { "browserslist": "1.7.7", - "caniuse-db": "1.0.30000865", + "caniuse-db": "1.0.30000870", "lodash.memoize": "4.1.2", "lodash.uniq": "4.5.0" } }, "caniuse-db": { - "version": "1.0.30000865", - "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000865.tgz", - "integrity": "sha1-gv+2TUD3VnYgqsAtOmMgeWiavGs=", + "version": "1.0.30000870", + "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000870.tgz", + "integrity": "sha1-85fNZJIsJPhdDOeAPJvVxaFXGxY=", "dev": true }, "canvas-prebuilt": { @@ -2692,9 +2692,9 @@ } }, "codemirror": { - "version": "5.39.0", - "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.39.0.tgz", - "integrity": "sha512-vpJRray/0ZCt9FiS7UcVr1JAm6OBdUt6TA/94Q7MScr8TnutVdQWh/WPr0migzaBPQmYvY7I9UZNvbsaLESIuQ==", + "version": "5.39.2", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.39.2.tgz", + "integrity": "sha512-mchBy0kQ1Wggi+e58SmoLgKO4nG7s/BqNg6/6TRbhsnXI/KRG+fKAvRQ1LLhZZ6ZtUoDQ0dl5aMhE+IkSRh60Q==", "dev": true }, "collection-visit": { @@ -3667,7 +3667,7 @@ "requires": { "custom-event": "1.0.1", "ent": "2.2.0", - "extend": "3.0.1", + "extend": "3.0.2", "void-elements": "2.0.1" } }, @@ -4518,9 +4518,9 @@ } }, "extend": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", - "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", "dev": true }, "extend-shallow": { @@ -5265,7 +5265,7 @@ "requires": { "asynckit": "0.4.0", "combined-stream": "1.0.6", - "mime-types": "2.1.18" + "mime-types": "2.1.19" } }, "formatio": { @@ -6008,7 +6008,7 @@ "requires": { "data-uri-to-buffer": "1.2.0", "debug": "2.6.9", - "extend": "3.0.1", + "extend": "3.0.2", "file-uri-to-path": "1.0.0", "ftp": "0.3.10", "readable-stream": "2.3.6" @@ -7568,9 +7568,9 @@ "dev": true }, "js-base64": { - "version": "2.4.6", - "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.6.tgz", - "integrity": "sha512-O9SR2NVICx6rCqh1qsU91QZ5IoNa+2T1ROJ0OQlfvATKGmnjsAvg3r0E5ufPZ4a95jdKTPXhFWiE/sOZ7a5Rtg==", + "version": "2.4.8", + "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.8.tgz", + "integrity": "sha512-hm2nYpDrwoO/OzBhdcqs/XGT6XjSuSSCVEpia+Kl2J6x4CYt5hISlVL/AYU1khoDXv0AQVgxtdJySb9gjAn56Q==", "dev": true }, "js-stringify": { @@ -7592,13 +7592,13 @@ "dev": true, "requires": { "argparse": "1.0.10", - "esprima": "4.0.0" + "esprima": "4.0.1" }, "dependencies": { "esprima": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true } } @@ -7814,13 +7814,13 @@ "integrity": "sha1-aewwzkUYvtWZezjwJ2SOjChekvc=", "dev": true, "requires": { - "markdown-it": "8.4.1" + "markdown-it": "8.4.2" } }, "karma": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/karma/-/karma-2.0.4.tgz", - "integrity": "sha512-32yhTwoi6BZgJZhR78GwhzyFABbYG/1WwQqYgY7Vh96Demvua2jM3+FyRltIMTUH/Kd5xaQvDw2L7jTvkYFeXg==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/karma/-/karma-2.0.5.tgz", + "integrity": "sha512-rECezBeY7mjzGUWhFlB7CvPHgkHJLXyUmWg+6vHCEsdWNUTnmiS6jRrIMcJEWgU2DUGZzGWG0bTRVky8fsDTOA==", "dev": true, "requires": { "bluebird": "3.5.1", @@ -8442,7 +8442,7 @@ "dev": true, "requires": { "accepts": "1.3.5", - "cache-content-type": "1.0.0", + "cache-content-type": "1.0.1", "content-disposition": "0.5.2", "content-type": "1.0.4", "cookies": "0.7.1", @@ -8653,7 +8653,7 @@ "log-update": "1.0.2", "ora": "0.2.3", "p-map": "1.2.0", - "rxjs": "6.2.1", + "rxjs": "6.2.2", "strip-ansi": "3.0.1" }, "dependencies": { @@ -8667,9 +8667,9 @@ } }, "rxjs": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.1.tgz", - "integrity": "sha512-OwMxHxmnmHTUpgO+V7dZChf3Tixf4ih95cmXjzzadULziVl/FKhHScGLj4goEw9weePVOH2Q0+GcCBUhKCZc/g==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.2.tgz", + "integrity": "sha512-0MI8+mkKAXZUF9vMrEoPnaoHkfzBPP4IGwUYRJhIRJF6/w3uByO1e91bEHn8zd43RdkTMKiooYKmwz7RH6zfOQ==", "dev": true, "requires": { "tslib": "1.9.3" @@ -8948,7 +8948,7 @@ "requires": { "asynckit": "0.4.0", "combined-stream": "1.0.6", - "mime-types": "2.1.18" + "mime-types": "2.1.19" } }, "har-validator": { @@ -9002,7 +9002,7 @@ "bl": "1.1.2", "caseless": "0.11.0", "combined-stream": "1.0.6", - "extend": "3.0.1", + "extend": "3.0.2", "forever-agent": "0.6.1", "form-data": "2.0.0", "har-validator": "2.0.6", @@ -9011,7 +9011,7 @@ "is-typedarray": "1.0.0", "isstream": "0.1.2", "json-stringify-safe": "5.0.1", - "mime-types": "2.1.18", + "mime-types": "2.1.19", "node-uuid": "1.4.8", "oauth-sign": "0.8.2", "qs": "6.2.3", @@ -9176,9 +9176,9 @@ } }, "markdown-it": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.1.tgz", - "integrity": "sha512-CzzqSSNkFRUf9vlWvhK1awpJreMRqdCrBvZ8DIoDWTOkESMIF741UPAhuAmbyWmdiFPA6WARNhnu2M6Nrhwa+A==", + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", "dev": true, "requires": { "argparse": "1.0.10", @@ -9385,9 +9385,9 @@ "dev": true }, "mgrs": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/mgrs/-/mgrs-0.0.3.tgz", - "integrity": "sha1-MFjTiukuGr+/dLMqj2y1IlpuqgU=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mgrs/-/mgrs-1.0.0.tgz", + "integrity": "sha1-+5FYjnjJACVnI5XLQLJffNatGCk=", "dev": true }, "micromatch": { @@ -9428,18 +9428,18 @@ "dev": true }, "mime-db": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", - "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==", + "version": "1.35.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.35.0.tgz", + "integrity": "sha512-JWT/IcCTsB0Io3AhWUMjRqucrHSPsSf2xKLaRldJVULioggvkJvggZ3VXNNSRkCddE6D+BUI4HEIZIA2OjwIvg==", "dev": true }, "mime-types": { - "version": "2.1.18", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", - "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", + "version": "2.1.19", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.19.tgz", + "integrity": "sha512-P1tKYHVSZ6uFo26mtnve4HQFE3koh1UWVkp8YUC+ESBHe945xWSoXuHHiGarDqcEZ+whpCDnlNw5LON0kLo+sw==", "dev": true, "requires": { - "mime-db": "1.33.0" + "mime-db": "1.35.0" } }, "mimic-fn": { @@ -9853,7 +9853,7 @@ "requires": { "asynckit": "0.4.0", "combined-stream": "1.0.6", - "mime-types": "2.1.18" + "mime-types": "2.1.19" } }, "har-schema": { @@ -9915,7 +9915,7 @@ "aws4": "1.7.0", "caseless": "0.12.0", "combined-stream": "1.0.6", - "extend": "3.0.1", + "extend": "3.0.2", "forever-agent": "0.6.1", "form-data": "2.1.4", "har-validator": "4.2.1", @@ -9924,7 +9924,7 @@ "is-typedarray": "1.0.0", "isstream": "0.1.2", "json-stringify-safe": "5.0.1", - "mime-types": "2.1.18", + "mime-types": "2.1.19", "oauth-sign": "0.8.2", "performance-now": "0.2.0", "qs": "6.4.0", @@ -10882,7 +10882,7 @@ "dev": true, "requires": { "chalk": "1.1.3", - "js-base64": "2.4.6", + "js-base64": "2.4.8", "source-map": "0.5.7", "supports-color": "3.2.3" }, @@ -11509,12 +11509,13 @@ "dev": true }, "proj4": { - "version": "2.3.16", - "resolved": "https://registry.npmjs.org/proj4/-/proj4-2.3.16.tgz", - "integrity": "sha1-5yflmUYH++5NI0FuxnL+TVDU51k=", + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/proj4/-/proj4-2.4.4.tgz", + "integrity": "sha512-yo6qTpBQXnxhcPopKJeVwwOBRzUpEa3vzSFlr38f5mF4Jnfb6NOL/ePIomefWiZmPgkUblHpcwnWVMB8FS3GKw==", "dev": true, "requires": { - "mgrs": "0.0.3" + "mgrs": "1.0.0", + "wkt-parser": "1.2.2" } }, "promise": { @@ -12072,15 +12073,15 @@ "dev": true, "requires": { "ast-types": "0.11.5", - "esprima": "4.0.0", + "esprima": "4.0.1", "private": "0.1.8", "source-map": "0.6.1" }, "dependencies": { "esprima": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, "source-map": { @@ -12308,7 +12309,7 @@ "aws4": "1.7.0", "caseless": "0.12.0", "combined-stream": "1.0.6", - "extend": "3.0.1", + "extend": "3.0.2", "forever-agent": "0.6.1", "form-data": "2.3.2", "har-validator": "5.0.3", @@ -12316,7 +12317,7 @@ "is-typedarray": "1.0.0", "isstream": "0.1.2", "json-stringify-safe": "5.0.1", - "mime-types": "2.1.18", + "mime-types": "2.1.19", "oauth-sign": "0.8.2", "performance-now": "2.1.0", "qs": "6.5.2", @@ -12342,7 +12343,7 @@ "dev": true, "optional": true, "requires": { - "extend": "3.0.1", + "extend": "3.0.2", "lodash": "4.17.10", "request": "2.87.0", "when": "3.7.8" @@ -12700,7 +12701,7 @@ "debug": "2.6.9", "escape-html": "1.0.3", "http-errors": "1.6.3", - "mime-types": "2.1.18", + "mime-types": "2.1.19", "parseurl": "1.3.2" } }, @@ -13992,7 +13993,7 @@ "dev": true, "requires": { "media-typer": "0.3.0", - "mime-types": "2.1.18" + "mime-types": "2.1.19" } }, "typedarray": { @@ -15214,9 +15215,9 @@ "dev": true }, "esprima": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, "jscodeshift": { @@ -15250,7 +15251,7 @@ "requires": { "ast-types": "0.10.1", "core-js": "2.5.7", - "esprima": "4.0.0", + "esprima": "4.0.1", "private": "0.1.8", "source-map": "0.6.1" } @@ -15293,7 +15294,7 @@ "v8-compile-cache": "2.0.0", "webpack-addons": "1.1.5", "yargs": "11.1.0", - "yeoman-environment": "2.3.0", + "yeoman-environment": "2.3.1", "yeoman-generator": "2.0.5" }, "dependencies": { @@ -16042,6 +16043,12 @@ "dev": true, "optional": true }, + "wkt-parser": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/wkt-parser/-/wkt-parser-1.2.2.tgz", + "integrity": "sha512-2aCAsY3VIKraNfMnAU2HYQyPQUnyeBvwXZofBXTR/Cev1vbL5Q4/Nw47JEFvkLtBm96RtK6fQbdPmc1kk8uhMw==", + "dev": true + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", @@ -16198,9 +16205,9 @@ "dev": true }, "yeoman-environment": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/yeoman-environment/-/yeoman-environment-2.3.0.tgz", - "integrity": "sha512-PHSAkVOqYdcR+C+Uht1SGC4eVD/9OhygYFkYaI66xF8vKIeS1RNYay+umj2ZrQeJ50tF5Q/RSO6qGDz9y3Ifug==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/yeoman-environment/-/yeoman-environment-2.3.1.tgz", + "integrity": "sha512-7BFbWNnJqG8f0TFR/awcccHj7Vl9CeG66Yuu81DiVIamqO7Uo/EOrdryjNICdRJNFdaQTliN4HUkM1zQBzszCQ==", "dev": true, "requires": { "chalk": "2.4.1", @@ -16440,7 +16447,7 @@ "shelljs": "0.8.2", "text-table": "0.2.0", "through2": "2.0.3", - "yeoman-environment": "2.3.0" + "yeoman-environment": "2.3.1" }, "dependencies": { "ansi-styles": { diff --git a/package.json b/package.json index cd2fa4365b..2ed3f2ebf7 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "nib": "^1.1.2", "pako": "^1.0.6", "phantomjs-prebuilt": "^2.1.5", - "proj4": "2.3.16", + "proj4": "^2.4.4", "pug": "^2.0.3", "pug-lint": "^2.4.0", "pug-loader": "^2.4.0", diff --git a/src/transform.js b/src/transform.js index 472cb9a11b..30a5d5e330 100644 --- a/src/transform.js +++ b/src/transform.js @@ -1,9 +1,10 @@ var proj4 = require('proj4'); -/* These projections exist in proj4 but aren't included by default. */ -proj4.Proj.projections.add(require('proj4/projections/equi')); -proj4.Proj.projections.add(require('proj4/projections/gauss')); -proj4.Proj.projections.add(require('proj4/projections/gstmerc')); -proj4.Proj.projections.add(require('proj4/projections/ortho')); +proj4 = proj4.__esModule ? proj4.default : proj4; +/* Ensure all projections in proj4 are included. */ +var projections = require.context('proj4/projections', true, /.*\.js$/); +projections.keys().forEach(function (key) { + proj4.Proj.projections.add(projections(key)); +}); var util = require('./util'); /** @@ -254,7 +255,7 @@ transform.transformCoordinates = function ( var trans = transform({source: srcPrj, target: tgtPrj}), output; if (util.isObject(coordinates) && 'x' in coordinates && 'y' in coordinates) { - output = trans.forward({x: coordinates.x, y: coordinates.y, z: coordinates.z || 0}); + output = trans.forward({x: +coordinates.x, y: +coordinates.y, z: +coordinates.z || 0}); if ('z' in coordinates) { return output; } @@ -263,7 +264,7 @@ transform.transformCoordinates = function ( if (Array.isArray(coordinates) && coordinates.length === 1 && util.isObject(coordinates[0]) && 'x' in coordinates[0] && 'y' in coordinates[0]) { - output = trans.forward({x: coordinates[0].x, y: coordinates[0].y, z: coordinates[0].z || 0}); + output = trans.forward({x: +coordinates[0].x, y: +coordinates[0].y, z: +coordinates[0].z || 0}); if ('z' in coordinates[0]) { return [output]; } @@ -298,23 +299,23 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp if (Array.isArray(coordinates[0])) { if (coordinates[0].length === 2) { xAcc = function (index) { - return coordinates[index][0]; + return +coordinates[index][0]; }; yAcc = function (index) { - return coordinates[index][1]; + return +coordinates[index][1]; }; writer = function (index, x, y) { output[index] = [x, y]; }; } else if (coordinates[0].length === 3) { xAcc = function (index) { - return coordinates[index][0]; + return +coordinates[index][0]; }; yAcc = function (index) { - return coordinates[index][1]; + return +coordinates[index][1]; }; zAcc = function (index) { - return coordinates[index][2]; + return +coordinates[index][2]; }; writer = function (index, x, y, z) { output[index] = [x, y, z]; @@ -327,10 +328,10 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp offset = 2; xAcc = function (index) { - return coordinates[index * offset]; + return +coordinates[index * offset]; }; yAcc = function (index) { - return coordinates[index * offset + 1]; + return +coordinates[index * offset + 1]; }; writer = function (index, x, y) { output[index] = x; @@ -340,13 +341,13 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp offset = 3; xAcc = function (index) { - return coordinates[index * offset]; + return +coordinates[index * offset]; }; yAcc = function (index) { - return coordinates[index * offset + 1]; + return +coordinates[index * offset + 1]; }; zAcc = function (index) { - return coordinates[index * offset + 2]; + return +coordinates[index * offset + 2]; }; writer = function (index, x, y, z) { output[index] = x; @@ -358,10 +359,10 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp offset = numberOfComponents; xAcc = function (index) { - return coordinates[index]; + return +coordinates[index]; }; yAcc = function (index) { - return coordinates[index + 1]; + return +coordinates[index + 1]; }; if (numberOfComponents === 2) { writer = function (index, x, y) { @@ -370,7 +371,7 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp }; } else { zAcc = function (index) { - return coordinates[index + 2]; + return +coordinates[index + 2]; }; writer = function (index, x, y, z) { output[index] = x; @@ -393,15 +394,15 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp 'x' in coordinates[0] && 'y' in coordinates[0]) { xAcc = function (index) { - return coordinates[index].x; + return +coordinates[index].x; }; yAcc = function (index) { - return coordinates[index].y; + return +coordinates[index].y; }; if ('z' in coordinates[0]) { zAcc = function (index) { - return coordinates[index].z; + return +coordinates[index].z; }; writer = function (index, x, y, z) { output[i] = {x: x, y: y, z: z}; diff --git a/src/util/index.js b/src/util/index.js index ba39ca3e8a..4d7751051f 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -1,5 +1,6 @@ var $ = require('jquery'); var proj4 = require('proj4'); +proj4 = proj4.__esModule ? proj4.default : proj4; var throttle = require('./throttle'); var mockVGL = require('./mockVGL'); diff --git a/tests/cases/annotationLayer.js b/tests/cases/annotationLayer.js index 6e74cad68c..2cec9e4054 100644 --- a/tests/cases/annotationLayer.js +++ b/tests/cases/annotationLayer.js @@ -156,6 +156,15 @@ describe('geo.annotationLayer', function () { corners: [{x: 0, y: 0}, {x: 1, y: 0}, {x: 1, y: 1}, {x: 0, y: 1}]}); layer.addAnnotation(rect, map.gcs()); expect(layer.annotations()[1]._coordinates()[1]).toEqual({x: 1, y: 0}); + /* Change the map input gcs to the main gcs and the coordinates won't be + * altered. */ + map.ingcs(map.gcs()); + layer.removeAnnotation(rect); + rect = geo.annotation.rectangleAnnotation({ + layer: layer, + corners: [{x: 0, y: 0}, {x: 1, y: 0}, {x: 1, y: 1}, {x: 0, y: 1}]}); + layer.addAnnotation(rect); + expect(layer.annotations()[1]._coordinates()[1]).toEqual({x: 1, y: 0}); }); it('annotationById', function () { expect(layer.annotationById()).toBe(undefined); @@ -192,19 +201,6 @@ describe('geo.annotationLayer', function () { expect(removeAnnotationEvent).toBe(3); expect(layer.annotations().length).toBe(1); }); - it('displayDistance', function () { - var c1 = {x: 100, y: 80}, - c2 = map.displayToGcs({x: 105, y: 84}), /* ingcs */ - c3 = map.displayToGcs({x: 107, y: 88}, null); /* gcs */ - expect(layer.displayDistance(c1, 'display', c2)).toBeCloseTo(6.40, 2); - expect(layer.displayDistance(c1, 'display', c2, 'EPSG:4326')).toBeCloseTo(6.40, 2); - expect(layer.displayDistance(c1, 'display', c3, null)).toBeCloseTo(10.63, 2); - expect(layer.displayDistance(c1, 'display', c3, 'EPSG:3857')).toBeCloseTo(10.63, 2); - expect(layer.displayDistance(c2, undefined, c1, 'display')).toBeCloseTo(6.40, 2); - expect(layer.displayDistance(c2, undefined, c3, null)).toBeCloseTo(4.47, 2); - expect(layer.displayDistance(c3, null, c1, 'display')).toBeCloseTo(10.63, 2); - expect(layer.displayDistance(c3, null, c2)).toBeCloseTo(4.47, 2); - }); it('geojson', function () { layer.removeAllAnnotations(); layer.addAnnotation(poly); @@ -330,6 +326,20 @@ describe('geo.annotationLayer', function () { expect(layer.validateAttribute(0.5, 'text')).toBe('0.5'); expect(layer.validateAttribute('value', 'text')).toBe('value'); }); + it('displayDistance', function () { + map.ingcs('EPSG:4326'); + var c1 = {x: 100, y: 80}, + c2 = map.displayToGcs({x: 105, y: 84}), /* ingcs */ + c3 = map.displayToGcs({x: 107, y: 88}, null); /* gcs */ + expect(layer.displayDistance(c1, 'display', c2)).toBeCloseTo(6.40, 2); + expect(layer.displayDistance(c1, 'display', c2, 'EPSG:4326')).toBeCloseTo(6.40, 2); + expect(layer.displayDistance(c1, 'display', c3, null)).toBeCloseTo(10.63, 2); + expect(layer.displayDistance(c1, 'display', c3, 'EPSG:3857')).toBeCloseTo(10.63, 2); + expect(layer.displayDistance(c2, undefined, c1, 'display')).toBeCloseTo(6.40, 2); + expect(layer.displayDistance(c2, undefined, c3, null)).toBeCloseTo(4.47, 2); + expect(layer.displayDistance(c3, null, c1, 'display')).toBeCloseTo(10.63, 2); + expect(layer.displayDistance(c3, null, c2)).toBeCloseTo(4.47, 2); + }); }); describe('Private utility functions', function () { var map, layer, point, rect, rect2, editActionEvent = 0; diff --git a/tests/cases/transform.js b/tests/cases/transform.js index 9d9db63b03..3fc106e60a 100644 --- a/tests/cases/transform.js +++ b/tests/cases/transform.js @@ -236,6 +236,10 @@ describe('geo.transform', function () { expect(closeToEqual(geo.transform.transformCoordinates(source, target, {x: 1, y: 2}), {x: 1, y: -2})).toBe(true); expect(closeToEqual(geo.transform.transformCoordinates(source, target, {x: 3, y: 4, z: 5}), {x: 3, y: -4, z: 5})).toBe(true); }); + it('coordinate format - single object with strings', function () { + expect(closeToEqual(geo.transform.transformCoordinates(source, target, {x: '1', y: '2'}), {x: 1, y: -2})).toBe(true); + expect(closeToEqual(geo.transform.transformCoordinates(source, target, {x: '3', y: '4', z: '5'}), {x: 3, y: -4, z: 5})).toBe(true); + }); it('empty array', function () { var res = geo.transform.transformCoordinates(source, target, []); expect(res instanceof Array).toBe(true); @@ -247,16 +251,22 @@ describe('geo.transform', function () { expect(res instanceof Array).toBe(true); expect(res.length).toBe(1); expect(closeToEqual(res[0], {x: 1, y: -2})).toBe(true); + res = geo.transform.transformCoordinates(source, target, [{x: '1', y: '2'}]); + expect(closeToEqual(res[0], {x: 1, y: -2})).toBe(true); res = geo.transform.transformCoordinates(source, target, [{x: 3, y: 4, z: 5}]); expect(res instanceof Array).toBe(true); expect(res.length).toBe(1); expect(closeToEqual(res[0], {x: 3, y: -4, z: 5})).toBe(true); + res = geo.transform.transformCoordinates(source, target, [{x: '3', y: '4', z: '5'}]); + expect(closeToEqual(res[0], {x: 3, y: -4, z: 5})).toBe(true); }); it('coordinate format - single array', function () { expect(closeToArray(geo.transform.transformCoordinates(source, target, [1, 2]), [1, -2])).toBe(true); expect(closeToArray(geo.transform.transformCoordinates(source, target, [3, 4, 5]), [3, -4, 5])).toBe(true); expect(closeToArray(geo.transform.transformCoordinates(source, target, [1, 2, 3, 4, 5, 6], 2), [1, -2, 3, -4, 5, -6])).toBe(true); expect(closeToArray(geo.transform.transformCoordinates(source, target, [1, 2, 3, 4, 5, 6], 3), [1, -2, 3, 4, -5, 6])).toBe(true); + expect(closeToArray(geo.transform.transformCoordinates(source, target, ['1', '2']), [1, -2])).toBe(true); + expect(closeToArray(geo.transform.transformCoordinates(source, target, ['3', '4', '5']), [3, -4, 5])).toBe(true); }); it('coordinate format - array of arrays', function () { var res; @@ -265,10 +275,14 @@ describe('geo.transform', function () { expect(closeToArray(res[0], [1, -2])).toBe(true); expect(closeToArray(res[1], [3, -4])).toBe(true); expect(closeToArray(res[2], [5, -6])).toBe(true); + res = geo.transform.transformCoordinates(source, target, [['1', '2'], ['3', '4'], ['5', '6']]); + expect(closeToArray(res[0], [1, -2])).toBe(true); res = geo.transform.transformCoordinates(source, target, [[1, 2, 3], [4, 5, 6]]); expect(res.length).toBe(2); expect(closeToArray(res[0], [1, -2, 3])).toBe(true); expect(closeToArray(res[1], [4, -5, 6])).toBe(true); + res = geo.transform.transformCoordinates(source, target, [['1', '2', '3'], ['4', '5', '6']]); + expect(closeToArray(res[0], [1, -2, 3])).toBe(true); }); it('coordinate format - array of objects', function () { var res; @@ -277,10 +291,14 @@ describe('geo.transform', function () { expect(closeToEqual(res[0], {x: 1, y: -2})).toBe(true); expect(closeToEqual(res[1], {x: 3, y: -4})).toBe(true); expect(closeToEqual(res[2], {x: 5, y: -6})).toBe(true); + res = geo.transform.transformCoordinates(source, target, [{x: '1', y: '2'}, {x: '3', y: '4'}, {x: '5', y: '6'}]); + expect(closeToEqual(res[0], {x: 1, y: -2})).toBe(true); res = geo.transform.transformCoordinates(source, target, [{x: 1, y: 2, z: 3}, {x: 4, y: 5, z: 6}]); expect(res.length).toBe(2); expect(closeToEqual(res[0], {x: 1, y: -2, z: 3})).toBe(true); expect(closeToEqual(res[1], {x: 4, y: -5, z: 6})).toBe(true); + res = geo.transform.transformCoordinates(source, target, [{x: '1', y: '2', z: '3'}, {x: '4', y: '5', z: '6'}]); + expect(closeToEqual(res[0], {x: 1, y: -2, z: 3})).toBe(true); }); });