diff --git a/Gruntfile.js b/Gruntfile.js index 7dc2c7576..b2b880ab8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,9 @@ module.exports = function(grunt) { -const Diff = require('diff'); -const nodeResolve = require('@rollup/plugin-node-resolve'); -const loadLocalePlugin = require('./load-locales.js'); -grunt.initConfig({ + const Diff = require('diff'); + const nodeResolve = require('@rollup/plugin-node-resolve'); + const loadLocalePlugin = require('./load-locales.js'); + const alias = require('@rollup/plugin-alias'); + grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), cssmin: { options: { @@ -50,30 +51,6 @@ grunt.initConfig({ copy : { main : { files: [ - { - expand: true, - cwd: 'node_modules/leaflet/dist/', - flatten: true, - filter: 'isFile', - src: ['leaflet-src.js'], - dest: 'dist/' - }, - { - expand: true, - cwd: 'node_modules/proj4/dist/', - flatten: true, - filter: 'isFile', - src: ['proj4-src.js'], - dest: 'dist/' - }, - { - expand: true, - cwd: 'node_modules/proj4leaflet/src/', - flatten: true, - filter: 'isFile', - src: ['proj4leaflet.js'], - dest: 'dist/' - }, { expand: true, flatten: true, @@ -87,28 +64,12 @@ grunt.initConfig({ filter: 'isFile', src: ['src/pmtilesRules.js'], dest: 'dist/' - }, - { - expand: true, - cwd: 'node_modules/leaflet.locatecontrol/src/', - flatten: true, - filter: 'isFile', - src: ['L.Control.Locate.js'], - dest: 'dist/' } ], options: { process: function (content, srcpath) { // see patch.diff file for comments on why patching is necessary - if (srcpath.includes('proj4leaflet.js')) { - console.log('PATCHING: ', srcpath); - const patch = grunt.file.read('src/proj4leaflet/patch.diff'); - return Diff.applyPatch(content, patch); - } else if (srcpath.includes('proj4-src.js')) { - console.log('PATCHING: ', srcpath); - const patch = grunt.file.read('src/proj4/patch.diff'); - return Diff.applyPatch(content, patch); - } else if (srcpath.includes('index.html')) { + if (srcpath.includes('index.html')) { console.log('MODIFYING: ', srcpath); var pathToModuleRE = /dist\/mapml\.js/gi; return content.replace(pathToModuleRE,"./mapml.js"); @@ -173,7 +134,7 @@ grunt.initConfig({ }, clean: { dist: ['dist'], - tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js','dist/mapmlviewer.js'], + tidyup: ['dist/mapmlviewer.js'], experiments: { options: {force: true}, src: ['../experiments/dist'] @@ -192,17 +153,28 @@ grunt.initConfig({ } }, rollup: { - options: { - format: 'es', - plugins: [nodeResolve(),loadLocalePlugin()], - external: './pmtilesRules.js' - }, - main: { - dest: 'dist/mapmlviewer.js', - src: 'src/mapml/index.js' // Only one source file is permitted - } - }, - prettier: { + options: { + format: 'es', + plugins: [ + nodeResolve(), + loadLocalePlugin(), + alias({ + entries: [ + { + find: 'leaflet', + replacement: 'leaflet/dist/leaflet-src.esm.js' + } + ] + }) + ], + external: './pmtilesRules.js' + }, + main: { + dest: 'dist/mapmlviewer.js', + src: 'src/mapml/index.js' // Only one source file is permitted + } + }, + prettier: { options: { // https://prettier.io/docs/en/options.html progress: true diff --git a/package-lock.json b/package-lock.json index 63377b2e3..9dcae99f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ "license": "W3C", "devDependencies": { "@playwright/test": "^1.39.0", + "@rollup/plugin-alias": "^5.1.1", + "@rollup/plugin-legacy": "^3.0.2", "@rollup/plugin-node-resolve": "^15.2.3", "diff": "^5.1.0", "express": "^4.17.1", @@ -26,13 +28,13 @@ "grunt-prettier": "^2.2.0", "grunt-rollup": "^12.0.0", "leaflet": "^1.9.4", - "leaflet.locatecontrol": "^0.79.0", + "leaflet.locatecontrol": "^0.81.1", "mapml-extension": "git+https://github.com/Maps4HTML/mapml-extension", "path": "^0.12.7", "playwright": "^1.39.0", "proj4": "^2.6.2", - "proj4leaflet": "^1.0.2", - "protomaps-leaflet": "4.0.0", + "proj4leaflet": "git+https://github.com/Maps4HTML/proj4leaflet.git#es-module", + "protomaps-leaflet": "^4.0.1", "rollup": "^3.29.5", "serve-static": "^1.15.0" } @@ -53,28 +55,62 @@ } }, "node_modules/@playwright/test": { - "version": "1.39.0", + "version": "1.48.1", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright": "1.39.0" + "playwright": "1.48.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" + } + }, + "node_modules/@rollup/plugin-alias": { + "version": "5.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-legacy": { + "version": "3.0.2", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } } }, "node_modules/@rollup/plugin-node-resolve": { - "version": "15.2.3", + "version": "15.3.0", "dev": true, "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.0.1", "@types/resolve": "1.20.2", "deepmerge": "^4.2.2", - "is-builtin-module": "^3.2.1", "is-module": "^1.0.0", "resolve": "^1.22.1" }, @@ -91,13 +127,13 @@ } }, "node_modules/@rollup/pluginutils": { - "version": "5.1.0", + "version": "5.1.3", "dev": true, "license": "MIT", "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", - "picomatch": "^2.3.1" + "picomatch": "^4.0.2" }, "engines": { "node": ">=14.0.0" @@ -117,7 +153,7 @@ "license": "MIT" }, "node_modules/@types/estree": { - "version": "1.0.5", + "version": "1.0.6", "dev": true, "license": "MIT" }, @@ -127,7 +163,7 @@ "license": "MIT" }, "node_modules/@types/leaflet": { - "version": "1.9.12", + "version": "1.9.14", "dev": true, "license": "MIT", "dependencies": { @@ -165,14 +201,11 @@ } }, "node_modules/ansi-styles": { - "version": "3.2.1", + "version": "2.2.1", "dev": true, "license": "MIT", - "dependencies": { - "color-convert": "^1.9.0" - }, "engines": { - "node": ">=4" + "node": ">=0.10.0" } }, "node_modules/argparse": { @@ -183,11 +216,6 @@ "sprintf-js": "~1.0.2" } }, - "node_modules/argparse/node_modules/sprintf-js": { - "version": "1.0.3", - "dev": true, - "license": "BSD-3-Clause" - }, "node_modules/array-each": { "version": "1.0.1", "dev": true, @@ -210,12 +238,12 @@ } }, "node_modules/async": { - "version": "3.2.4", + "version": "3.2.6", "dev": true, "license": "MIT" }, "node_modules/balanced-match": { - "version": "1.0.0", + "version": "1.0.2", "dev": true, "license": "MIT" }, @@ -252,39 +280,20 @@ "npm": "1.2.8000 || >= 1.4.16" } }, - "node_modules/body-parser/node_modules/bytes": { - "version": "3.1.2", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/body-parser/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/body-parser/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" + "node_modules/body/node_modules/bytes": { + "version": "1.0.0", + "dev": true }, - "node_modules/body-parser/node_modules/raw-body": { - "version": "2.5.2", + "node_modules/body/node_modules/raw-body": { + "version": "1.1.7", "dev": true, "license": "MIT", "dependencies": { - "bytes": "3.1.2", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "unpipe": "1.0.0" + "bytes": "1", + "string_decoder": "0.10" }, "engines": { - "node": ">= 0.8" + "node": ">= 0.8.0" } }, "node_modules/brace-expansion": { @@ -307,21 +316,14 @@ "node": ">=8" } }, - "node_modules/builtin-modules": { - "version": "3.3.0", + "node_modules/bytes": { + "version": "3.1.2", "dev": true, "license": "MIT", "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">= 0.8" } }, - "node_modules/bytes": { - "version": "1.0.0", - "dev": true - }, "node_modules/call-bind": { "version": "1.0.7", "dev": true, @@ -341,20 +343,22 @@ } }, "node_modules/chalk": { - "version": "2.4.2", + "version": "1.1.3", "dev": true, "license": "MIT", "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" }, "engines": { - "node": ">=4" + "node": ">=0.10.0" } }, "node_modules/clean-css": { - "version": "5.3.2", + "version": "5.3.3", "dev": true, "license": "MIT", "dependencies": { @@ -385,15 +389,18 @@ } }, "node_modules/color-convert": { - "version": "1.9.3", + "version": "2.0.1", "dev": true, "license": "MIT", "dependencies": { - "color-name": "1.1.3" + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" } }, "node_modules/color-name": { - "version": "1.1.3", + "version": "1.1.4", "dev": true, "license": "MIT" }, @@ -433,25 +440,6 @@ "node": ">= 0.6" } }, - "node_modules/content-disposition/node_modules/safe-buffer": { - "version": "5.2.1", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/content-type": { "version": "1.0.5", "dev": true, @@ -465,7 +453,7 @@ "dev": true }, "node_modules/cookie": { - "version": "0.6.0", + "version": "0.7.1", "dev": true, "license": "MIT", "engines": { @@ -478,7 +466,7 @@ "license": "MIT" }, "node_modules/core-util-is": { - "version": "1.0.2", + "version": "1.0.3", "dev": true, "license": "MIT" }, @@ -487,7 +475,7 @@ "dev": true }, "node_modules/dateformat": { - "version": "3.0.3", + "version": "4.6.3", "dev": true, "license": "MIT", "engines": { @@ -495,11 +483,11 @@ } }, "node_modules/debug": { - "version": "3.2.7", + "version": "2.6.9", "dev": true, "license": "MIT", "dependencies": { - "ms": "^2.1.1" + "ms": "2.0.0" } }, "node_modules/deepmerge": { @@ -552,7 +540,7 @@ } }, "node_modules/diff": { - "version": "5.1.0", + "version": "5.2.0", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -569,7 +557,7 @@ } }, "node_modules/dom-serializer/node_modules/domelementtype": { - "version": "2.2.0", + "version": "2.3.0", "dev": true, "funding": [ { @@ -706,8 +694,19 @@ "node": ">= 0.8.0" } }, + "node_modules/expand-tilde": { + "version": "2.0.2", + "dev": true, + "license": "MIT", + "dependencies": { + "homedir-polyfill": "^1.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/express": { - "version": "4.21.0", + "version": "4.21.1", "dev": true, "license": "MIT", "dependencies": { @@ -716,7 +715,7 @@ "body-parser": "1.20.3", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.6.0", + "cookie": "0.7.1", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -747,38 +746,6 @@ "node": ">= 0.10.0" } }, - "node_modules/express/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/express/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" - }, - "node_modules/express/node_modules/safe-buffer": { - "version": "5.2.1", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/extend": { "version": "3.0.2", "dev": true, @@ -801,15 +768,17 @@ "license": "MIT" }, "node_modules/figures": { - "version": "1.7.0", + "version": "3.2.0", "dev": true, "license": "MIT", "dependencies": { - "escape-string-regexp": "^1.0.5", - "object-assign": "^4.1.0" + "escape-string-regexp": "^1.0.5" }, "engines": { - "node": ">=0.10.0" + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/file-sync-cmp": { @@ -845,42 +814,18 @@ "node": ">= 0.8" } }, - "node_modules/finalhandler/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/finalhandler/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" - }, "node_modules/findup-sync": { - "version": "0.3.0", - "dev": true, - "dependencies": { - "glob": "~5.0.0" - }, - "engines": { - "node": ">= 0.6.0" - } - }, - "node_modules/findup-sync/node_modules/glob": { - "version": "5.0.15", + "version": "5.0.0", "dev": true, - "license": "ISC", + "license": "MIT", "dependencies": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "detect-file": "^1.0.0", + "is-glob": "^4.0.3", + "micromatch": "^4.0.4", + "resolve-dir": "^1.0.1" }, "engines": { - "node": "*" + "node": ">= 10.13.0" } }, "node_modules/fined": { @@ -898,17 +843,6 @@ "node": ">= 0.10" } }, - "node_modules/fined/node_modules/expand-tilde": { - "version": "2.0.2", - "dev": true, - "license": "MIT", - "dependencies": { - "homedir-polyfill": "^1.0.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/flagged-respawn": { "version": "1.0.1", "dev": true, @@ -995,7 +929,7 @@ } }, "node_modules/getobject": { - "version": "1.0.0", + "version": "1.0.2", "dev": true, "engines": { "node": ">=10" @@ -1020,56 +954,93 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/globule": { - "version": "1.3.1", + "node_modules/global-modules": { + "version": "1.0.0", "dev": true, "license": "MIT", "dependencies": { - "glob": "~7.1.1", - "lodash": "~4.17.12", - "minimatch": "~3.0.2" + "global-prefix": "^1.0.1", + "is-windows": "^1.0.1", + "resolve-dir": "^1.0.0" }, "engines": { - "node": ">= 0.10" + "node": ">=0.10.0" } }, - "node_modules/gopd": { - "version": "1.0.1", + "node_modules/global-prefix": { + "version": "1.0.2", "dev": true, "license": "MIT", "dependencies": { - "get-intrinsic": "^1.1.3" + "expand-tilde": "^2.0.2", + "homedir-polyfill": "^1.0.1", + "ini": "^1.3.4", + "is-windows": "^1.0.1", + "which": "^1.2.14" }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "engines": { + "node": ">=0.10.0" } }, - "node_modules/grunt": { - "version": "1.5.3", + "node_modules/global-prefix/node_modules/which": { + "version": "1.3.1", "dev": true, - "license": "MIT", + "license": "ISC", "dependencies": { - "dateformat": "~3.0.3", + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, + "node_modules/globule": { + "version": "1.3.4", + "dev": true, + "license": "MIT", + "dependencies": { + "glob": "~7.1.1", + "lodash": "^4.17.21", + "minimatch": "~3.0.2" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/grunt": { + "version": "1.6.1", + "dev": true, + "license": "MIT", + "dependencies": { + "dateformat": "~4.6.2", "eventemitter2": "~0.4.13", "exit": "~0.1.2", - "findup-sync": "~0.3.0", + "findup-sync": "~5.0.0", "glob": "~7.1.6", "grunt-cli": "~1.4.3", "grunt-known-options": "~2.0.0", "grunt-legacy-log": "~3.0.0", "grunt-legacy-util": "~2.0.1", - "iconv-lite": "~0.4.13", + "iconv-lite": "~0.6.3", "js-yaml": "~3.14.0", "minimatch": "~3.0.4", - "mkdirp": "~1.0.4", - "nopt": "~3.0.6", - "rimraf": "~3.0.2" + "nopt": "~3.0.6" }, "bin": { "grunt": "bin/grunt" }, "engines": { - "node": ">=8" + "node": ">=16" } }, "node_modules/grunt-cli": { @@ -1103,28 +1074,20 @@ } }, "node_modules/grunt-contrib-clean": { - "version": "2.0.0", + "version": "2.0.1", "dev": true, "license": "MIT", "dependencies": { - "async": "^2.6.1", + "async": "^3.2.3", "rimraf": "^2.6.2" }, "engines": { - "node": ">=6" + "node": ">=12" }, "peerDependencies": { "grunt": ">=0.4.5" } }, - "node_modules/grunt-contrib-clean/node_modules/async": { - "version": "2.6.4", - "dev": true, - "license": "MIT", - "dependencies": { - "lodash": "^4.17.14" - } - }, "node_modules/grunt-contrib-concat": { "version": "1.0.1", "dev": true, @@ -1140,37 +1103,6 @@ "grunt": ">=0.4.0" } }, - "node_modules/grunt-contrib-concat/node_modules/ansi-styles": { - "version": "2.2.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/grunt-contrib-concat/node_modules/chalk": { - "version": "1.1.3", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/grunt-contrib-concat/node_modules/supports-color": { - "version": "2.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/grunt-contrib-copy": { "version": "1.0.0", "dev": true, @@ -1183,37 +1115,6 @@ "node": ">=0.10.0" } }, - "node_modules/grunt-contrib-copy/node_modules/ansi-styles": { - "version": "2.2.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/grunt-contrib-copy/node_modules/chalk": { - "version": "1.1.3", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/grunt-contrib-copy/node_modules/supports-color": { - "version": "2.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/grunt-contrib-cssmin": { "version": "4.0.0", "dev": true, @@ -1256,92 +1157,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/grunt-contrib-cssmin/node_modules/color-convert": { - "version": "2.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/color-name": { - "version": "1.1.4", - "dev": true, - "license": "MIT" - }, - "node_modules/grunt-contrib-cssmin/node_modules/figures": { - "version": "3.2.0", - "dev": true, - "license": "MIT", - "dependencies": { - "escape-string-regexp": "^1.0.5" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/gzip-size": { - "version": "5.1.1", - "dev": true, - "license": "MIT", - "dependencies": { - "duplexer": "^0.1.1", - "pify": "^4.0.1" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/has-flag": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/maxmin": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "chalk": "^4.1.0", - "figures": "^3.2.0", - "gzip-size": "^5.1.1", - "pretty-bytes": "^5.3.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/pify": { - "version": "4.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, - "node_modules/grunt-contrib-cssmin/node_modules/pretty-bytes": { - "version": "5.6.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/grunt-contrib-cssmin/node_modules/supports-color": { "version": "7.2.0", "dev": true, @@ -1395,30 +1210,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/grunt-contrib-jshint/node_modules/color-convert": { - "version": "2.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/grunt-contrib-jshint/node_modules/color-name": { - "version": "1.1.4", - "dev": true, - "license": "MIT" - }, - "node_modules/grunt-contrib-jshint/node_modules/has-flag": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/grunt-contrib-jshint/node_modules/supports-color": { "version": "7.2.0", "dev": true, @@ -1445,9 +1236,50 @@ } }, "node_modules/grunt-contrib-uglify/node_modules/ansi-styles": { - "version": "2.2.1", + "version": "3.2.1", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/grunt-contrib-uglify/node_modules/chalk": { + "version": "2.4.2", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/grunt-contrib-uglify/node_modules/color-convert": { + "version": "1.9.3", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/grunt-contrib-uglify/node_modules/color-name": { + "version": "1.1.3", + "dev": true, + "license": "MIT" + }, + "node_modules/grunt-contrib-uglify/node_modules/figures": { + "version": "1.7.0", "dev": true, "license": "MIT", + "dependencies": { + "escape-string-regexp": "^1.0.5", + "object-assign": "^4.1.0" + }, "engines": { "node": ">=0.10.0" } @@ -1463,6 +1295,14 @@ "node": ">=0.12.0" } }, + "node_modules/grunt-contrib-uglify/node_modules/has-flag": { + "version": "3.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/grunt-contrib-uglify/node_modules/maxmin": { "version": "2.1.0", "dev": true, @@ -1477,6 +1317,14 @@ "node": ">=0.12" } }, + "node_modules/grunt-contrib-uglify/node_modules/maxmin/node_modules/ansi-styles": { + "version": "2.2.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/grunt-contrib-uglify/node_modules/maxmin/node_modules/chalk": { "version": "1.1.3", "dev": true, @@ -1492,6 +1340,14 @@ "node": ">=0.10.0" } }, + "node_modules/grunt-contrib-uglify/node_modules/maxmin/node_modules/supports-color": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/grunt-contrib-uglify/node_modules/pretty-bytes": { "version": "3.0.1", "dev": true, @@ -1504,11 +1360,14 @@ } }, "node_modules/grunt-contrib-uglify/node_modules/supports-color": { - "version": "2.0.0", + "version": "5.5.0", "dev": true, "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, "engines": { - "node": ">=0.8.0" + "node": ">=4" } }, "node_modules/grunt-contrib-watch": { @@ -1598,7 +1457,7 @@ } }, "node_modules/grunt-legacy-log-utils/node_modules/chalk": { - "version": "4.1.1", + "version": "4.1.2", "dev": true, "license": "MIT", "dependencies": { @@ -1612,30 +1471,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/grunt-legacy-log-utils/node_modules/color-convert": { - "version": "2.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/grunt-legacy-log-utils/node_modules/color-name": { - "version": "1.1.4", - "dev": true, - "license": "MIT" - }, - "node_modules/grunt-legacy-log-utils/node_modules/has-flag": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/grunt-legacy-log-utils/node_modules/supports-color": { "version": "7.2.0", "dev": true, @@ -1664,20 +1499,6 @@ "node": ">=10" } }, - "node_modules/grunt-legacy-util/node_modules/which": { - "version": "2.0.2", - "dev": true, - "license": "ISC", - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/grunt-prettier": { "version": "2.2.0", "dev": true, @@ -1704,7 +1525,7 @@ } }, "node_modules/grunt-rollup/node_modules/rollup": { - "version": "2.79.1", + "version": "2.79.2", "dev": true, "license": "MIT", "bin": { @@ -1717,18 +1538,27 @@ "fsevents": "~2.3.2" } }, - "node_modules/grunt/node_modules/rimraf": { - "version": "3.0.2", + "node_modules/grunt/node_modules/iconv-lite": { + "version": "0.6.3", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gzip-size": { + "version": "5.1.1", "dev": true, - "license": "ISC", + "license": "MIT", "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" + "duplexer": "^0.1.1", + "pify": "^4.0.1" }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "engines": { + "node": ">=6" } }, "node_modules/has-ansi": { @@ -1743,11 +1573,11 @@ } }, "node_modules/has-flag": { - "version": "3.0.0", + "version": "4.0.0", "dev": true, "license": "MIT", "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/has-property-descriptors": { @@ -1840,7 +1670,7 @@ } }, "node_modules/http-parser-js": { - "version": "0.4.10", + "version": "0.5.8", "dev": true, "license": "MIT" }, @@ -1899,22 +1729,8 @@ "node": ">=0.10.0" } }, - "node_modules/is-builtin-module": { - "version": "3.2.1", - "dev": true, - "license": "MIT", - "dependencies": { - "builtin-modules": "^3.3.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-core-module": { - "version": "2.15.0", + "version": "2.15.1", "dev": true, "license": "MIT", "dependencies": { @@ -2031,7 +1847,7 @@ } }, "node_modules/jshint": { - "version": "2.13.5", + "version": "2.13.6", "dev": true, "license": "MIT", "dependencies": { @@ -2061,7 +1877,8 @@ "license": "BSD-2-Clause" }, "node_modules/leaflet.locatecontrol": { - "version": "0.79.0", + "version": "0.81.1", + "resolved": "git+ssh://git@github.com/Maps4HTML/leaflet-locatecontrol.git#04001e9ecd4c842069920f3e85179f5b531c6718", "dev": true, "license": "MIT" }, @@ -2083,17 +1900,6 @@ "node": ">=10" } }, - "node_modules/liftup/node_modules/expand-tilde": { - "version": "2.0.2", - "dev": true, - "license": "MIT", - "dependencies": { - "homedir-polyfill": "^1.0.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/liftup/node_modules/findup-sync": { "version": "4.0.0", "dev": true, @@ -2108,80 +1914,97 @@ "node": ">= 8" } }, - "node_modules/liftup/node_modules/global-modules": { - "version": "1.0.0", + "node_modules/livereload-js": { + "version": "2.4.0", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash": { + "version": "4.17.21", + "dev": true, + "license": "MIT" + }, + "node_modules/make-iterator": { + "version": "1.0.1", "dev": true, "license": "MIT", "dependencies": { - "global-prefix": "^1.0.1", - "is-windows": "^1.0.1", - "resolve-dir": "^1.0.0" + "kind-of": "^6.0.2" }, "engines": { "node": ">=0.10.0" } }, - "node_modules/liftup/node_modules/global-prefix": { - "version": "1.0.2", + "node_modules/map-cache": { + "version": "0.2.2", "dev": true, "license": "MIT", - "dependencies": { - "expand-tilde": "^2.0.2", - "homedir-polyfill": "^1.0.1", - "ini": "^1.3.4", - "is-windows": "^1.0.1", - "which": "^1.2.14" - }, "engines": { "node": ">=0.10.0" } }, - "node_modules/liftup/node_modules/resolve-dir": { - "version": "1.0.1", + "node_modules/mapml-extension": { + "version": "1.0.0", + "resolved": "git+ssh://git@github.com/Maps4HTML/mapml-extension.git#f5fed276bbed7735a50c7501f02ab383430c9c99", + "dev": true, + "license": "W3C" + }, + "node_modules/maxmin": { + "version": "3.0.0", "dev": true, "license": "MIT", "dependencies": { - "expand-tilde": "^2.0.0", - "global-modules": "^1.0.0" + "chalk": "^4.1.0", + "figures": "^3.2.0", + "gzip-size": "^5.1.1", + "pretty-bytes": "^5.3.0" }, "engines": { - "node": ">=0.10.0" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/livereload-js": { - "version": "2.4.0", - "dev": true, - "license": "MIT" - }, - "node_modules/lodash": { - "version": "4.17.21", - "dev": true, - "license": "MIT" - }, - "node_modules/make-iterator": { - "version": "1.0.1", + "node_modules/maxmin/node_modules/ansi-styles": { + "version": "4.3.0", "dev": true, "license": "MIT", "dependencies": { - "kind-of": "^6.0.2" + "color-convert": "^2.0.1" }, "engines": { - "node": ">=0.10.0" + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/map-cache": { - "version": "0.2.2", + "node_modules/maxmin/node_modules/chalk": { + "version": "4.1.2", "dev": true, "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, "engines": { - "node": ">=0.10.0" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/mapml-extension": { - "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Maps4HTML/mapml-extension.git#c1914cda0698f6651c5ff2aacbfbe7285421fa98", + "node_modules/maxmin/node_modules/supports-color": { + "version": "7.2.0", "dev": true, - "license": "W3C" + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } }, "node_modules/media-typer": { "version": "0.3.0", @@ -2224,6 +2047,17 @@ "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime": { "version": "1.6.0", "dev": true, @@ -2265,19 +2099,8 @@ "node": "*" } }, - "node_modules/mkdirp": { - "version": "1.0.4", - "dev": true, - "license": "MIT", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/ms": { - "version": "2.1.2", + "version": "2.0.0", "dev": true, "license": "MIT" }, @@ -2495,51 +2318,59 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", + "version": "1.1.1", "dev": true, "license": "ISC" }, "node_modules/picomatch": { - "version": "2.3.1", + "version": "4.0.2", "dev": true, "license": "MIT", "engines": { - "node": ">=8.6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pify": { + "version": "4.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/playwright": { - "version": "1.39.0", + "version": "1.48.1", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.39.0" + "playwright-core": "1.48.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" }, "optionalDependencies": { "fsevents": "2.3.2" } }, "node_modules/playwright-core": { - "version": "1.39.0", + "version": "1.48.1", "dev": true, "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/pmtiles": { - "version": "3.0.7", + "version": "3.2.0", "dev": true, "license": "BSD-3-Clause", "dependencies": { @@ -2553,7 +2384,7 @@ "license": "ISC" }, "node_modules/prettier": { - "version": "2.8.4", + "version": "2.8.8", "dev": true, "license": "MIT", "bin": { @@ -2566,6 +2397,17 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/pretty-bytes": { + "version": "5.6.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/process": { "version": "0.11.10", "dev": true, @@ -2583,20 +2425,21 @@ } }, "node_modules/proj4": { - "version": "2.6.2", + "version": "2.12.1", "dev": true, "license": "MIT", "dependencies": { "mgrs": "1.0.0", - "wkt-parser": "^1.2.4" + "wkt-parser": "^1.3.3" } }, "node_modules/proj4leaflet": { "version": "1.0.2", + "resolved": "git+ssh://git@github.com/Maps4HTML/proj4leaflet.git#d4374670a5284fec00f59a3eac7082ee3016d5b0", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "proj4": "^2.3.14" + "proj4": "^2.6.2" } }, "node_modules/protocol-buffers-schema": { @@ -2605,7 +2448,7 @@ "license": "MIT" }, "node_modules/protomaps-leaflet": { - "version": "4.0.0", + "version": "4.0.1", "dev": true, "license": "BSD-3-Clause", "dependencies": { @@ -2659,15 +2502,17 @@ } }, "node_modules/raw-body": { - "version": "1.1.7", + "version": "2.5.2", "dev": true, "license": "MIT", "dependencies": { - "bytes": "1", - "string_decoder": "0.10" + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" }, "engines": { - "node": ">= 0.8.0" + "node": ">= 0.8" } }, "node_modules/rbush": { @@ -2716,6 +2561,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/resolve-dir": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "expand-tilde": "^2.0.0", + "global-modules": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/resolve-protobuf-schema": { "version": "2.1.0", "dev": true, @@ -2725,7 +2582,7 @@ } }, "node_modules/rimraf": { - "version": "2.6.3", + "version": "2.7.1", "dev": true, "license": "ISC", "dependencies": { @@ -2751,8 +2608,22 @@ } }, "node_modules/safe-buffer": { - "version": "5.1.2", + "version": "5.2.1", "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], "license": "MIT" }, "node_modules/safe-json-parse": { @@ -2787,19 +2658,6 @@ "node": ">= 0.8.0" } }, - "node_modules/send/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/send/node_modules/debug/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" - }, "node_modules/send/node_modules/encodeurl": { "version": "1.0.2", "dev": true, @@ -2874,7 +2732,7 @@ } }, "node_modules/sprintf-js": { - "version": "1.1.2", + "version": "1.0.3", "dev": true, "license": "BSD-3-Clause" }, @@ -2918,14 +2776,11 @@ } }, "node_modules/supports-color": { - "version": "5.5.0", + "version": "2.0.0", "dev": true, "license": "MIT", - "dependencies": { - "has-flag": "^3.0.0" - }, "engines": { - "node": ">=4" + "node": ">=0.8.0" } }, "node_modules/supports-preserve-symlinks-flag": { @@ -2952,6 +2807,19 @@ "qs": "^6.4.0" } }, + "node_modules/tiny-lr/node_modules/debug": { + "version": "3.2.7", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/tiny-lr/node_modules/ms": { + "version": "2.1.3", + "dev": true, + "license": "MIT" + }, "node_modules/to-regex-range": { "version": "5.0.1", "dev": true, @@ -2984,7 +2852,7 @@ } }, "node_modules/uglify-js": { - "version": "3.14.5", + "version": "3.19.3", "dev": true, "license": "BSD-2-Clause", "bin": { @@ -3003,17 +2871,22 @@ } }, "node_modules/underscore.string": { - "version": "3.3.5", + "version": "3.3.6", "dev": true, "license": "MIT", "dependencies": { - "sprintf-js": "^1.0.3", + "sprintf-js": "^1.1.1", "util-deprecate": "^1.0.2" }, "engines": { "node": "*" } }, + "node_modules/underscore.string/node_modules/sprintf-js": { + "version": "1.1.3", + "dev": true, + "license": "BSD-3-Clause" + }, "node_modules/unpipe": { "version": "1.0.0", "dev": true, @@ -3084,11 +2957,11 @@ } }, "node_modules/websocket-driver": { - "version": "0.7.3", + "version": "0.7.4", "dev": true, "license": "Apache-2.0", "dependencies": { - "http-parser-js": ">=0.4.0 <0.4.11", + "http-parser-js": ">=0.5.1", "safe-buffer": ">=5.1.0", "websocket-extensions": ">=0.1.1" }, @@ -3105,18 +2978,21 @@ } }, "node_modules/which": { - "version": "1.3.1", + "version": "2.0.2", "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, "bin": { - "which": "bin/which" + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" } }, "node_modules/wkt-parser": { - "version": "1.2.4", + "version": "1.3.3", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 2af2db909..a2bf3d617 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "web-map", "layer" ], - "main": "mapml.js", - "module": "mapml.js", + "main": "dist/mapml.js", + "module": "dist/mapml.js", "author": "Maps for HTML Community Group", "repository": { "type": "git", @@ -37,6 +37,8 @@ }, "devDependencies": { "@playwright/test": "^1.39.0", + "@rollup/plugin-alias": "^5.1.1", + "@rollup/plugin-legacy": "^3.0.2", "@rollup/plugin-node-resolve": "^15.2.3", "mapml-extension": "git+https://github.com/Maps4HTML/mapml-extension", "diff": "^5.1.0", @@ -53,12 +55,12 @@ "grunt-prettier": "^2.2.0", "grunt-rollup": "^12.0.0", "leaflet": "^1.9.4", - "leaflet.locatecontrol": "^0.79.0", + "leaflet.locatecontrol": "^0.81.1", "path": "^0.12.7", "playwright": "^1.39.0", "proj4": "^2.6.2", - "proj4leaflet": "^1.0.2", - "protomaps-leaflet": "4.0.0", + "proj4leaflet": "git+https://github.com/Maps4HTML/proj4leaflet.git#es-module", + "protomaps-leaflet": "^4.0.1", "rollup": "^3.29.5", "serve-static": "^1.15.0" }, diff --git a/src/layer-.js b/src/layer-.js index 18c480196..d75b84900 100644 --- a/src/layer-.js +++ b/src/layer-.js @@ -1,4 +1,4 @@ -import { BaseLayerElement } from './layer'; +import { BaseLayerElement } from './layer.js'; export class LayerDashElement extends BaseLayerElement { constructor() { diff --git a/src/layer.js b/src/layer.js index 4cfacc093..9e24f40d5 100644 --- a/src/layer.js +++ b/src/layer.js @@ -1,6 +1,8 @@ -import { Util } from './mapml/utils/Util'; -import { MapMLLayer, mapMLLayer } from './mapml/layers/MapMLLayer'; -import { createLayerControlHTML } from './mapml/elementSupport/layers/createLayerControlForLayer'; +import { setOptions, DomUtil, bounds, point } from 'leaflet'; + +import { Util } from './mapml/utils/Util.js'; +import { MapMLLayer, mapMLLayer } from './mapml/layers/MapMLLayer.js'; +import { createLayerControlHTML } from './mapml/elementSupport/layers/createLayerControlForLayer.js'; export class BaseLayerElement extends HTMLElement { static get observedAttributes() { @@ -437,9 +439,9 @@ export class BaseLayerElement extends HTMLElement { /* * Runs the effects of the mutation observer, which is to add map-features' and * map-extents' leaflet layer implementations to the appropriate container in - * the map-layer._layer: either as a sub-layer directly in the L.LayerGroup + * the map-layer._layer: either as a sub-layer directly in the LayerGroup * (MapMLLayer._layer) or as a sub-layer in the MapMLLayer._mapmlvectors - * L.FeatureGroup + * FeatureGroup */ _runMutationObserver(elementsGroup) { const _addFeatureToMapMLVectors = (feature) => { @@ -561,7 +563,7 @@ export class BaseLayerElement extends HTMLElement { var proj = this.parentNode.projection ? this.parentNode.projection : 'OSMTILE'; - L.setOptions(this._layer, { + setOptions(this._layer, { zIndex: position, mapprojection: proj, opacity: window.getComputedStyle(this).opacity @@ -741,7 +743,7 @@ export class BaseLayerElement extends HTMLElement { for (var j = 0; j < styleLinks.length; j++) { stylesControl.appendChild(styleLinks[j].getLayerControlOption()); - L.DomUtil.addClass( + DomUtil.addClass( stylesControl, 'mapml-layer-item-style mapml-control-layers' ); @@ -797,9 +799,9 @@ export class BaseLayerElement extends HTMLElement { extent = this.extent, tL = extent.topLeft.pcrs, bR = extent.bottomRight.pcrs, - layerBounds = L.bounds( - L.point(tL.horizontal, tL.vertical), - L.point(bR.horizontal, bR.vertical) + layerBounds = bounds( + point(tL.horizontal, tL.vertical), + point(bR.horizontal, bR.vertical) ), center = map.options.crs.unproject(layerBounds.getCenter(true)); diff --git a/src/map-area.js b/src/map-area.js index ecbf4d1d6..87d57f368 100644 --- a/src/map-area.js +++ b/src/map-area.js @@ -1,3 +1,5 @@ +import { point, circle, latLngBounds, rectangle, polygon, SVG } from 'leaflet'; + export class HTMLMapAreaElement extends HTMLAreaElement { static get observedAttributes() { return ['coords', 'alt', 'href', 'shape', 'rel', 'type', 'target']; @@ -89,31 +91,31 @@ export class HTMLMapAreaElement extends HTMLAreaElement { if (this.shape === 'circle') { var pixelRadius = parseInt(this.coords.split(',')[2]), - pointOnCirc = L.point(points[0]).add(L.point(0, pixelRadius)), + pointOnCirc = point(points[0]).add(point(0, pixelRadius)), latLngOnCirc = map.containerPointToLatLng(pointOnCirc), latLngCenter = map.containerPointToLatLng(points[0]), radiusInMeters = map.distance(latLngCenter, latLngOnCirc); - this._feature = L.circle(latLngCenter, radiusInMeters, options).addTo( + this._feature = circle(latLngCenter, radiusInMeters, options).addTo( map ); } else if (!this.shape || this.shape === 'rect') { - var bounds = L.latLngBounds( + var bnds = latLngBounds( map.containerPointToLatLng(points[0]), map.containerPointToLatLng(points[1]) ); - this._feature = L.rectangle(bounds, options).addTo(map); + this._feature = rectangle(bnds, options).addTo(map); } else if (this.shape === 'poly') { - this._feature = L.polygon(this._pointsToLatLngs(points), options).addTo( + this._feature = polygon(this._pointsToLatLngs(points), options).addTo( map ); } else { // whole initial area of map is a hyperlink - this._feature = L.rectangle(map.getBounds(), options).addTo(map); + this._feature = rectangle(map.getBounds(), options).addTo(map); } if (this.alt) { // other Leaflet features are implemented via SVG. SVG displays tooltips // based on the graphics child element. - var title = L.SVG.create('title'), + var title = SVG.create('title'), titleText = document.createTextNode(this.alt); title.appendChild(titleText); this._feature._path.appendChild(title); diff --git a/src/map-extent.js b/src/map-extent.js index 8c4877db1..7f08032a3 100644 --- a/src/map-extent.js +++ b/src/map-extent.js @@ -1,6 +1,8 @@ -import { Util } from './mapml/utils/Util'; -import { extentLayer } from './mapml/layers/ExtentLayer'; -import { createLayerControlExtentHTML } from './mapml/elementSupport/extents/createLayerControlForExtent'; +import { bounds as Lbounds, point as Lpoint } from 'leaflet'; + +import { Util } from './mapml/utils/Util.js'; +import { extentLayer } from './mapml/layers/ExtentLayer.js'; +import { createLayerControlExtentHTML } from './mapml/elementSupport/extents/createLayerControlForExtent.js'; /* global M */ export class HTMLExtentElement extends HTMLElement { @@ -121,7 +123,7 @@ export class HTMLExtentElement extends HTMLElement { xmax = extent.bottomRight.pcrs.horizontal, ymin = extent.bottomRight.pcrs.vertical, ymax = extent.topLeft.pcrs.vertical, - bounds = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax)), + bounds = Lbounds(Lpoint(xmin, ymin), Lpoint(xmax, ymax)), center = map.options.crs.unproject(bounds.getCenter(true)), maxZoom = extent.zoom.maxZoom, minZoom = extent.zoom.minZoom; @@ -544,7 +546,7 @@ export class HTMLExtentElement extends HTMLElement { zoomBounds.maxNativeZoom = maxNativeZoom; } if (!bounds) { - bounds = L.bounds(templateBounds.min, templateBounds.max); + bounds = Lbounds(templateBounds.min, templateBounds.max); } else { bounds.extend(templateBounds); } @@ -552,7 +554,7 @@ export class HTMLExtentElement extends HTMLElement { if (bounds) { this._extentLayer.bounds = bounds; } else { - this._extentLayer.bounds = L.bounds( + this._extentLayer.bounds = Lbounds( M[this.units].options.bounds.min, M[this.units].options.bounds.max ); diff --git a/src/map-feature.js b/src/map-feature.js index 238cd8eed..5ae172fd4 100644 --- a/src/map-feature.js +++ b/src/map-feature.js @@ -1,4 +1,7 @@ -import { Util } from './mapml/utils/Util'; +import { bounds, point } from 'leaflet'; + +import { Util } from './mapml/utils/Util.js'; +import proj4 from 'proj4'; export class HTMLFeatureElement extends HTMLElement { static get observedAttributes() { @@ -234,7 +237,7 @@ export class HTMLFeatureElement extends HTMLElement { } removeFeature(layerToRemoveFrom) { - // layerToRemoveFrom is the L.LayerGroup or L.FeatureGroup to remove this + // layerToRemoveFrom is the LayerGroup or FeatureGroup to remove this // feature from... layerToRemoveFrom.removeLayer(this._geometry); // TODO: MOVE THIS LOGIC TO layerToRemoveFrom.removeLayer(Geometry) @@ -345,10 +348,10 @@ export class HTMLFeatureElement extends HTMLElement { bboxExtent = _updateExtent(shape, coord[i], bboxExtent); } } - let topLeft = L.point(bboxExtent[0], bboxExtent[1]); - let bottomRight = L.point(bboxExtent[2], bboxExtent[3]); + let topLeft = point(bboxExtent[0], bboxExtent[1]); + let bottomRight = point(bboxExtent[2], bboxExtent[3]); let pcrsBound = Util.boundsToPCRSBounds( - L.bounds(topLeft, bottomRight), + bounds(topLeft, bottomRight), zoom, map.options.projection, cs @@ -367,7 +370,7 @@ export class HTMLFeatureElement extends HTMLElement { M[projection].scale(+this.zoom || maxZoom) ); pcrsBound = Util.pixelToPCRSBounds( - L.bounds(pixel.subtract(tileCenter), pixel.add(tileCenter)), + bounds(pixel.subtract(tileCenter), pixel.add(tileCenter)), this.zoom || maxZoom, projection ); @@ -423,9 +426,9 @@ export class HTMLFeatureElement extends HTMLElement { getZoomToZoom() { let tL = this.extent.topLeft.pcrs, bR = this.extent.bottomRight.pcrs, - bound = L.bounds( - L.point(tL.horizontal, tL.vertical), - L.point(bR.horizontal, bR.vertical) + bound = bounds( + point(tL.horizontal, tL.vertical), + point(bR.horizontal, bR.vertical) ); let projection = this.getMapEl()._map.options.projection, layerZoomBounds = this.getLayerEl().extent.zoom, @@ -616,9 +619,9 @@ export class HTMLFeatureElement extends HTMLElement { map = this.getMapEl()._map; let tL = extent.topLeft.pcrs, bR = extent.bottomRight.pcrs, - bound = L.bounds( - L.point(tL.horizontal, tL.vertical), - L.point(bR.horizontal, bR.vertical) + bound = bounds( + point(tL.horizontal, tL.vertical), + point(bR.horizontal, bR.vertical) ), center = map.options.crs.unproject(bound.getCenter(true)); map.setView(center, this.getZoomToZoom(), { animate: false }); diff --git a/src/map-input.js b/src/map-input.js index 6fa947066..b2672df14 100644 --- a/src/map-input.js +++ b/src/map-input.js @@ -1,9 +1,9 @@ -import { Util } from './mapml/utils/Util'; -import { ZoomInput } from './mapml/elementSupport/inputs/zoomInput'; -import { HiddenInput } from './mapml/elementSupport/inputs/hiddenInput'; -import { WidthInput } from './mapml/elementSupport/inputs/widthInput'; -import { HeightInput } from './mapml/elementSupport/inputs/heightInput'; -import { LocationInput } from './mapml/elementSupport/inputs/locationInput'; +import { Util } from './mapml/utils/Util.js'; +import { ZoomInput } from './mapml/elementSupport/inputs/zoomInput.js'; +import { HiddenInput } from './mapml/elementSupport/inputs/hiddenInput.js'; +import { WidthInput } from './mapml/elementSupport/inputs/widthInput.js'; +import { HeightInput } from './mapml/elementSupport/inputs/heightInput.js'; +import { LocationInput } from './mapml/elementSupport/inputs/locationInput.js'; /* global M */ export class HTMLInputElement extends HTMLElement { diff --git a/src/map-layer.js b/src/map-layer.js index 30e5e2dd2..801eb09d3 100644 --- a/src/map-layer.js +++ b/src/map-layer.js @@ -1,4 +1,4 @@ -import { BaseLayerElement } from './layer'; +import { BaseLayerElement } from './layer.js'; export class HTMLLayerElement extends BaseLayerElement { constructor() { diff --git a/src/map-link.js b/src/map-link.js index 9b9195b4d..c454c2110 100644 --- a/src/map-link.js +++ b/src/map-link.js @@ -1,8 +1,17 @@ -import { Util } from './mapml/utils/Util'; -import { templatedImageLayer } from './mapml/layers/TemplatedImageLayer'; -import { templatedTileLayer } from './mapml/layers/TemplatedTileLayer'; -import { templatedFeaturesLayer } from './mapml/layers/TemplatedFeaturesLayer'; -import { templatedPMTilesLayer } from './mapml/layers/TemplatedPMTilesLayer'; +import { + bounds, + point, + extend, + DomEvent, + stamp, + Util as LeafletUtil +} from 'leaflet'; + +import { Util } from './mapml/utils/Util.js'; +import { templatedImageLayer } from './mapml/layers/TemplatedImageLayer.js'; +import { templatedTileLayer } from './mapml/layers/TemplatedTileLayer.js'; +import { templatedFeaturesLayer } from './mapml/layers/TemplatedFeaturesLayer.js'; +import { templatedPMTilesLayer } from './mapml/layers/TemplatedPMTilesLayer.js'; /* global M */ export class HTMLLinkElement extends HTMLElement { @@ -151,11 +160,11 @@ export class HTMLLinkElement extends HTMLElement { xmax = extent.bottomRight.pcrs.horizontal, ymin = extent.bottomRight.pcrs.vertical, ymax = extent.topLeft.pcrs.vertical, - bounds = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax)), - center = map.options.crs.unproject(bounds.getCenter(true)), + newBounds = bounds(point(xmin, ymin), point(xmax, ymax)), + center = map.options.crs.unproject(newBounds.getCenter(true)), maxZoom = extent.zoom.maxZoom, minZoom = extent.zoom.minZoom; - map.setView(center, Util.getMaxZoom(bounds, map, minZoom, maxZoom), { + map.setView(center, Util.getMaxZoom(newBounds, map, minZoom, maxZoom), { animate: false }); } @@ -434,8 +443,8 @@ export class HTMLLinkElement extends HTMLElement { }).addTo(this.parentExtent._extentLayer); } else if (this.rel === 'query') { this.attachShadow({ mode: 'open' }); - L.extend(this._templateVars, this._setupQueryVars(this._templateVars)); - L.extend(this._templateVars, { extentBounds: this.getBounds() }); + extend(this._templateVars, this._setupQueryVars(this._templateVars)); + extend(this._templateVars, { extentBounds: this.getBounds() }); } } _setupQueryVars(template) { @@ -654,7 +663,7 @@ export class HTMLLinkElement extends HTMLElement { projection = this.parentElement.units, boundsUnit = {}; boundsUnit.name = M.FALLBACK_CS; - let bounds = M[projection].options.crs.tilematrix.bounds(0), + let bnds = M[projection].options.crs.tilematrix.bounds(0), locInputs = false, numberOfAxes = 0, horizontalAxis = false, @@ -673,8 +682,8 @@ export class HTMLLinkElement extends HTMLElement { boundsUnit.name = Util.axisToCS( inputs[i].getAttribute('axis').toLowerCase() ); - bounds.min.x = min; - bounds.max.x = max; + bnds.min.x = min; + bnds.max.x = max; boundsUnit.horizontalAxis = inputs[i] .getAttribute('axis') .toLowerCase(); @@ -686,8 +695,8 @@ export class HTMLLinkElement extends HTMLElement { boundsUnit.name = Util.axisToCS( inputs[i].getAttribute('axis').toLowerCase() ); - bounds.min.y = min; - bounds.max.y = max; + bnds.min.y = min; + bnds.max.y = max; boundsUnit.verticalAxis = inputs[i] .getAttribute('axis') .toLowerCase(); @@ -714,19 +723,19 @@ export class HTMLLinkElement extends HTMLElement { let zoomValue = this._templateVars.zoom?.hasAttribute('value') ? +this._templateVars.zoom.getAttribute('value') : 0; - bounds = Util.boundsToPCRSBounds( - bounds, + bnds = Util.boundsToPCRSBounds( + bnds, zoomValue, projection, boundsUnit.name ); } else if (!locInputs) { - bounds = this.getFallbackBounds(projection); + bnds = this.getFallbackBounds(projection); } - return bounds; + return bnds; } getFallbackBounds(projection) { - let bounds; + let bnds; let zoom = 0; let metaExtent = this.parentElement.getMeta('extent'); @@ -746,13 +755,13 @@ export class HTMLLinkElement extends HTMLElement { } } let axes = Util.csToAxes(cs); - bounds = Util.boundsToPCRSBounds( - L.bounds( - L.point( + bnds = Util.boundsToPCRSBounds( + bounds( + point( +content[`top-left-${axes[0]}`], +content[`top-left-${axes[1]}`] ), - L.point( + point( +content[`bottom-right-${axes[0]}`], +content[`bottom-right-${axes[1]}`] ) @@ -763,9 +772,9 @@ export class HTMLLinkElement extends HTMLElement { ); } else { let crs = M[projection]; - bounds = crs.options.crs.pcrs.bounds; + bnds = crs.options.crs.pcrs.bounds; } - return bounds; + return bnds; } getBase() { let layer = this.getRootNode().host; @@ -792,7 +801,7 @@ export class HTMLLinkElement extends HTMLElement { } /** * Return BOTH min/max(Display)Zoom AND min/maxNativeZoom which - * are options that can be passed to L.GridLayer... + * are options that can be passed to GridLayer... * https://leafletjs.com/reference.html#gridlayer-minzoom * * @param {Object} zoomInput - is an element reference to a map-input[type=zoom] @@ -847,7 +856,7 @@ export class HTMLLinkElement extends HTMLElement { xmax = extent.bottomRight.pcrs.horizontal, ymin = extent.bottomRight.pcrs.vertical, ymax = extent.topLeft.pcrs.vertical, - mapBounds = L.bounds(L.point(xmin, ymin), L.point(xmax, ymax)); + mapBounds = bounds(point(xmin, ymin), point(xmax, ymax)); if (this._templatedLayer) { isVisible = this._templatedLayer.isVisible(); @@ -867,7 +876,7 @@ export class HTMLLinkElement extends HTMLElement { _createSelfOrStyleLink() { let layerEl = this.getLayerEl(); const changeStyle = function (e) { - L.DomEvent.stop(e); + DomEvent.stop(e); layerEl.dispatchEvent( new CustomEvent('changestyle', { detail: { @@ -883,11 +892,11 @@ export class HTMLLinkElement extends HTMLElement { document.createElement('input') ); styleOptionInput.setAttribute('type', 'radio'); - styleOptionInput.setAttribute('id', 'rad-' + L.stamp(styleOptionInput)); + styleOptionInput.setAttribute('id', 'rad-' + stamp(styleOptionInput)); styleOptionInput.setAttribute( 'name', // grouping radio buttons based on parent layer's style - 'styles-' + L.stamp(styleOption) + 'styles-' + stamp(styleOption) ); styleOptionInput.setAttribute('value', this.getAttribute('title')); styleOptionInput.setAttribute( @@ -897,7 +906,7 @@ export class HTMLLinkElement extends HTMLElement { var styleOptionLabel = styleOption.appendChild( document.createElement('label') ); - styleOptionLabel.setAttribute('for', 'rad-' + L.stamp(styleOptionInput)); + styleOptionLabel.setAttribute('for', 'rad-' + stamp(styleOptionInput)); styleOptionLabel.innerText = this.title; if (this.rel === 'style self' || this.rel === 'self style') { styleOptionInput.checked = true; @@ -921,7 +930,7 @@ export class HTMLLinkElement extends HTMLElement { obj[inp.name] = inp.value; } console.log(obj); // DEBUGGING - return L.Util.template(this.tref, obj); + return LeafletUtil.template(this.tref, obj); } else if (this.rel === 'tile') { // TODO. Need to get tile coords from moveend // should be done/called from the TemplatedTilelayer.js file diff --git a/src/map-select.js b/src/map-select.js index 7398570c5..56451839d 100644 --- a/src/map-select.js +++ b/src/map-select.js @@ -1,3 +1,5 @@ +import { DomUtil } from 'leaflet'; + export class HTMLSelectElement extends HTMLElement { static get observedAttributes() { return ['name', 'id']; @@ -48,12 +50,12 @@ export class HTMLSelectElement extends HTMLElement { // don't add it again if it is referenced > once // generate a
this.htmlselect = this.transcribe(); - var selectdetails = L.DomUtil.create( + var selectdetails = DomUtil.create( 'details', 'mapml-layer-item-details mapml-control-layers' ), - selectsummary = L.DomUtil.create('summary'), - selectSummaryLabel = L.DomUtil.create('label'); + selectsummary = DomUtil.create('summary'), + selectSummaryLabel = DomUtil.create('label'); selectSummaryLabel.innerText = this.getAttribute('name'); selectSummaryLabel.setAttribute('for', this.getAttribute('id')); selectsummary.appendChild(selectSummaryLabel); diff --git a/src/mapml-viewer.js b/src/mapml-viewer.js index 705af834d..5aab491dc 100644 --- a/src/mapml-viewer.js +++ b/src/mapml-viewer.js @@ -1,5 +1,14 @@ -import { Util } from './mapml/utils/Util'; -import { DOMTokenList } from './mapml/utils/DOMTokenList'; +import { + map, + LatLng, + control, + bounds, + latLngBounds, + LayerGroup +} from 'leaflet'; +import Proj from 'proj4leaflet/src/proj4leaflet.js'; +import { Util } from './mapml/utils/Util.js'; +import { DOMTokenList } from './mapml/utils/DOMTokenList.js'; import { HTMLLayerElement } from './map-layer.js'; import { LayerDashElement } from './layer-.js'; @@ -10,18 +19,18 @@ import { HTMLInputElement } from './map-input.js'; import { HTMLSelectElement } from './map-select.js'; import { HTMLLinkElement } from './map-link.js'; import { HTMLStyleElement } from './map-style.js'; -import { HTMLWebMapElement } from './web-map'; +import { HTMLWebMapElement } from './web-map.js'; import { HTMLMapAreaElement } from './map-area.js'; -import { layerControl } from './mapml/control/LayerControl'; -import { AttributionButton } from './mapml/control/AttributionButton'; -import { reloadButton } from './mapml/control/ReloadButton'; -import { scaleBar } from './mapml/control/ScaleBar'; -import { fullscreenButton } from './mapml/control/FullscreenButton'; -import { geolocationButton } from './mapml/control/GeolocationButton'; -import { debugOverlay } from './mapml/layers/DebugOverlay'; -import { crosshair } from './mapml/layers/Crosshair'; -import { featureIndexOverlay } from './mapml/layers/FeatureIndexOverlay'; +import { layerControl } from './mapml/control/LayerControl.js'; +import { AttributionButton } from './mapml/control/AttributionButton.js'; +import { reloadButton } from './mapml/control/ReloadButton.js'; +import { scaleBar } from './mapml/control/ScaleBar.js'; +import { fullscreenButton } from './mapml/control/FullscreenButton.js'; +import { geolocationButton } from './mapml/control/GeolocationButton.js'; +import { debugOverlay } from './mapml/layers/DebugOverlay.js'; +import { crosshair } from './mapml/layers/Crosshair.js'; +import { featureIndexOverlay } from './mapml/layers/FeatureIndexOverlay.js'; export class HTMLMapmlViewerElement extends HTMLElement { static get observedAttributes() { @@ -230,8 +239,8 @@ export class HTMLMapmlViewerElement extends HTMLElement { }, 0); } }) - .catch(() => { - throw new Error('Projection not defined'); + .catch((e) => { + throw new Error('Projection not defined: ' + e); }); } _setLocale() { @@ -301,8 +310,8 @@ export class HTMLMapmlViewerElement extends HTMLElement { } _createMap() { if (!this._map) { - this._map = L.map(this._container, { - center: new L.LatLng(this.lat, this.lon), + this._map = map(this._container, { + center: new LatLng(this.lat, this.lon), minZoom: 0, maxZoom: M[this.projection].options.resolutions.length - 1, projection: this.projection, @@ -472,7 +481,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { // Only add controls if there is enough top left vertical space if (!this._zoomControl && totalSize + 93 <= mapSize) { totalSize += 93; - this._zoomControl = L.control + this._zoomControl = control .zoom({ zoomInTitle: this.locale.btnZoomIn, zoomOutTitle: this.locale.btnZoomOut @@ -1023,7 +1032,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { } zoomTo(lat, lon, zoom) { zoom = Number.isInteger(+zoom) ? +zoom : this.zoom; - let location = new L.LatLng(+lat, +lon); + let location = new LatLng(+lat, +lon); this._map.setView(location, zoom); this.zoom = zoom; this.lat = location.lat; @@ -1225,10 +1234,10 @@ export class HTMLMapmlViewerElement extends HTMLElement { ? t.tilesize : M.TILE_SIZE; - M[t.projection] = new L.Proj.CRS(t.projection, t.proj4string, { + M[t.projection] = new Proj.CRS(t.projection, t.proj4string, { origin: t.origin, resolutions: t.resolutions, - bounds: L.bounds(t.bounds), + bounds: bounds(t.bounds), crs: { tcrs: { horizontal: { @@ -1250,7 +1259,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { ) }, bounds: (zoom) => - L.bounds( + bounds( [ M[t.projection].options.crs.tcrs.horizontal.min, M[t.projection].options.crs.tcrs.vertical.min @@ -1310,7 +1319,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { } }, get bounds() { - return L.latLngBounds( + return latLngBounds( [ M[t.projection].options.crs.gcrs.vertical.min, M[t.projection].options.crs.gcrs.horizontal.min @@ -1333,7 +1342,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { min: 0, max: (map) => map.getSize().y }, - bounds: (map) => L.bounds(L.point([0, 0]), map.getSize()) + bounds: (map) => bounds([0, 0], map.getSize()) }, tile: { horizontal: { @@ -1347,7 +1356,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { max: tileSize }, get bounds() { - return L.bounds( + return bounds( [ M[t.projection].options.crs.tile.horizontal.min, M[t.projection].options.crs.tile.vertical.min @@ -1379,7 +1388,7 @@ export class HTMLMapmlViewerElement extends HTMLElement { ) }, bounds: (zoom) => - L.bounds( + bounds( [ M[t.projection].options.crs.tilematrix.horizontal.min, M[t.projection].options.crs.tilematrix.vertical.min diff --git a/src/mapml/GlobalM.js b/src/mapml/GlobalM.js index 445d3f150..9c1e5171f 100644 --- a/src/mapml/GlobalM.js +++ b/src/mapml/GlobalM.js @@ -1,10 +1,12 @@ -import { QueryHandler } from './handlers/QueryHandler'; -import { ContextMenu } from './handlers/ContextMenu'; -import { Util } from './utils/Util'; -import { AnnounceMovement } from './handlers/AnnounceMovement'; -import { FeatureIndex } from './handlers/FeatureIndex'; -import { Options } from './DefaultMapOptions'; -import './handlers/keyboard'; +import { Map, CRS, bounds, latLngBounds, point, setOptions } from 'leaflet'; +import { QueryHandler } from './handlers/QueryHandler.js'; +import { ContextMenu } from './handlers/ContextMenu.js'; +import { Util } from './utils/Util.js'; +import { AnnounceMovement } from './handlers/AnnounceMovement.js'; +import { FeatureIndex } from './handlers/FeatureIndex.js'; +import { Options } from './DefaultMapOptions.js'; +import './handlers/keyboard.js'; +import Proj from 'proj4leaflet/src/proj4leaflet.js'; (function (window, document, undefined) { let M = {}; @@ -23,16 +25,16 @@ import './handlers/keyboard'; M.options = Object.assign(M.options, JSON.parse(mapOptions.innerHTML)); // see https://leafletjs.com/reference-1.5.0.html#crs-l-crs-base - // "new classes can't inherit from (L.CRS), and methods can't be added - // to (L.CRS.anything) with the include function + // "new classes can't inherit from (CRS), and methods can't be added + // to (CRS.anything) with the include function // so we'll use the options property as a way to integrate needed // properties and methods... - M.WGS84 = new L.Proj.CRS( + M.WGS84 = new Proj.CRS( 'EPSG:4326', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ', { origin: [-180, +90], - bounds: L.bounds([ + bounds: bounds([ [-180, -90], [180, 90] ]), @@ -66,7 +68,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [ M.WGS84.options.crs.tcrs.horizontal.min, M.WGS84.options.crs.tcrs.vertical.min @@ -114,7 +116,7 @@ import './handlers/keyboard'; max: 90.0 }, get bounds() { - return L.latLngBounds( + return latLngBounds( [ M.WGS84.options.crs.gcrs.vertical.min, M.WGS84.options.crs.gcrs.horizontal.min @@ -137,7 +139,7 @@ import './handlers/keyboard'; min: 0, max: (map) => map.getSize().y }, - bounds: (map) => L.bounds(L.point([0, 0]), map.getSize()) + bounds: (map) => bounds(point([0, 0]), map.getSize()) }, tile: { horizontal: { @@ -151,7 +153,7 @@ import './handlers/keyboard'; max: 256 }, get bounds() { - return L.bounds( + return bounds( [ M.WGS84.options.crs.tile.horizontal.min, M.WGS84.options.crs.tile.vertical.min @@ -183,7 +185,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [ M.WGS84.options.crs.tilematrix.horizontal.min, M.WGS84.options.crs.tilematrix.vertical.min @@ -197,12 +199,12 @@ import './handlers/keyboard'; } } ); - M.CBMTILE = new L.Proj.CRS( + M.CBMTILE = new Proj.CRS( 'EPSG:3978', '+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs', { origin: [-34655800, 39310000], - bounds: L.bounds([ + bounds: bounds([ [-34655800, -39000000], [10000000, 39310000] ]), @@ -238,7 +240,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [ M.CBMTILE.options.crs.tcrs.horizontal.min, M.CBMTILE.options.crs.tcrs.vertical.min @@ -286,7 +288,7 @@ import './handlers/keyboard'; max: 86.46 }, get bounds() { - return L.latLngBounds( + return latLngBounds( [ M.CBMTILE.options.crs.gcrs.vertical.min, M.CBMTILE.options.crs.gcrs.horizontal.min @@ -309,7 +311,7 @@ import './handlers/keyboard'; min: 0, max: (map) => map.getSize().y }, - bounds: (map) => L.bounds(L.point([0, 0]), map.getSize()) + bounds: (map) => bounds(point([0, 0]), map.getSize()) }, tile: { horizontal: { @@ -323,7 +325,7 @@ import './handlers/keyboard'; max: 256 }, get bounds() { - return L.bounds( + return bounds( [ M.CBMTILE.options.crs.tile.horizontal.min, M.CBMTILE.options.crs.tile.vertical.min @@ -355,7 +357,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [0, 0], [ M.CBMTILE.options.crs.tilematrix.horizontal.max(zoom), @@ -366,12 +368,12 @@ import './handlers/keyboard'; } } ); - M.APSTILE = new L.Proj.CRS( + M.APSTILE = new Proj.CRS( 'EPSG:5936', '+proj=stere +lat_0=90 +lat_ts=50 +lon_0=-150 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m +no_defs', { origin: [-2.8567784109255e7, 3.2567784109255e7], - bounds: L.bounds([ + bounds: bounds([ [-28567784.109254867, -28567784.109254755], [32567784.109255023, 32567784.10925506] ]), @@ -403,7 +405,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [ M.APSTILE.options.crs.tcrs.horizontal.min, M.APSTILE.options.crs.tcrs.vertical.min @@ -451,7 +453,7 @@ import './handlers/keyboard'; max: 90.0 }, get bounds() { - return L.latLngBounds( + return latLngBounds( [ M.APSTILE.options.crs.gcrs.vertical.min, M.APSTILE.options.crs.gcrs.horizontal.min @@ -474,7 +476,7 @@ import './handlers/keyboard'; min: 0, max: (map) => map.getSize().y }, - bounds: (map) => L.bounds(L.point([0, 0]), map.getSize()) + bounds: (map) => bounds(point([0, 0]), map.getSize()) }, tile: { horizontal: { @@ -488,7 +490,7 @@ import './handlers/keyboard'; max: 256 }, get bounds() { - return L.bounds( + return bounds( [ M.APSTILE.options.crs.tile.horizontal.min, M.APSTILE.options.crs.tile.vertical.min @@ -520,7 +522,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [0, 0], [ M.APSTILE.options.crs.tilematrix.horizontal.max(zoom), @@ -531,10 +533,10 @@ import './handlers/keyboard'; } } ); - M.OSMTILE = L.CRS.EPSG3857; - L.setOptions(M.OSMTILE, { + M.OSMTILE = CRS.EPSG3857; + setOptions(M.OSMTILE, { origin: [-20037508.342787, 20037508.342787], - bounds: L.bounds([ + bounds: bounds([ [-20037508.342787, -20037508.342787], [20037508.342787, 20037508.342787] ]), @@ -568,7 +570,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [ M.OSMTILE.options.crs.tcrs.horizontal.min, M.OSMTILE.options.crs.tcrs.vertical.min @@ -622,7 +624,7 @@ import './handlers/keyboard'; } }, get bounds() { - return L.latLngBounds( + return latLngBounds( [ M.OSMTILE.options.crs.gcrs.vertical.min, M.OSMTILE.options.crs.gcrs.horizontal.min @@ -645,7 +647,7 @@ import './handlers/keyboard'; min: 0, max: (map) => map.getSize().y }, - bounds: (map) => L.bounds(L.point([0, 0]), map.getSize()) + bounds: (map) => bounds(point([0, 0]), map.getSize()) }, tile: { horizontal: { @@ -659,7 +661,7 @@ import './handlers/keyboard'; max: 256 }, get bounds() { - return L.bounds( + return bounds( [ M.OSMTILE.options.crs.tile.horizontal.min, M.OSMTILE.options.crs.tile.vertical.min @@ -691,7 +693,7 @@ import './handlers/keyboard'; ) }, bounds: (zoom) => - L.bounds( + bounds( [0, 0], [ M.OSMTILE.options.crs.tilematrix.horizontal.max(zoom), @@ -706,10 +708,10 @@ import './handlers/keyboard'; M.mapml2geojson = Util.mapml2geojson; // see https://leafletjs.com/examples/extending/extending-3-controls.html#handlers - L.Map.addInitHook('addHandler', 'query', QueryHandler); - L.Map.addInitHook('addHandler', 'contextMenu', ContextMenu); - L.Map.addInitHook('addHandler', 'announceMovement', AnnounceMovement); - L.Map.addInitHook('addHandler', 'featureIndex', FeatureIndex); + Map.addInitHook('addHandler', 'query', QueryHandler); + Map.addInitHook('addHandler', 'contextMenu', ContextMenu); + Map.addInitHook('addHandler', 'announceMovement', AnnounceMovement); + Map.addInitHook('addHandler', 'featureIndex', FeatureIndex); // constants M.TILE_SIZE = 256; diff --git a/src/mapml/control/AttributionButton.js b/src/mapml/control/AttributionButton.js index 23bf383f4..50eaf4431 100644 --- a/src/mapml/control/AttributionButton.js +++ b/src/mapml/control/AttributionButton.js @@ -1,4 +1,6 @@ -export var AttributionButton = L.Control.Attribution.extend({ +import { Control, DomUtil, DomEvent, Map } from 'leaflet'; + +export var AttributionButton = Control.Attribution.extend({ options: { prefix: 'W3C Community and Business Groups logo Maps for HTML Community Group | Slava Ukraini Leaflet ' @@ -10,11 +12,8 @@ export var AttributionButton = L.Control.Attribution.extend({ }, onAdd: function (map) { map.attributionControl = this; - this._container = L.DomUtil.create( - 'details', - 'leaflet-control-attribution' - ); - L.DomEvent.disableClickPropagation(this._container); + this._container = DomUtil.create('details', 'leaflet-control-attribution'); + DomEvent.disableClickPropagation(this._container); for (var i in map._layers) { if (map._layers[i].getAttribution) { @@ -75,12 +74,12 @@ export var AttributionButton = L.Control.Attribution.extend({ } }); -L.Map.mergeOptions({ +Map.mergeOptions({ attributionControl: false, toggleableAttributionControl: true }); -L.Map.addInitHook(function () { +Map.addInitHook(function () { if (this.options.toggleableAttributionControl) { attributionButton({ mapEl: this.options.mapEl }).addTo(this); } diff --git a/src/mapml/control/FullscreenButton.js b/src/mapml/control/FullscreenButton.js index b907542cc..255c2f16b 100644 --- a/src/mapml/control/FullscreenButton.js +++ b/src/mapml/control/FullscreenButton.js @@ -1,5 +1,7 @@ -import { Util } from '../utils/Util'; -export var FullscreenButton = L.Control.extend({ +import { Control, DomUtil, DomEvent, Map, Util as LeafletUtil } from 'leaflet'; +import { Util } from '../utils/Util.js'; + +export var FullscreenButton = Control.extend({ options: { position: 'topleft', title: { @@ -18,12 +20,12 @@ export var FullscreenButton = L.Control.extend({ false: locale.btnFullScreen, true: locale.btnExitFullScreen }; - var container = L.DomUtil.create( + var container = DomUtil.create( 'div', 'leaflet-control-fullscreen leaflet-bar leaflet-control' ); - this.link = L.DomUtil.create( + this.link = DomUtil.create( 'a', 'leaflet-control-fullscreen-button leaflet-bar-part', container @@ -35,7 +37,7 @@ export var FullscreenButton = L.Control.extend({ this._map.on('fullscreenchange', this._toggleTitle, this); this._toggleTitle(); - L.DomEvent.on(this.link, 'click', this._click, this); + DomEvent.on(this.link, 'click', this._click, this); return container; }, @@ -45,8 +47,8 @@ export var FullscreenButton = L.Control.extend({ }, _click: function (e) { - L.DomEvent.stopPropagation(e); - L.DomEvent.preventDefault(e); + DomEvent.stopPropagation(e); + DomEvent.preventDefault(e); this._map.toggleFullscreen(this.options); }, @@ -55,7 +57,7 @@ export var FullscreenButton = L.Control.extend({ } }); -L.Map.include({ +Map.include({ isFullscreen: function () { return this._isFullscreen || false; }, @@ -100,13 +102,13 @@ L.Map.include({ }, _enablePseudoFullscreen: function (container) { - L.DomUtil.addClass(container, 'leaflet-pseudo-fullscreen'); + DomUtil.addClass(container, 'leaflet-pseudo-fullscreen'); this._setFullscreen(true); this.fire('fullscreenchange'); }, _disablePseudoFullscreen: function (container) { - L.DomUtil.removeClass(container, 'leaflet-pseudo-fullscreen'); + DomUtil.removeClass(container, 'leaflet-pseudo-fullscreen'); this._setFullscreen(false); this.fire('fullscreenchange'); }, @@ -118,9 +120,9 @@ L.Map.include({ 'mapml-viewer,[is=web-map]' ); if (fullscreen) { - L.DomUtil.addClass(container, 'mapml-fullscreen-on'); + DomUtil.addClass(container, 'mapml-fullscreen-on'); } else { - L.DomUtil.removeClass(container, 'mapml-fullscreen-on'); + DomUtil.removeClass(container, 'mapml-fullscreen-on'); } this.invalidateSize(); }, @@ -138,11 +140,11 @@ L.Map.include({ } }); -L.Map.mergeOptions({ +Map.mergeOptions({ fullscreenControl: false }); -L.Map.addInitHook(function () { +Map.addInitHook(function () { if (this.options.fullscreenControl) { this.fullscreenControl = new FullscreenButton( this.options.fullscreenControl @@ -163,14 +165,14 @@ L.Map.addInitHook(function () { } if (fullscreenchange) { - var onFullscreenChange = L.bind(this._onFullscreenChange, this); + var onFullscreenChange = LeafletUtil.bind(this._onFullscreenChange, this); this.whenReady(function () { - L.DomEvent.on(document, fullscreenchange, onFullscreenChange); + DomEvent.on(document, fullscreenchange, onFullscreenChange); }); this.on('unload', function () { - L.DomEvent.off(document, fullscreenchange, onFullscreenChange); + DomEvent.off(document, fullscreenchange, onFullscreenChange); }); } }); diff --git a/src/mapml/control/GeolocationButton.js b/src/mapml/control/GeolocationButton.js index 779ff3d39..e7c42f53e 100644 --- a/src/mapml/control/GeolocationButton.js +++ b/src/mapml/control/GeolocationButton.js @@ -1,4 +1,7 @@ -export var GeolocationButton = L.Control.extend({ +import { Control } from 'leaflet'; +import { LocateControl } from 'leaflet.locatecontrol'; + +export var GeolocationButton = Control.extend({ options: { position: 'bottomright' }, @@ -10,18 +13,19 @@ export var GeolocationButton = L.Control.extend({ onAdd: function (map) { // customize locate control to focus map after start/stop, so that // featureIndexOverlay is correctly displayed - L.Control.CustomLocate = L.Control.Locate.extend({ + Control.CustomLocate = LocateControl.extend({ start: function () { - L.Control.Locate.prototype.start.call(this); + LocateControl.prototype.start.call(this); map.getContainer().focus(); }, stop: function () { - L.Control.Locate.prototype.stop.call(this); + LocateControl.prototype.stop.call(this); map.getContainer().focus(); } }); let locale = this._getLocale(map); - this.locateControl = new L.Control.CustomLocate({ + + this.locateControl = new Control.CustomLocate({ showPopup: false, strings: { title: locale.btnLocTrackOff diff --git a/src/mapml/control/LayerControl.js b/src/mapml/control/LayerControl.js index 7bf9b5df9..3e1c3a6b0 100644 --- a/src/mapml/control/LayerControl.js +++ b/src/mapml/control/LayerControl.js @@ -1,5 +1,7 @@ -export var LayerControl = L.Control.Layers.extend({ - /* removes 'base' layers as a concept */ +import { Control, DomEvent, DomUtil, setOptions, stamp } from 'leaflet'; + +// Refactored LayerControl to remove global L dependency +export var LayerControl = Control.Layers.extend({ options: { autoZIndex: false, sortLayers: true, @@ -12,10 +14,10 @@ export var LayerControl = L.Control.Layers.extend({ } }, initialize: function (overlays, options) { - L.setOptions(this, options); + setOptions(this, options); // the _layers array contains objects like {layer: layer, name: "name", overlay: true} - // the array index is the id of the layer returned by L.stamp(layer) which I guess is a unique hash + // the array index is the id of the layer returned by stamp(layer) which I guess is a unique hash this._layerControlInputs = []; this._layers = []; this._lastZIndex = 0; @@ -28,13 +30,13 @@ export var LayerControl = L.Control.Layers.extend({ onAdd: function () { this._initLayout(); // Adding event on layer control button - L.DomEvent.on( + DomEvent.on( this._container.getElementsByTagName('a')[0], 'keydown', this._focusFirstLayer, this._container ); - L.DomEvent.on( + DomEvent.on( this._container, 'contextmenu', this._preventDefaultContextMenu, @@ -49,7 +51,7 @@ export var LayerControl = L.Control.Layers.extend({ return this._container; }, onRemove: function (map) { - L.DomEvent.off( + DomEvent.off( this._container.getElementsByTagName('a')[0], 'keydown', this._focusFirstLayer, @@ -76,7 +78,7 @@ export var LayerControl = L.Control.Layers.extend({ return this._map ? this._update() : this; }, removeLayer: function (layer) { - L.Control.Layers.prototype.removeLayer.call(this, layer); + Control.Layers.prototype.removeLayer.call(this, layer); if (this._layers.length === 0) { this._container.setAttribute('hidden', ''); } @@ -105,8 +107,8 @@ export var LayerControl = L.Control.Layers.extend({ return this; } - L.DomUtil.empty(this._baseLayersList); - L.DomUtil.empty(this._overlaysList); + DomUtil.empty(this._baseLayersList); + DomUtil.empty(this._overlaysList); this._layerControlInputs = []; var baseLayersPresent, @@ -123,7 +125,7 @@ export var LayerControl = L.Control.Layers.extend({ this.options.sortFunction(a.layer, b.layer, a.name, b.name) ); } - // --------------------------------------------------> + for (i = 0; i < this._layers.length; i++) { obj = this._layers[i]; this._addItem(obj); @@ -152,7 +154,7 @@ export var LayerControl = L.Control.Layers.extend({ ); this._layerControlInputs.push(obj.input); - obj.input.layerId = L.stamp(obj.layer); + obj.input.layerId = stamp(obj.layer); this._overlaysList.appendChild(layercontrols); return layercontrols; @@ -182,7 +184,7 @@ export var LayerControl = L.Control.Layers.extend({ ) return this; - L.DomUtil.removeClass(this._container, 'leaflet-control-layers-expanded'); + DomUtil.removeClass(this._container, 'leaflet-control-layers-expanded'); if (e.originalEvent?.pointerType === 'touch') { this._container._isExpanded = false; } diff --git a/src/mapml/control/ReloadButton.js b/src/mapml/control/ReloadButton.js index 0ba4a8d68..28e99bf2e 100644 --- a/src/mapml/control/ReloadButton.js +++ b/src/mapml/control/ReloadButton.js @@ -1,4 +1,6 @@ -export var ReloadButton = L.Control.extend({ +import { Control, DomUtil, DomEvent } from 'leaflet'; + +export var ReloadButton = Control.extend({ options: { position: 'topleft' }, @@ -9,18 +11,18 @@ export var ReloadButton = L.Control.extend({ }, onAdd: function (map) { let locale = this._getLocale(map); - let container = L.DomUtil.create('div', 'mapml-reload-button leaflet-bar'); + let container = DomUtil.create('div', 'mapml-reload-button leaflet-bar'); - let link = L.DomUtil.create('button', 'mapml-reload-button', container); + let link = DomUtil.create('button', 'mapml-reload-button', container); link.innerHTML = ""; link.title = locale.cmReload; link.setAttribute('type', 'button'); link.classList.add('mapml-button'); link.setAttribute('aria-label', 'Reload'); - L.DomEvent.disableClickPropagation(link); - L.DomEvent.on(link, 'click', L.DomEvent.stop); - L.DomEvent.on(link, 'click', this._goReload, this); + DomEvent.disableClickPropagation(link); + DomEvent.on(link, 'click', DomEvent.stop); + DomEvent.on(link, 'click', this._goReload, this); this._reloadButton = link; @@ -54,14 +56,14 @@ export var ReloadButton = L.Control.extend({ _updateDisabled: function () { setTimeout(() => { - L.DomUtil.removeClass(this._reloadButton, 'leaflet-disabled'); + DomUtil.removeClass(this._reloadButton, 'leaflet-disabled'); this._reloadButton.setAttribute('aria-disabled', 'false'); if ( this._map && (this._disabled || this._map.options.mapEl._history.length <= 1) ) { - L.DomUtil.addClass(this._reloadButton, 'leaflet-disabled'); + DomUtil.addClass(this._reloadButton, 'leaflet-disabled'); this._reloadButton.setAttribute('aria-disabled', 'true'); } }, 0); diff --git a/src/mapml/control/ScaleBar.js b/src/mapml/control/ScaleBar.js index 7e099001c..d954d6763 100644 --- a/src/mapml/control/ScaleBar.js +++ b/src/mapml/control/ScaleBar.js @@ -1,4 +1,6 @@ -export var ScaleBar = L.Control.Scale.extend({ +import { Control, DomUtil } from 'leaflet'; + +export var ScaleBar = Control.Scale.extend({ options: { maxWidth: 100, updateWhenIdle: true, @@ -12,8 +14,8 @@ export var ScaleBar = L.Control.Scale.extend({ map._container.insertAdjacentHTML('beforeend', outputScale); // initialize _container - this._container = L.DomUtil.create('div', 'mapml-control-scale'); - let scaleControl = L.Control.Scale.prototype.onAdd.call(this, map); + this._container = DomUtil.create('div', 'mapml-control-scale'); + let scaleControl = Control.Scale.prototype.onAdd.call(this, map); this._container.appendChild(scaleControl); this._container.setAttribute('tabindex', 0); this._scaleControl = this; diff --git a/src/mapml/elementSupport/extents/createLayerControlForExtent.js b/src/mapml/elementSupport/extents/createLayerControlForExtent.js index 6671784db..0f502ca20 100644 --- a/src/mapml/elementSupport/extents/createLayerControlForExtent.js +++ b/src/mapml/elementSupport/extents/createLayerControlForExtent.js @@ -1,39 +1,38 @@ +import { DomUtil, SVG, DomEvent, stamp } from 'leaflet'; +import { Util } from '../../utils/Util.js'; + export var createLayerControlExtentHTML = function () { - var extent = L.DomUtil.create('fieldset', 'mapml-layer-extent'), - extentProperties = L.DomUtil.create( + var extent = DomUtil.create('fieldset', 'mapml-layer-extent'), + extentProperties = DomUtil.create( 'div', 'mapml-layer-item-properties', extent ), - extentSettings = L.DomUtil.create( - 'div', - 'mapml-layer-item-settings', - extent - ), - extentLabel = L.DomUtil.create( + extentSettings = DomUtil.create('div', 'mapml-layer-item-settings', extent), + extentLabel = DomUtil.create( 'label', 'mapml-layer-item-toggle', extentProperties ), - input = L.DomUtil.create('input'), - svgExtentControlIcon = L.SVG.create('svg'), - extentControlPath1 = L.SVG.create('path'), - extentControlPath2 = L.SVG.create('path'), - extentNameIcon = L.DomUtil.create('span'), - extentItemControls = L.DomUtil.create( + input = DomUtil.create('input'), + svgExtentControlIcon = SVG.create('svg'), + extentControlPath1 = SVG.create('path'), + extentControlPath2 = SVG.create('path'), + extentNameIcon = DomUtil.create('span'), + extentItemControls = DomUtil.create( 'div', 'mapml-layer-item-controls', extentProperties ), - opacityControl = L.DomUtil.create( + opacityControl = DomUtil.create( 'details', 'mapml-layer-item-details mapml-control-layers', extentSettings ), - extentOpacitySummary = L.DomUtil.create('summary', '', opacityControl), + extentOpacitySummary = DomUtil.create('summary', '', opacityControl), mapEl = this.getMapEl(), layerEl = this.getLayerEl(), - opacity = L.DomUtil.create('input', '', opacityControl); + opacity = DomUtil.create('input', '', opacityControl); extentSettings.hidden = true; extent.setAttribute('aria-grabbed', 'false'); @@ -59,7 +58,7 @@ export var createLayerControlExtentHTML = function () { extentSettings.appendChild(frag); } - let removeExtentButton = L.DomUtil.create( + let removeExtentButton = DomUtil.create( 'button', 'mapml-layer-item-remove-control', extentItemControls @@ -74,7 +73,7 @@ export var createLayerControlExtentHTML = function () { this.remove(); }); - let extentsettingsButton = L.DomUtil.create( + let extentsettingsButton = DomUtil.create( 'button', 'mapml-layer-item-settings-control', extentItemControls @@ -83,7 +82,7 @@ export var createLayerControlExtentHTML = function () { extentsettingsButton.title = mapEl.locale.lmExtentSettings; extentsettingsButton.setAttribute('aria-expanded', false); extentsettingsButton.classList.add('mapml-button'); - L.DomEvent.on( + DomEvent.on( extentsettingsButton, 'click', (e) => { @@ -104,14 +103,14 @@ export var createLayerControlExtentHTML = function () { extentNameIcon.appendChild(svgExtentControlIcon); extentOpacitySummary.innerText = mapEl.locale.lcOpacity; extentOpacitySummary.id = - 'mapml-extent-item-opacity-' + L.stamp(extentOpacitySummary); + 'mapml-extent-item-opacity-' + stamp(extentOpacitySummary); opacity.setAttribute('type', 'range'); opacity.setAttribute('min', '0'); opacity.setAttribute('max', '1.0'); opacity.setAttribute('step', '0.1'); opacity.setAttribute( 'aria-labelledby', - 'mapml-extent-item-opacity-' + L.stamp(extentOpacitySummary) + 'mapml-extent-item-opacity-' + stamp(extentOpacitySummary) ); const changeOpacity = function (e) { if (e && e.target && e.target.value >= 0 && e.target.value <= 1.0) { @@ -122,7 +121,7 @@ export var createLayerControlExtentHTML = function () { opacity.value = this._extentLayer._container.style.opacity || '1.0'; opacity.addEventListener('change', changeOpacity.bind(this)); - var extentItemNameSpan = L.DomUtil.create( + var extentItemNameSpan = DomUtil.create( 'span', 'mapml-extent-item-name', extentLabel @@ -137,7 +136,7 @@ export var createLayerControlExtentHTML = function () { this._layerControlCheckbox = input; input.addEventListener('change', changeCheck.bind(this)); extentItemNameSpan.id = - 'mapml-extent-item-name-{' + L.stamp(extentItemNameSpan) + '}'; + 'mapml-extent-item-name-{' + stamp(extentItemNameSpan) + '}'; extent.setAttribute('aria-labelledby', extentItemNameSpan.id); extentItemNameSpan.extent = this; diff --git a/src/mapml/elementSupport/inputs/locationInput.js b/src/mapml/elementSupport/inputs/locationInput.js index 3d0a4a9ff..1d43bc2ce 100644 --- a/src/mapml/elementSupport/inputs/locationInput.js +++ b/src/mapml/elementSupport/inputs/locationInput.js @@ -1,4 +1,6 @@ -import { Util } from '../../utils/Util'; +import { Point } from 'leaflet'; + +import { Util } from '../../utils/Util.js'; export class LocationInput { constructor(name, position, axis, units, min, max, rel, layer) { this.name = name; @@ -101,7 +103,7 @@ export class LocationInput { let obj = []; for (let j = tileRange.min.y; j <= tileRange.max.y; j++) { for (let i = tileRange.min.x; i <= tileRange.max.x; i++) { - const coords = new L.Point(i, j); + const coords = new Point(i, j); coords.z = templatedTileLayer._tileZoom; obj.push(coords); } diff --git a/src/mapml/elementSupport/layers/createLayerControlForLayer.js b/src/mapml/elementSupport/layers/createLayerControlForLayer.js index 247871930..44e3388b9 100644 --- a/src/mapml/elementSupport/layers/createLayerControlForLayer.js +++ b/src/mapml/elementSupport/layers/createLayerControlForLayer.js @@ -1,42 +1,40 @@ +import { DomUtil, SVG, DomEvent, stamp } from 'leaflet'; export var createLayerControlHTML = async function () { - var fieldset = L.DomUtil.create('fieldset', 'mapml-layer-item'), - input = L.DomUtil.create('input'), - layerItemName = L.DomUtil.create('span', 'mapml-layer-item-name'), - settingsButtonNameIcon = L.DomUtil.create('span'), - layerItemProperty = L.DomUtil.create( + var fieldset = DomUtil.create('fieldset', 'mapml-layer-item'), + input = DomUtil.create('input'), + layerItemName = DomUtil.create('span', 'mapml-layer-item-name'), + settingsButtonNameIcon = DomUtil.create('span'), + layerItemProperty = DomUtil.create( 'div', 'mapml-layer-item-properties', fieldset ), - layerItemSettings = L.DomUtil.create( + layerItemSettings = DomUtil.create( 'div', 'mapml-layer-item-settings', fieldset ), - itemToggleLabel = L.DomUtil.create( + itemToggleLabel = DomUtil.create( 'label', 'mapml-layer-item-toggle', layerItemProperty ), - layerItemControls = L.DomUtil.create( + layerItemControls = DomUtil.create( 'div', 'mapml-layer-item-controls', layerItemProperty ), - opacityControl = L.DomUtil.create( + opacityControl = DomUtil.create( 'details', 'mapml-layer-item-opacity mapml-control-layers', layerItemSettings ), - opacity = L.DomUtil.create('input'), - opacityControlSummary = L.DomUtil.create('summary'), - svgSettingsControlIcon = L.SVG.create('svg'), - settingsControlPath1 = L.SVG.create('path'), - settingsControlPath2 = L.SVG.create('path'), - extentsFieldset = L.DomUtil.create( - 'fieldset', - 'mapml-layer-grouped-extents' - ), + opacity = DomUtil.create('input'), + opacityControlSummary = DomUtil.create('summary'), + svgSettingsControlIcon = SVG.create('svg'), + settingsControlPath1 = SVG.create('path'), + settingsControlPath2 = SVG.create('path'), + extentsFieldset = DomUtil.create('fieldset', 'mapml-layer-grouped-extents'), mapEl = this.parentNode; // append the paths in svg for the remove layer and toggle icons @@ -56,7 +54,7 @@ export var createLayerControlHTML = async function () { layerItemSettings.hidden = true; settingsButtonNameIcon.setAttribute('aria-hidden', true); - let removeControlButton = L.DomUtil.create( + let removeControlButton = DomUtil.create( 'button', 'mapml-layer-item-remove-control', layerItemControls @@ -65,8 +63,8 @@ export var createLayerControlHTML = async function () { removeControlButton.title = mapEl.locale.lmRemoveLayer; removeControlButton.innerHTML = ""; removeControlButton.classList.add('mapml-button'); - L.DomEvent.on(removeControlButton, 'click', L.DomEvent.stop); - L.DomEvent.on( + DomEvent.on(removeControlButton, 'click', DomEvent.stop); + DomEvent.on( removeControlButton, 'click', (e) => { @@ -101,7 +99,7 @@ export var createLayerControlHTML = async function () { this._layer ); - let itemSettingControlButton = L.DomUtil.create( + let itemSettingControlButton = DomUtil.create( 'button', 'mapml-layer-item-settings-control', layerItemControls @@ -110,7 +108,7 @@ export var createLayerControlHTML = async function () { itemSettingControlButton.title = mapEl.locale.lmLayerSettings; itemSettingControlButton.setAttribute('aria-expanded', false); itemSettingControlButton.classList.add('mapml-button'); - L.DomEvent.on( + DomEvent.on( itemSettingControlButton, 'click', (e) => { @@ -148,10 +146,10 @@ export var createLayerControlHTML = async function () { } else { layerItemName.innerHTML = this._layer._title; } - layerItemName.id = 'mapml-layer-item-name-{' + L.stamp(layerItemName) + '}'; + layerItemName.id = 'mapml-layer-item-name-{' + stamp(layerItemName) + '}'; opacityControlSummary.innerText = mapEl.locale.lcOpacity; opacityControlSummary.id = - 'mapml-layer-item-opacity-' + L.stamp(opacityControlSummary); + 'mapml-layer-item-opacity-' + stamp(opacityControlSummary); opacityControl.appendChild(opacityControlSummary); opacityControl.appendChild(opacity); opacity.setAttribute('type', 'range'); @@ -161,7 +159,7 @@ export var createLayerControlHTML = async function () { opacity.setAttribute('step', '0.1'); opacity.setAttribute( 'aria-labelledby', - 'mapml-layer-item-opacity-' + L.stamp(opacityControlSummary) + 'mapml-layer-item-opacity-' + stamp(opacityControlSummary) ); const changeOpacity = function (e) { diff --git a/src/mapml/features/featureRenderer.js b/src/mapml/features/featureRenderer.js index d2e058820..ca529158c 100644 --- a/src/mapml/features/featureRenderer.js +++ b/src/mapml/features/featureRenderer.js @@ -1,21 +1,23 @@ -import { Util } from '../utils/Util'; +import { SVG, DomUtil, stamp } from 'leaflet'; + +import { Util } from '../utils/Util.js'; /** * Returns a new Feature Renderer * @param {Object} options - Options for the renderer * @returns {*} */ -export var FeatureRenderer = L.SVG.extend({ +export var FeatureRenderer = SVG.extend({ /** - * Override method of same name from L.SVG, use the this._container property + * Override method of same name from SVG, use the this._container property * to set up the role="none presentation" on featureGroupu container, * per this recommendation: - * https://github.com/Maps4HTML/MapML.js/pull/471#issuecomment-845192246 + * https://github.com/Maps4HTML/MapMjs/pull/471#issuecomment-845192246 * @private overrides ancestor method so that we have a _container to work with */ _initContainer: function () { // call the method we're overriding, per https://leafletjs.com/examples/extending/extending-1-classes.html#methods-of-the-parent-class // note you have to pass 'this' as the first arg - L.SVG.prototype._initContainer.call(this); + SVG.prototype._initContainer.call(this); // knowing that the previous method call creates the this._container, we // access it and set the role="none presetation" which suppresses the // announcement of "Graphic" on each feature focus. @@ -30,13 +32,13 @@ export var FeatureRenderer = L.SVG.extend({ */ _initPath: function (layer, stampLayer = true) { if (layer._outline) { - let outlinePath = L.SVG.create('path'); + let outlinePath = SVG.create('path'); if (layer.options.className) - L.DomUtil.addClass( + DomUtil.addClass( outlinePath, layer.featureAttributes.class || layer.options.className ); - L.DomUtil.addClass(outlinePath, 'mapml-feature-outline'); + DomUtil.addClass(outlinePath, 'mapml-feature-outline'); outlinePath.style.fill = 'none'; layer.outlinePath = outlinePath; } @@ -67,8 +69,8 @@ export var FeatureRenderer = L.SVG.extend({ this._updateStyle(layer); } if (stampLayer) { - let stamp = L.stamp(layer); - this._layers[stamp] = layer; + let s = stamp(layer); + this._layers[s] = layer; } }, @@ -88,7 +90,7 @@ export var FeatureRenderer = L.SVG.extend({ interactive = false, attr = undefined ) { - let p = L.SVG.create('path'); + let p = SVG.create('path'); ring.path = p; if (!attr) { if (title) p.setAttribute('aria-label', title); @@ -99,10 +101,10 @@ export var FeatureRenderer = L.SVG.extend({ } } if (ring.cls || cls) { - L.DomUtil.addClass(p, ring.cls || cls); + DomUtil.addClass(p, ring.cls || cls); } if (interactive) { - L.DomUtil.addClass(p, 'leaflet-interactive'); + DomUtil.addClass(p, 'leaflet-interactive'); } }, @@ -165,16 +167,16 @@ export var FeatureRenderer = L.SVG.extend({ for (let p of layer._parts) { if (p.path) { layer.removeInteractiveTarget(p.path); - L.DomUtil.remove(p.path); + DomUtil.remove(p.path); } for (let subP of p.subrings) { - if (subP.path) L.DomUtil.remove(subP.path); + if (subP.path) DomUtil.remove(subP.path); } } - if (layer.outlinePath) L.DomUtil.remove(layer.outlinePath); + if (layer.outlinePath) DomUtil.remove(layer.outlinePath); layer.removeInteractiveTarget(layer.group); - L.DomUtil.remove(layer.group); - delete this._layers[L.stamp(layer)]; + DomUtil.remove(layer.group); + delete this._layers[stamp(layer)]; }, /** @@ -201,7 +203,7 @@ export var FeatureRenderer = L.SVG.extend({ /** * Generates the marker d attribute for a given point - * @param {L.Point} p - The point of the marker + * @param {Point} p - The point of the marker * @returns {string} * @private */ @@ -302,7 +304,7 @@ export var FeatureRenderer = L.SVG.extend({ /** * Generates the d string of a feature part - * @param {L.Point[]} rings - The points making up a given part of a feature + * @param {Point[]} rings - The points making up a given part of a feature * @param {boolean} closed - Whether a feature is closed or not * @returns {string} */ diff --git a/src/mapml/features/geometry.js b/src/mapml/features/geometry.js index 3617155a2..f433b5a33 100644 --- a/src/mapml/features/geometry.js +++ b/src/mapml/features/geometry.js @@ -1,6 +1,8 @@ -import { Path, path } from './path'; +import { FeatureGroup, LayerGroup, DomUtil, DomEvent, bounds } from 'leaflet'; -export var Geometry = L.FeatureGroup.extend({ +import { Path, path } from './path.js'; + +export var Geometry = FeatureGroup.extend({ /** * Initialize the feature group * @param {M.Path[]} layers @@ -13,7 +15,7 @@ export var Geometry = L.FeatureGroup.extend({ options ); - L.LayerGroup.prototype.initialize.call(this, layers, options); + LayerGroup.prototype.initialize.call(this, layers, options); this._featureEl = this.options.mapmlFeature; this.layerBounds = options.layerBounds; @@ -26,7 +28,7 @@ export var Geometry = L.FeatureGroup.extend({ (this.options.onEachFeature && this.options.properties) || this.options.link ) { - L.DomUtil.addClass(this.options.group, 'leaflet-interactive'); + DomUtil.addClass(this.options.group, 'leaflet-interactive'); if (this.options.link) { Path.prototype.attachLinkHandler.call( this, @@ -43,7 +45,7 @@ export var Geometry = L.FeatureGroup.extend({ } } - L.DomEvent.on(this.options.group, 'keyup keydown', this._handleFocus, this); + DomEvent.on(this.options.group, 'keyup keydown', this._handleFocus, this); this.options.group.setAttribute('aria-label', this.options.accessibleTitle); if (this.options.featureID) this.options.group.setAttribute('data-fid', this.options.featureID); @@ -53,7 +55,7 @@ export var Geometry = L.FeatureGroup.extend({ }, onAdd: function (map) { - L.LayerGroup.prototype.onAdd.call(this, map); + LayerGroup.prototype.onAdd.call(this, map); this.updateInteraction(); }, @@ -104,7 +106,7 @@ export var Geometry = L.FeatureGroup.extend({ /** * Handler for focus events - * @param {L.DOMEvent} e - Event that occurred + * @param {DOMEvent} e - Event that occurred * @private */ _handleFocus: function (e) { @@ -117,7 +119,7 @@ export var Geometry = L.FeatureGroup.extend({ // Down/right arrow keys replicate tabbing through the feature index // Up/left arrow keys replicate shift-tabbing through the feature index if (e.keyCode === 37 || e.keyCode === 38) { - L.DomEvent.stop(e); + DomEvent.stop(e); this._map.featureIndex.inBoundFeatures[index].path.setAttribute( 'tabindex', -1 @@ -133,7 +135,7 @@ export var Geometry = L.FeatureGroup.extend({ this._map.featureIndex.currentIndex--; } } else if (e.keyCode === 39 || e.keyCode === 40) { - L.DomEvent.stop(e); + DomEvent.stop(e); this._map.featureIndex.inBoundFeatures[index].path.setAttribute( 'tabindex', -1 @@ -184,7 +186,7 @@ export var Geometry = L.FeatureGroup.extend({ } else if (e.keyCode === 13 || e.keyCode === 32) { this.closeTooltip(); if (!this.options.link && this.options.onEachFeature) { - L.DomEvent.stop(e); + DomEvent.stop(e); this.openPopup(); } } else { @@ -200,7 +202,7 @@ export var Geometry = L.FeatureGroup.extend({ if (!layer.options.link && layer.options.interactive) { this.options.onEachFeature(this.options.properties, layer); } - L.FeatureGroup.prototype.addLayer.call(this, layer); + FeatureGroup.prototype.addLayer.call(this, layer); }, /** @@ -209,7 +211,7 @@ export var Geometry = L.FeatureGroup.extend({ * @private */ _previousFeature: function (e) { - L.DomEvent.stop(e); + DomEvent.stop(e); this._map.featureIndex.currentIndex = Math.max( this._map.featureIndex.currentIndex - 1, 0 @@ -228,7 +230,7 @@ export var Geometry = L.FeatureGroup.extend({ * @private */ _nextFeature: function (e) { - L.DomEvent.stop(e); + DomEvent.stop(e); this._map.featureIndex.currentIndex = Math.min( this._map.featureIndex.currentIndex + 1, this._map.featureIndex.inBoundFeatures.length - 1 @@ -242,16 +244,16 @@ export var Geometry = L.FeatureGroup.extend({ }, getPCRSCenter: function () { - let bounds; + let bnds; for (let l in this._layers) { let layer = this._layers[l]; - if (!bounds) { - bounds = L.bounds(layer.getPCRSCenter(), layer.getPCRSCenter()); + if (!bnds) { + bnds = bounds(layer.getPCRSCenter(), layer.getPCRSCenter()); } else { - bounds.extend(layer.getPCRSCenter()); + bnds.extend(layer.getPCRSCenter()); } } - return bounds.getCenter(); + return bnds.getCenter(); } }); diff --git a/src/mapml/features/path.js b/src/mapml/features/path.js index 2ca213242..c590faf2c 100644 --- a/src/mapml/features/path.js +++ b/src/mapml/features/path.js @@ -1,6 +1,14 @@ -import { Util } from '../utils/Util'; +import { + Path as LeafletPath, + setOptions, + DomEvent, + point, + bounds +} from 'leaflet'; + +import { Util } from '../utils/Util.js'; /** - * M.Path is a extension of L.Path that understands mapml feature markup + * M.Path is a extension of Path that understands mapml feature markup * It converts the markup to the following structure (abstract enough to encompass all feature types) for example: * this._outlinePath = HTMLElement; * this._parts = [ @@ -19,7 +27,7 @@ import { Util } from '../utils/Util'; * ... * ]; */ -export var Path = L.Path.extend({ +export var Path = LeafletPath.extend({ /** * Initializes the M.Path * @param {HTMLElement} markup - The markup representation of the feature @@ -33,7 +41,7 @@ export var Path = L.Path.extend({ if (options.wrappers.length > 0) options = Object.assign(this._convertWrappers(options.wrappers), options); - L.setOptions(this, options); + setOptions(this, options); this.group = this.options.group; this.options.interactive = @@ -69,7 +77,7 @@ export var Path = L.Path.extend({ elem.classList.add('map-a'); if (link.visited) elem.classList.add('map-a-visited'); elem.mousedown = (e) => (dragStart = { x: e.clientX, y: e.clientY }); - L.DomEvent.on(elem, 'mousedown', elem.mousedown, this); + DomEvent.on(elem, 'mousedown', elem.mousedown, this); elem.mouseup = (e) => { if (e.button !== 0) return; // don't trigger when button isn't left click let onTop = true, @@ -100,12 +108,12 @@ export var Path = L.Path.extend({ } } }; - L.DomEvent.on(elem, 'mouseup', elem.mouseup, this); - L.DomEvent.on( + DomEvent.on(elem, 'mouseup', elem.mouseup, this); + DomEvent.on( elem, 'keypress', (e) => { - L.DomEvent.stop(e); + DomEvent.stop(e); if (e.keyCode === 13 || e.keyCode === 32) { link.visited = true; elem.setAttribute('stroke', '#6c00a2'); @@ -115,7 +123,7 @@ export var Path = L.Path.extend({ }, this ); - L.DomEvent.on( + DomEvent.on( elem, 'mouseenter keyup', (e) => { @@ -133,7 +141,7 @@ export var Path = L.Path.extend({ }, this ); - L.DomEvent.on( + DomEvent.on( elem, 'mouseout keydown mousedown', (e) => { @@ -151,7 +159,7 @@ export var Path = L.Path.extend({ this._map.getContainer().removeChild(container); } function addMouseHandler() { - L.DomEvent.on( + DomEvent.on( this._map.getContainer(), 'mouseout mouseenter click', handleMouse, @@ -160,7 +168,7 @@ export var Path = L.Path.extend({ } leafletLayer.on('remove', removeMouseHandler, leafletLayer); function removeMouseHandler() { - L.DomEvent.off(this._map.getContainer(), { + DomEvent.off(this._map.getContainer(), { mouseout: handleMouse, mouseenter: handleMouse, click: handleMouse @@ -170,8 +178,8 @@ export var Path = L.Path.extend({ /** * Updates internal structure of the feature to the new map state, the structure can be found in this._parts - * @param {L.Map} addedMap - The map that the feature is part of, can be left blank in the case of static features - * @param {L.Point} tileOrigin - The tile origin for the feature, if blank then it takes the maps pixel origin in the function + * @param {Map} addedMap - The map that the feature is part of, can be left blank in the case of static features + * @param {Point} tileOrigin - The tile origin for the feature, if blank then it takes the maps pixel origin in the function * @param {int} zoomingTo - The zoom the map is animating to, if left blank then it takes the map zoom, its provided because in templated tiles zoom is delayed * @private */ @@ -196,11 +204,11 @@ export var Path = L.Path.extend({ /** * Converts the PCRS points to pixel points that can be used to create the SVG - * @param {L.Point[][]} r - Is the rings of a feature, either the mainParts, subParts or outline - * @param {L.Map} map - The map that the feature is part of - * @param {L.Point} origin - The origin used to calculate the pixel points + * @param {Point[][]} r - Is the rings of a feature, either the mainParts, subParts or outline + * @param {Map} map - The map that the feature is part of + * @param {Point} origin - The origin used to calculate the pixel points * @param {int} zoom - The current zoom level of the map - * @returns {L.Point[][]} + * @returns {Point[][]} * @private */ _convertRing: function (r, map, origin, zoom) { @@ -211,7 +219,7 @@ export var Path = L.Path.extend({ let interm = []; for (let p of sub.points) { let conv = map.options.crs.transformation.transform(p, scale); - interm.push(L.point(conv.x, conv.y)._subtract(origin).round()); + interm.push(point(conv.x, conv.y)._subtract(origin).round()); } parts.push(interm); } @@ -284,11 +292,11 @@ export var Path = L.Path.extend({ if (subRings.length > 0) this._parts[0].subrings = this._parts[0].subrings.concat(subRings); } else if (this.type === 'MAP-MULTIPOINT') { - for (let point of ring[0].points.concat(subRings)) { + for (let pt of ring[0].points.concat(subRings)) { this._parts.push({ - rings: [{ points: [point] }], + rings: [{ points: [pt] }], subrings: [], - cls: `${point.cls || ''} ${this.options.className || ''}`.trim() + cls: `${pt.cls || ''} ${this.options.className || ''}`.trim() }); } } else { @@ -390,24 +398,24 @@ export var Path = L.Path.extend({ let noSpan = coords.textContent.replace(/(<([^>]+)>)/gi, ''), pairs = noSpan.trim().match(/(\S+\s+\S+)/gim), local = [], - bounds; + bnds; for (let p of pairs) { let numPair = []; p.split(/\s+/gim).forEach(Util._parseNumber, numPair); - let point = Util.pointToPCRSPoint( - L.point(numPair), + let pt = Util.pointToPCRSPoint( + point(numPair), this.options.zoom, this.options.projection, this.options.nativeCS ); - local.push(point); - bounds = bounds ? bounds.extend(point) : L.bounds(point, point); + local.push(pt); + bnds = bnds ? bnds.extend(pt) : bounds(pt, pt); } if (this._bounds) { - this._bounds.extend(bounds.min); - this._bounds.extend(bounds.max); + this._bounds.extend(bnds.min); + this._bounds.extend(bnds.max); } else { - this._bounds = bounds; + this._bounds = bnds; } if (isFirst) { main.push({ points: local }); @@ -422,7 +430,7 @@ export var Path = L.Path.extend({ } subParts.unshift({ points: local, - center: bounds.getCenter(), + center: bnds.getCenter(), cls: `${cls || ''} ${wrapperAttr.className || ''}`.trim(), attr: attrMap, link: wrapperAttr.link, @@ -454,7 +462,7 @@ export var Path = L.Path.extend({ /** * Returns the center of the entire feature - * @returns {L.Point} + * @returns {Point} */ getCenter: function () { if (!this._bounds) return null; diff --git a/src/mapml/handlers/AnnounceMovement.js b/src/mapml/handlers/AnnounceMovement.js index 820da48e3..5d0c06bf5 100644 --- a/src/mapml/handlers/AnnounceMovement.js +++ b/src/mapml/handlers/AnnounceMovement.js @@ -1,5 +1,6 @@ -import { Util } from '../utils/Util'; -export var AnnounceMovement = L.Handler.extend({ +import { Handler } from 'leaflet'; +import { Util } from '../utils/Util.js'; +export var AnnounceMovement = Handler.extend({ addHooks: function () { this._map.on({ layeradd: this.totalBounds, diff --git a/src/mapml/handlers/ContextMenu.js b/src/mapml/handlers/ContextMenu.js index 628d70e93..d6750c689 100644 --- a/src/mapml/handlers/ContextMenu.js +++ b/src/mapml/handlers/ContextMenu.js @@ -1,4 +1,13 @@ -import { Util } from '../utils/Util'; +import { + Handler, + Browser, + DomUtil, + DomEvent, + point, + stamp, + extend +} from 'leaflet'; +import { Util } from '../utils/Util.js'; /* MIT License related to portions of M.ContextMenu Copyright (c) 2017 adam.ratcliffe@gmail.com @@ -9,10 +18,10 @@ The above copyright notice and this permission notice shall be included in all c */ /* global M, KeyboardEvent */ -export var ContextMenu = L.Handler.extend({ - _touchstart: L.Browser.msPointer +export var ContextMenu = Handler.extend({ + _touchstart: Browser.msPointer ? 'MSPointerDown' - : L.Browser.pointer + : Browser.pointer ? 'pointerdown' : 'touchstart', _getLocale: function (map) { @@ -21,7 +30,7 @@ export var ContextMenu = L.Handler.extend({ : M.options.locale; }, initialize: function (map) { - L.Handler.prototype.initialize.call(this, map); + Handler.prototype.initialize.call(this, map); let locale = this._getLocale(map); this.activeIndex = 0; //current fous index on menu this.excludedIndices = [4, 7]; //menu indexes that are -------- @@ -166,7 +175,7 @@ export var ContextMenu = L.Handler.extend({ this._mapMenuVisible = false; this._keyboardEvent = false; - this._container = L.DomUtil.create( + this._container = DomUtil.create( 'div', 'mapml-contextmenu', map.getContainer() @@ -198,7 +207,7 @@ export var ContextMenu = L.Handler.extend({ this._items[CTXCOPY] ); - this._copySubMenu = L.DomUtil.create( + this._copySubMenu = DomUtil.create( 'div', 'mapml-contextmenu mapml-submenu', this._container @@ -251,7 +260,7 @@ export var ContextMenu = L.Handler.extend({ this._items[CTXVWSRC] ); - this._layerMenu = L.DomUtil.create( + this._layerMenu = DomUtil.create( 'div', 'mapml-contextmenu mapml-layer-menu', map.getContainer() @@ -260,7 +269,7 @@ export var ContextMenu = L.Handler.extend({ this._createItem(this._layerMenu, this._layerItems[LYRZOOMTO]); this._createItem(this._layerMenu, this._layerItems[LYRCOPY]); - this._extentLayerMenu = L.DomUtil.create( + this._extentLayerMenu = DomUtil.create( 'div', 'mapml-contextmenu mapml-extent-menu', map.getContainer() @@ -269,18 +278,18 @@ export var ContextMenu = L.Handler.extend({ this._createItem(this._extentLayerMenu, this._extentLayerItems[LYRZOOMTO]); this._createItem(this._extentLayerMenu, this._extentLayerItems[LYRCOPY]); - L.DomEvent.on(this._container, 'click', L.DomEvent.stop) - .on(this._container, 'mousedown', L.DomEvent.stop) - .on(this._container, 'dblclick', L.DomEvent.stop) - .on(this._container, 'contextmenu', L.DomEvent.stop) - .on(this._layerMenu, 'click', L.DomEvent.stop) - .on(this._layerMenu, 'mousedown', L.DomEvent.stop) - .on(this._layerMenu, 'dblclick', L.DomEvent.stop) - .on(this._layerMenu, 'contextmenu', L.DomEvent.stop) - .on(this._extentLayerMenu, 'click', L.DomEvent.stop) - .on(this._extentLayerMenu, 'mousedown', L.DomEvent.stop) - .on(this._extentLayerMenu, 'dblclick', L.DomEvent.stop) - .on(this._extentLayerMenu, 'contextmenu', L.DomEvent.stop); + DomEvent.on(this._container, 'click', DomEvent.stop) + .on(this._container, 'mousedown', DomEvent.stop) + .on(this._container, 'dblclick', DomEvent.stop) + .on(this._container, 'contextmenu', DomEvent.stop) + .on(this._layerMenu, 'click', DomEvent.stop) + .on(this._layerMenu, 'mousedown', DomEvent.stop) + .on(this._layerMenu, 'dblclick', DomEvent.stop) + .on(this._layerMenu, 'contextmenu', DomEvent.stop) + .on(this._extentLayerMenu, 'click', DomEvent.stop) + .on(this._extentLayerMenu, 'mousedown', DomEvent.stop) + .on(this._extentLayerMenu, 'dblclick', DomEvent.stop) + .on(this._extentLayerMenu, 'contextmenu', DomEvent.stop); this.t = document.createElement('template'); this.t.innerHTML = ` @@ -300,15 +309,15 @@ export var ContextMenu = L.Handler.extend({ addHooks: function () { var container = this._map.getContainer(); - L.DomEvent.on(container, 'mouseleave', this._hide, this).on( + DomEvent.on(container, 'mouseleave', this._hide, this).on( document, 'keydown', this._onKeyDown, this ); - if (L.Browser.touch) { - L.DomEvent.on(document, this._touchstart, this._hide, this); + if (Browser.touch) { + DomEvent.on(document, this._touchstart, this._hide, this); } this._map.on( @@ -324,15 +333,15 @@ export var ContextMenu = L.Handler.extend({ removeHooks: function () { var container = this._map.getContainer(); - L.DomEvent.off(container, 'mouseleave', this._hide, this).off( + DomEvent.off(container, 'mouseleave', this._hide, this).off( document, 'keydown', this._onKeyDown, this ); - if (L.Browser.touch) { - L.DomEvent.off(document, this._touchstart, this._hide, this); + if (Browser.touch) { + DomEvent.off(document, this._touchstart, this._hide, this); } this._map.off( @@ -567,8 +576,8 @@ export var ContextMenu = L.Handler.extend({ _copyTCRS: function (e) { let mapEl = this.options.mapEl, click = this.contextMenu._clickEvent, - point = mapEl._map.project(click.latlng), - pt = { x: point.x.toFixed(), y: point.y.toFixed() }, + pt0 = mapEl._map.project(click.latlng), + pt = { x: pt0.x.toFixed(), y: pt0.y.toFixed() }, projection = mapEl.projection, feature = this.contextMenu.t.content.firstElementChild.cloneNode(true), caption = feature.querySelector('map-featurecaption'), @@ -589,7 +598,7 @@ export var ContextMenu = L.Handler.extend({ _copyTileMatrix: function (e) { let mapEl = this.options.mapEl, click = this.contextMenu._clickEvent, - point = mapEl._map.project(click.latlng), + pt = mapEl._map.project(click.latlng), tileSize = mapEl._map.options.crs.options.crs.tile.bounds.max.x, projection = mapEl.projection, feature = this.contextMenu.t.content.firstElementChild.cloneNode(true), @@ -603,8 +612,8 @@ export var ContextMenu = L.Handler.extend({ geom.setAttribute('cs', 'gcrs'); caption.textContent = `Copied ${projection} tilematrix location (not implemented yet)`; h2.textContent = `Copied ${projection} tilematrix location (not implemented yet)`; - div.textContent = `${Math.trunc(point.x / tileSize)} ${Math.trunc( - point.y / tileSize + div.textContent = `${Math.trunc(pt.x / tileSize)} ${Math.trunc( + pt.y / tileSize )}`; coords.textContent = `${click.latlng.lng.toFixed( 6 @@ -644,11 +653,11 @@ export var ContextMenu = L.Handler.extend({ // method returns meters, confusingly: // https://leafletjs.com/reference.html#map-project // https://leafletjs.com/reference.html#crs-project - point = mapEl._map.project(click.latlng), + pt0 = mapEl._map.project(click.latlng), tileSize = mapEl._map.options.crs.options.crs.tile.bounds.max.x, - pointX = point.x % tileSize, - pointY = point.y % tileSize, - pt = L.point(pointX, pointY).trunc(), + pointX = pt0.x % tileSize, + pointY = pt0.y % tileSize, + pt = point(pointX, pointY).trunc(), projection = mapEl.projection, feature = this.contextMenu.t.content.firstElementChild.cloneNode(true), caption = feature.querySelector('map-featurecaption'), @@ -697,21 +706,21 @@ export var ContextMenu = L.Handler.extend({ _copyAllCoords: function (e) { let mapEl = this.options.mapEl, click = this.contextMenu._clickEvent, - point = mapEl._map.project(click.latlng), + pt0 = mapEl._map.project(click.latlng), tileSize = mapEl._map.options.crs.options.crs.tile.bounds.max.x, - pointX = point.x % tileSize, - pointY = point.y % tileSize, + pointX = pt0.x % tileSize, + pointY = pt0.y % tileSize, scale = mapEl._map.options.crs.scale(+mapEl.zoom), - pcrs = mapEl._map.options.crs.transformation.untransform(point, scale); + pcrs = mapEl._map.options.crs.transformation.untransform(pt0, scale); let allData = `z:${mapEl.zoom}\n`; allData += `tile: i:${Math.trunc(pointX)}, j:${Math.trunc(pointY)}\n`; allData += `tilematrix: column:${Math.trunc( - point.x / tileSize - )}, row:${Math.trunc(point.y / tileSize)}\n`; + pt0.x / tileSize + )}, row:${Math.trunc(pt0.y / tileSize)}\n`; allData += `map: i:${Math.trunc(click.containerPoint.x)}, j:${Math.trunc( click.containerPoint.y )}\n`; - allData += `tcrs: x:${Math.trunc(point.x)}, y:${Math.trunc(point.y)}\n`; + allData += `tcrs: x:${Math.trunc(pt0.x)}, y:${Math.trunc(pt0.y)}\n`; allData += `pcrs: easting:${pcrs.x.toFixed(2)}, northing:${pcrs.y.toFixed( 2 )}\n`; @@ -745,22 +754,22 @@ export var ContextMenu = L.Handler.extend({ el.setAttribute('aria-controls', 'mapml-copy-submenu'); } - L.DomEvent.on(el, 'mouseover', this._onItemMouseOver, this) + DomEvent.on(el, 'mouseover', this._onItemMouseOver, this) .on(el, 'mouseout', this._onItemMouseOut, this) - .on(el, 'mousedown', L.DomEvent.stopPropagation) + .on(el, 'mousedown', DomEvent.stopPropagation) .on(el, 'click', callback); - if (L.Browser.touch) { - L.DomEvent.on(el, this._touchstart, L.DomEvent.stopPropagation); + if (Browser.touch) { + DomEvent.on(el, this._touchstart, DomEvent.stopPropagation); } // Devices without a mouse fire "mouseover" on tap, but never “mouseout" - if (!L.Browser.pointer) { - L.DomEvent.on(el, 'click', this._onItemMouseOut, this); + if (!Browser.pointer) { + DomEvent.on(el, 'click', this._onItemMouseOut, this); } return { - id: L.Util.stamp(el), + id: stamp(el), el: el, callback: callback }; @@ -775,7 +784,7 @@ export var ContextMenu = L.Handler.extend({ ); return { - id: L.Util.stamp(el), + id: stamp(el), el: el }; }, @@ -867,7 +876,7 @@ export var ContextMenu = L.Handler.extend({ // use a keyboard Shift+F10 to display the context menu; this appears // to be because blink returns a PointerEvent of type==='contextmenu', // while gecko returns an object (for e.originalEvent). - if (L.Browser.gecko) { + if (Browser.gecko) { const getCenter = function (el) { let w = el.getBoundingClientRect().width; let h = el.getBoundingClientRect().height; @@ -901,7 +910,7 @@ export var ContextMenu = L.Handler.extend({ _showAtPoint: function (pt, data, container) { if (this._items.length) { - let event = L.extend(data || {}, { contextmenu: this }); + let event = extend(data || {}, { contextmenu: this }); this._showLocation = { containerPoint: pt @@ -942,7 +951,7 @@ export var ContextMenu = L.Handler.extend({ anchor; if (this._map.options.contextmenuAnchor) { - anchor = L.point(this._map.options.contextmenuAnchor); + anchor = point(this._map.options.contextmenuAnchor); pt = pt.add(anchor); } @@ -1233,7 +1242,7 @@ export var ContextMenu = L.Handler.extend({ } } else if (e.code === 'Escape') { if (this._layerMenuTabs || this._extentLayerMenuTabs) { - L.DomEvent.stop(e); + DomEvent.stop(e); this._focusOnLayerControl(); return; } @@ -1374,14 +1383,14 @@ export var ContextMenu = L.Handler.extend({ }, _onItemMouseOver: function (e) { - L.DomUtil.addClass(e.target || e.srcElement, 'over'); + DomUtil.addClass(e.target || e.srcElement, 'over'); let locale = e.locale || M.options.locale; if (e.srcElement.innerText === locale.cmCopyCoords + ' (C)') this._showCopySubMenu(e); }, _onItemMouseOut: function (e) { - L.DomUtil.removeClass(e.target || e.srcElement, 'over'); + DomUtil.removeClass(e.target || e.srcElement, 'over'); this._hideCopySubMenu(e); }, diff --git a/src/mapml/handlers/FeatureIndex.js b/src/mapml/handlers/FeatureIndex.js index fc181a8f2..8c6aaa417 100644 --- a/src/mapml/handlers/FeatureIndex.js +++ b/src/mapml/handlers/FeatureIndex.js @@ -1,7 +1,8 @@ -import { Util } from '../utils/Util'; -export var FeatureIndex = L.Handler.extend({ +import { Handler } from 'leaflet'; +import { Util } from '../utils/Util.js'; +export var FeatureIndex = Handler.extend({ initialize: function (map) { - L.Handler.prototype.initialize.call(this, map); + Handler.prototype.initialize.call(this, map); this.inBoundFeatures = []; this.outBoundFeatures = []; this.currentIndex = 0; diff --git a/src/mapml/handlers/QueryHandler.js b/src/mapml/handlers/QueryHandler.js index 0f51b5d05..27bd727f4 100644 --- a/src/mapml/handlers/QueryHandler.js +++ b/src/mapml/handlers/QueryHandler.js @@ -1,18 +1,26 @@ -import { featureLayer } from '../layers/FeatureLayer'; -import { featureRenderer } from '../features/featureRenderer'; +import { + Handler, + DomEvent, + DomUtil, + setOptions, + Bounds, + Util as LeafletUtil +} from 'leaflet'; +import { featureLayer } from '../layers/FeatureLayer.js'; +import { featureRenderer } from '../features/featureRenderer.js'; -export var QueryHandler = L.Handler.extend({ +export var QueryHandler = Handler.extend({ addHooks: function () { // get a reference to the actual element, so we can // use its layers property to iterate the layers from top down // evaluating if they are 'on the map' (enabled) - L.setOptions(this, { mapEl: this._map.options.mapEl }); - L.DomEvent.on(this._map, 'click', this._queryTopLayer, this); - L.DomEvent.on(this._map, 'keypress', this._queryTopLayerAtMapCenter, this); + setOptions(this, { mapEl: this._map.options.mapEl }); + DomEvent.on(this._map, 'click', this._queryTopLayer, this); + DomEvent.on(this._map, 'keypress', this._queryTopLayerAtMapCenter, this); }, removeHooks: function () { - L.DomEvent.off(this._map, 'click', this._queryTopLayer, this); - L.DomEvent.on(this._map, 'keypress', this._queryTopLayerAtMapCenter, this); + DomEvent.off(this._map, 'click', this._queryTopLayer, this); + DomEvent.on(this._map, 'keypress', this._queryTopLayerAtMapCenter, this); }, _getTopQueryableLayer: function () { var layers = this.options.mapEl.layers; @@ -71,7 +79,7 @@ export var QueryHandler = L.Handler.extend({ }; var tcrsClickLoc = crs.latLngToPoint(e.latlng, zoom), tileMatrixClickLoc = tcrsClickLoc.divideBy(tileSize).floor(), - tileBounds = new L.Bounds( + tileBounds = new Bounds( tcrsClickLoc.divideBy(tileSize).floor().multiplyBy(tileSize), tcrsClickLoc.divideBy(tileSize).ceil().multiplyBy(tileSize) ); @@ -88,7 +96,7 @@ export var QueryHandler = L.Handler.extend({ var fetchFeatures = function (template, obj) { const parser = new DOMParser(); - return fetch(L.Util.template(template.template, obj), { + return fetch(LeafletUtil.template(template.template, obj), { redirect: 'follow' }) .then((response) => { @@ -258,7 +266,7 @@ export var QueryHandler = L.Handler.extend({ obj[template.query.tiletop] = tcrs2pcrs(tileBounds.min).y; obj[template.query.tileright] = tcrs2pcrs(tileBounds.max).x; // add hidden or other variables that may be present into the values to - // be processed by L.Util.template below. + // be processed by Util.template below. for (var v in template.query) { if ( [ @@ -334,8 +342,8 @@ export var QueryHandler = L.Handler.extend({ f.addTo(layer); - let div = L.DomUtil.create('div', 'mapml-popup-content'), - c = L.DomUtil.create('iframe'); + let div = DomUtil.create('div', 'mapml-popup-content'), + c = DomUtil.create('iframe'); c.style = 'border: none'; c.srcdoc = features[0].querySelector( 'map-feature map-properties' diff --git a/src/mapml/handlers/keyboard.js b/src/mapml/handlers/keyboard.js index 6d2f4e393..48facfbe2 100644 --- a/src/mapml/handlers/keyboard.js +++ b/src/mapml/handlers/keyboard.js @@ -1,4 +1,5 @@ -L.Map.Keyboard.include({ +import { Map, DomEvent, point } from 'leaflet'; +Map.Keyboard.include({ _onKeyDown: function (e) { if (e.altKey || e.metaKey) { return; @@ -26,10 +27,10 @@ L.Map.Keyboard.include({ if (!map._panAnim || !map._panAnim._inProgress) { offset = this._panKeys[key]; if (e.shiftKey) { - offset = L.point(offset).multiplyBy(3); + offset = point(offset).multiplyBy(3); } if (e.ctrlKey) { - offset = L.point(offset).divideBy(5); + offset = point(offset).divideBy(5); } map.panBy(offset); @@ -54,6 +55,6 @@ L.Map.Keyboard.include({ return; } - L.DomEvent.stop(e); + DomEvent.stop(e); } }); diff --git a/src/mapml/index.js b/src/mapml/index.js index 20f788a73..92d55728a 100644 --- a/src/mapml/index.js +++ b/src/mapml/index.js @@ -38,24 +38,19 @@ * publicity pertaining to the work without specific, written prior permission. * Title to copyright in this work will at all times remain with copyright holders. */ -/* global L, Node */ -import '../../dist/leaflet-src.js'; -import '../../dist/proj4-src.js'; -import '../../dist/proj4leaflet.js'; -import '../../dist/L.Control.Locate.js'; import './GlobalM.js'; -import { HTMLMapmlViewerElement } from '../mapml-viewer'; -import { HTMLLayerElement } from '../mapml-viewer'; -import { HTMLMapCaptionElement } from '../mapml-viewer'; -import { HTMLFeatureElement } from '../mapml-viewer'; -import { HTMLExtentElement } from '../mapml-viewer'; -import { HTMLInputElement } from '../mapml-viewer'; -import { HTMLSelectElement } from '../mapml-viewer'; -import { HTMLLinkElement } from '../mapml-viewer'; -import { HTMLStyleElement } from '../mapml-viewer'; -import { HTMLWebMapElement as HTMLMapElement } from '../mapml-viewer'; -import { HTMLMapAreaElement as HTMLAreaElement } from '../mapml-viewer'; +import { HTMLMapmlViewerElement } from '../mapml-viewer.js'; +import { HTMLLayerElement } from '../mapml-viewer.js'; +import { HTMLMapCaptionElement } from '../mapml-viewer.js'; +import { HTMLFeatureElement } from '../mapml-viewer.js'; +import { HTMLExtentElement } from '../mapml-viewer.js'; +import { HTMLInputElement } from '../mapml-viewer.js'; +import { HTMLSelectElement } from '../mapml-viewer.js'; +import { HTMLLinkElement } from '../mapml-viewer.js'; +import { HTMLStyleElement } from '../mapml-viewer.js'; +import { HTMLWebMapElement as HTMLMapElement } from '../mapml-viewer.js'; +import { HTMLMapAreaElement as HTMLAreaElement } from '../mapml-viewer.js'; window.MapML = { HTMLMapmlViewerElement, diff --git a/src/mapml/layers/Crosshair.js b/src/mapml/layers/Crosshair.js index 89d673e1b..a30b727a1 100644 --- a/src/mapml/layers/Crosshair.js +++ b/src/mapml/layers/Crosshair.js @@ -1,14 +1,12 @@ -export var Crosshair = L.Layer.extend({ +import { Layer, DomUtil, DomEvent } from 'leaflet'; + +export var Crosshair = Layer.extend({ onAdd: function (map) { // SVG crosshair design from https://github.com/xguaita/Leaflet.MapCenterCoord/blob/master/src/icons/MapCenterCoordIcon1.svg?short_path=81a5c76 // Optimized with SVGOMG: https://jakearchibald.github.io/svgomg/ let svgInnerHTML = ``; - this._container = L.DomUtil.create( - 'div', - 'mapml-crosshair', - map._container - ); + this._container = DomUtil.create('div', 'mapml-crosshair', map._container); this._container.innerHTML = svgInnerHTML; map.isFocused = false; this._isQueryable = false; @@ -19,7 +17,7 @@ export var Crosshair = L.Layer.extend({ this ); map.on('popupopen', this._isMapFocused, this); - L.DomEvent.on( + DomEvent.on( map._container, 'keydown keyup mousedown', this._isMapFocused, @@ -35,11 +33,7 @@ export var Crosshair = L.Layer.extend({ this._toggleEvents ); map.off('popupopen', this._isMapFocused); - L.DomEvent.off( - map._container, - 'keydown keyup mousedown', - this._isMapFocused - ); + DomEvent.off(map._container, 'keydown keyup mousedown', this._isMapFocused); }, _toggleEvents: function () { @@ -62,9 +56,9 @@ export var Crosshair = L.Layer.extend({ _addOrRemoveMapOutline: function (e) { let mapContainer = this._map._container; if (this._map.isFocused && !this._outline) { - this._outline = L.DomUtil.create('div', 'mapml-outline', mapContainer); + this._outline = DomUtil.create('div', 'mapml-outline', mapContainer); } else if (!this._map.isFocused && this._outline) { - L.DomUtil.remove(this._outline); + DomUtil.remove(this._outline); delete this._outline; } }, diff --git a/src/mapml/layers/DebugOverlay.js b/src/mapml/layers/DebugOverlay.js index f4f3c3458..72a361c4e 100644 --- a/src/mapml/layers/DebugOverlay.js +++ b/src/mapml/layers/DebugOverlay.js @@ -1,14 +1,22 @@ -export var DebugOverlay = L.Layer.extend({ +import { + Layer, + DomUtil, + GridLayer, + LayerGroup, + Path, + point, + circle, + bounds, + setOptions +} from 'leaflet'; + +export var DebugOverlay = Layer.extend({ onAdd: function (map) { let mapSize = map.getSize(); //conditionally show container for debug panel/banner only when the map has enough space for it if (mapSize.x > 400 || mapSize.y > 300) { - this._container = L.DomUtil.create( - 'table', - 'mapml-debug', - map._container - ); + this._container = DomUtil.create('table', 'mapml-debug', map._container); this._panel = debugPanel({ className: 'mapml-debug-panel', @@ -39,7 +47,7 @@ export var DebugOverlay = L.Layer.extend({ if (this._panel) { //conditionally remove the panel, as it's not always added map.removeLayer(this._panel); - L.DomUtil.remove(this._container); + DomUtil.remove(this._container); } } }); @@ -48,13 +56,13 @@ export var debugOverlay = function () { return new DebugOverlay(); }; -export var DebugPanel = L.Layer.extend({ +export var DebugPanel = Layer.extend({ initialize: function (options) { - L.setOptions(this, options); + setOptions(this, options); }, onAdd: function (map) { - this._title = L.DomUtil.create( + this._title = DomUtil.create( 'caption', 'mapml-debug-banner', this.options.pane @@ -62,7 +70,7 @@ export var DebugPanel = L.Layer.extend({ this._title.innerHTML = 'Debug mode'; map.debug = {}; - map.debug._infoContainer = this._debugContainer = L.DomUtil.create( + map.debug._infoContainer = this._debugContainer = DomUtil.create( 'tbody', 'mapml-debug-panel', this.options.pane @@ -70,32 +78,32 @@ export var DebugPanel = L.Layer.extend({ let infoContainer = map.debug._infoContainer; - map.debug._tileCoord = L.DomUtil.create( + map.debug._tileCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer ); - map.debug._tileMatrixCoord = L.DomUtil.create( + map.debug._tileMatrixCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer ); - map.debug._mapCoord = L.DomUtil.create( + map.debug._mapCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer ); - map.debug._tcrsCoord = L.DomUtil.create( + map.debug._tcrsCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer ); - map.debug._pcrsCoord = L.DomUtil.create( + map.debug._pcrsCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer ); - map.debug._gcrsCoord = L.DomUtil.create( + map.debug._gcrsCoord = DomUtil.create( 'tr', 'mapml-debug-coordinates', infoContainer @@ -104,21 +112,24 @@ export var DebugPanel = L.Layer.extend({ this._map.on('mousemove', this._updateCoords); }, onRemove: function () { - L.DomUtil.remove(this._title); + DomUtil.remove(this._title); if (this._debugContainer) { - L.DomUtil.remove(this._debugContainer); + DomUtil.remove(this._debugContainer); this._map.off('mousemove', this._updateCoords); } }, _updateCoords: function (e) { if (this.contextMenu._visible) return; let mapEl = this.options.mapEl, - point = mapEl._map.project(e.latlng), + pointCoords = mapEl._map.project(e.latlng), scale = mapEl._map.options.crs.scale(+mapEl.zoom), - pcrs = mapEl._map.options.crs.transformation.untransform(point, scale), + pcrs = mapEl._map.options.crs.transformation.untransform( + pointCoords, + scale + ), tileSize = mapEl._map.options.crs.options.crs.tile.bounds.max.x, - pointI = point.x % tileSize, - pointJ = point.y % tileSize; + pointI = pointCoords.x % tileSize, + pointJ = pointCoords.y % tileSize; if (pointI < 0) pointI += tileSize; if (pointJ < 0) pointJ += tileSize; @@ -140,13 +151,13 @@ export var DebugPanel = L.Layer.extend({ `; this.debug._tcrsCoord.innerHTML = ` tcrs: - x: ${Math.trunc(point.x)}, - y: ${Math.trunc(point.y)} + x: ${Math.trunc(pointCoords.x)}, + y: ${Math.trunc(pointCoords.y)} `; this.debug._tileMatrixCoord.innerHTML = ` tilematrix: - column: ${Math.trunc(point.x / tileSize)}, - row: ${Math.trunc(point.y / tileSize)} + column: ${Math.trunc(pointCoords.x / tileSize)}, + row: ${Math.trunc(pointCoords.y / tileSize)} `; this.debug._pcrsCoord.innerHTML = ` pcrs: @@ -160,14 +171,14 @@ export var debugPanel = function (options) { return new DebugPanel(options); }; -export var DebugGrid = L.GridLayer.extend({ +export var DebugGrid = GridLayer.extend({ initialize: function (options) { - L.setOptions(this, options); - L.GridLayer.prototype.initialize.call(this, this._map); + setOptions(this, options); + GridLayer.prototype.initialize.call(this, this._map); }, createTile: function (coords) { - let tile = L.DomUtil.create('div', 'mapml-debug-tile'); + let tile = DomUtil.create('div', 'mapml-debug-tile'); tile.setAttribute('col', coords.x); tile.setAttribute('row', coords.y); tile.setAttribute('zoom', coords.z); @@ -186,19 +197,19 @@ export var debugGrid = function (options) { return new DebugGrid(options); }; -export var DebugVectors = L.LayerGroup.extend({ +export var DebugVectors = LayerGroup.extend({ initialize: function (options) { - L.setOptions(this, options); - L.LayerGroup.prototype.initialize.call(this, this._map, options); + setOptions(this, options); + LayerGroup.prototype.initialize.call(this, this._map, options); }, onAdd: function (map) { map.on('overlayremove', this._mapLayerUpdate, this); map.on('overlayadd', this._mapLayerUpdate, this); let center = map.options.crs.transformation.transform( - L.point(0, 0), + point(0, 0), map.options.crs.scale(0) ); - this._centerVector = L.circle(map.options.crs.pointToLatLng(center, 0), { + this._centerVector = circle(map.options.crs.pointToLatLng(center, 0), { radius: 250, className: 'mapml-debug-vectors projection-centre' }); @@ -226,22 +237,16 @@ export var DebugVectors = L.LayerGroup.extend({ if (layers[i].layerBounds) { boundsArray = [ layers[i].layerBounds.min, - L.point(layers[i].layerBounds.max.x, layers[i].layerBounds.min.y), + point(layers[i].layerBounds.max.x, layers[i].layerBounds.min.y), layers[i].layerBounds.max, - L.point(layers[i].layerBounds.min.x, layers[i].layerBounds.max.y) + point(layers[i].layerBounds.min.x, layers[i].layerBounds.max.y) ]; } else { boundsArray = [ layers[i].extentBounds.min, - L.point( - layers[i].extentBounds.max.x, - layers[i].extentBounds.min.y - ), + point(layers[i].extentBounds.max.x, layers[i].extentBounds.min.y), layers[i].extentBounds.max, - L.point( - layers[i].extentBounds.min.x, - layers[i].extentBounds.max.y - ) + point(layers[i].extentBounds.min.x, layers[i].extentBounds.max.y) ]; } @@ -282,9 +287,9 @@ export var DebugVectors = L.LayerGroup.extend({ if (map.totalLayerBounds) { let totalBoundsArray = [ map.totalLayerBounds.min, - L.point(map.totalLayerBounds.max.x, map.totalLayerBounds.min.y), + point(map.totalLayerBounds.max.x, map.totalLayerBounds.min.y), map.totalLayerBounds.max, - L.point(map.totalLayerBounds.min.x, map.totalLayerBounds.max.y) + point(map.totalLayerBounds.min.x, map.totalLayerBounds.max.y) ]; let totalBounds = projectedExtent(totalBoundsArray, { @@ -309,10 +314,10 @@ export var debugVectors = function (options) { return new DebugVectors(options); }; -var ProjectedExtent = L.Path.extend({ +var ProjectedExtent = Path.extend({ getCenter: function (round) { let crs = this._map.options.crs; - return crs.unproject(L.bounds(this._locations).getCenter()); + return crs.unproject(bounds(this._locations).getCenter()); }, options: { @@ -321,7 +326,7 @@ var ProjectedExtent = L.Path.extend({ initialize: function (locations, options) { //locations passed in as pcrs coordinates this._locations = locations; - L.setOptions(this, options); + setOptions(this, options); }, _project: function () { @@ -329,14 +334,12 @@ var ProjectedExtent = L.Path.extend({ let scale = this._map.options.crs.scale(this._map.getZoom()), map = this._map; for (let i = 0; i < this._locations.length; i++) { - let point = map.options.crs.transformation.transform( + let pt0 = map.options.crs.transformation.transform( this._locations[i], scale ); //substract the pixel origin from the pixel coordinates to get the location relative to map viewport - this._rings.push( - L.point(point.x, point.y)._subtract(map.getPixelOrigin()) - ); + this._rings.push(point(pt0.x, pt0.y)._subtract(map.getPixelOrigin())); } //leaflet SVG renderer looks for and array of arrays to build polygons, //in this case it only deals with a rectangle so one closed array or points diff --git a/src/mapml/layers/ExtentLayer.js b/src/mapml/layers/ExtentLayer.js index 7be2fd2a8..45cb6350c 100644 --- a/src/mapml/layers/ExtentLayer.js +++ b/src/mapml/layers/ExtentLayer.js @@ -1,14 +1,14 @@ -export var ExtentLayer = L.LayerGroup.extend({ +import { LayerGroup, DomUtil } from 'leaflet'; + +export var ExtentLayer = LayerGroup.extend({ initialize: function (options) { - // TODO: should invoke prototype.initialize to trigger the leaflet initialization for proper setup - // otherwise the initialize we provide will override the init that leaflet provides - // but we still need to create the container and the pane by ourselves - L.LayerGroup.prototype.initialize.call(this, null, options); - this._container = L.DomUtil.create('div', 'leaflet-layer'); + // Call LayerGroup's initialize to trigger Leaflet's setup + LayerGroup.prototype.initialize.call(this, null, options); + this._container = DomUtil.create('div', 'leaflet-layer'); this._extentEl = this.options.extentEl; this.changeOpacity(this.options.opacity); - // TODO: need renaming ex. mapml-extentLayer-container - L.DomUtil.addClass(this._container, 'mapml-extentlayer-container'); + // Add class to the container + DomUtil.addClass(this._container, 'mapml-extentlayer-container'); }, getEvents: function () { return { @@ -22,7 +22,7 @@ export var ExtentLayer = L.LayerGroup.extend({ return this._container; }, onAdd: function (map) { - L.LayerGroup.prototype.onAdd.call(this, map); + LayerGroup.prototype.onAdd.call(this, map); let pane = this.options.extentEl.parentLayer._layer._container; pane.appendChild(this._container); }, @@ -52,8 +52,8 @@ export var ExtentLayer = L.LayerGroup.extend({ } }, onRemove: function () { - L.LayerGroup.prototype.onRemove.call(this, this._map); - L.DomUtil.remove(this._container); + LayerGroup.prototype.onRemove.call(this, this._map); + DomUtil.remove(this._container); }, _previousFeature: function (e) { diff --git a/src/mapml/layers/FeatureIndexOverlay.js b/src/mapml/layers/FeatureIndexOverlay.js index 09efce4a5..986b9f306 100644 --- a/src/mapml/layers/FeatureIndexOverlay.js +++ b/src/mapml/layers/FeatureIndexOverlay.js @@ -1,16 +1,18 @@ -import { Util } from '../utils/Util'; -export var FeatureIndexOverlay = L.Layer.extend({ +import { Layer, DomUtil, point, bounds } from 'leaflet'; +import { Util } from '../utils/Util.js'; + +export var FeatureIndexOverlay = Layer.extend({ onAdd: function (map) { let svgInnerHTML = ``; - this._container = L.DomUtil.create( + this._container = DomUtil.create( 'div', 'mapml-feature-index-box', map._container ); this._container.innerHTML = svgInnerHTML; - this._output = L.DomUtil.create( + this._output = DomUtil.create( 'output', 'mapml-feature-index', map._container @@ -18,7 +20,7 @@ export var FeatureIndexOverlay = L.Layer.extend({ this._output.setAttribute('role', 'status'); this._output.setAttribute('aria-live', 'polite'); this._output.setAttribute('aria-atomic', 'true'); - this._body = L.DomUtil.create( + this._body = DomUtil.create( 'span', 'mapml-feature-index-content', this._output @@ -32,12 +34,12 @@ export var FeatureIndexOverlay = L.Layer.extend({ }, _calculateReticleBounds: function () { - let bounds = this._map.getPixelBounds(); - let center = bounds.getCenter(); + let bnds = this._map.getPixelBounds(); + let center = bnds.getCenter(); let wRatio = - Math.abs(bounds.min.x - bounds.max.x) / this._map.options.mapEl.width; + Math.abs(bnds.min.x - bnds.max.x) / this._map.options.mapEl.width; let hRatio = - Math.abs(bounds.min.y - bounds.max.y) / this._map.options.mapEl.height; + Math.abs(bnds.min.y - bnds.max.y) / this._map.options.mapEl.height; let reticleDimension = getComputedStyle(this._container).width.replace( /[^\d.]/g, @@ -49,9 +51,9 @@ export var FeatureIndexOverlay = L.Layer.extend({ } let w = (wRatio * reticleDimension) / 2; let h = (hRatio * reticleDimension) / 2; - let minPoint = L.point(center.x - w, center.y + h); - let maxPoint = L.point(center.x + w, center.y - h); - let b = L.bounds(minPoint, maxPoint); + let minPoint = point(center.x - w, center.y + h); + let maxPoint = point(center.x + w, center.y - h); + let b = bounds(minPoint, maxPoint); return Util.pixelToPCRSBounds( b, this._map.getZoom(), @@ -85,24 +87,24 @@ export var FeatureIndexOverlay = L.Layer.extend({ keys.forEach((i) => { let layer = features[i].layer; let layers = features[i].layer._layers; - let bounds = L.bounds(); + let b = bounds(); if (layers) { let keys = Object.keys(layers); keys.forEach((j) => { - if (!bounds) - bounds = L.bounds( + if (!b) + b = bounds( layer._layers[j]._bounds.min, layer._layers[j]._bounds.max ); - bounds.extend(layer._layers[j]._bounds.min); - bounds.extend(layer._layers[j]._bounds.max); + b.extend(layer._layers[j]._bounds.min); + b.extend(layer._layers[j]._bounds.max); }); } else if (layer._bounds) { - bounds = L.bounds(layer._bounds.min, layer._bounds.max); + b = bounds(layer._bounds.min, layer._bounds.max); } - if (featureIndexBounds.overlaps(bounds)) { + if (featureIndexBounds.overlaps(b)) { let label = features[i].path.getAttribute('aria-label'); if (index < 8) { diff --git a/src/mapml/layers/FeatureLayer.js b/src/mapml/layers/FeatureLayer.js index 6ec9f1637..d3a516439 100644 --- a/src/mapml/layers/FeatureLayer.js +++ b/src/mapml/layers/FeatureLayer.js @@ -1,8 +1,16 @@ -import { Util } from '../utils/Util'; -import { path } from '../features/path'; -import { geometry } from '../features/geometry'; +import { + FeatureGroup, + DomUtil, + bounds, + SVG, + Util as LeafletUtil, + Browser +} from 'leaflet'; +import { Util } from '../utils/Util.js'; +import { path } from '../features/path.js'; +import { geometry } from '../features/geometry.js'; -export var FeatureLayer = L.FeatureGroup.extend({ +export var FeatureLayer = FeatureGroup.extend({ /* * M.MapML turns any MapML feature data into a Leaflet layer. Based on L.GeoJSON. * @@ -15,12 +23,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ 2. for static templated feature: null 3. for non-templated feature: map-layer (with no src) or mapml file (with src) */ - // options.extent: when you use a FeatureLayer, you can either get it to calculate the - // .layerBounds dynamically (the default), based on adds/removes of features from the layer/ - // or you can construct it with a bounds (via options.extent), - // which will then remain static for the lifetime of the layer - - L.FeatureGroup.prototype.initialize.call(this, null, options); + FeatureGroup.prototype.initialize.call(this, null, options); // this.options.static is false ONLY for tiled vector features // this._staticFeature is ONLY true when not used by TemplatedFeaturesLayer // this.options.query true when created by QueryHandler.js @@ -29,39 +32,35 @@ export var FeatureLayer = L.FeatureGroup.extend({ // not a tiled vector layer this._container = null; if (this.options.query) { - this._container = L.DomUtil.create( + this._container = DomUtil.create( 'div', 'leaflet-layer', this.options.pane ); - // must have leaflet-pane class because of new/changed rule in leaflet.css - // info: https://github.com/Leaflet/Leaflet/pull/4597 - L.DomUtil.addClass( + DomUtil.addClass( this._container, 'leaflet-pane mapml-vector-container' ); } else if (this.options._leafletLayer) { - this._container = L.DomUtil.create( + this._container = DomUtil.create( 'div', 'leaflet-layer', this.options.pane ); - L.DomUtil.addClass( + DomUtil.addClass( this._container, 'leaflet-pane mapml-vector-container' ); - // static mapmlvector should always at the top - // this._container.style.zIndex = 1000; } else { // if the current featureLayer is a sublayer of templatedFeatureLayer, // append directly to the templated feature container (passed in as options.pane) this._container = this.options.pane; - L.DomUtil.addClass( + DomUtil.addClass( this._container, 'leaflet-pane mapml-vector-container' ); } - L.setOptions(this.options.renderer, { pane: this._container }); + this.options.renderer.options.pane = this._container; } if (this.options.query) { this._queryFeatures = mapml.features ? mapml.features : mapml; @@ -110,25 +109,20 @@ export var FeatureLayer = L.FeatureGroup.extend({ onAdd: function (map) { this._map = map; - L.FeatureGroup.prototype.onAdd.call(this, map); + FeatureGroup.prototype.onAdd.call(this, map); if (this._staticFeature) { this._validateRendering(); } - if (this._queryFeatures) + if (this._queryFeatures) { map.on('featurepagination', this.showPaginationFeature, this); + } }, addLayer: function (layerToAdd) { - L.FeatureGroup.prototype.addLayer.call(this, layerToAdd); - // static FeatureLayer (e.g. MapMLLayer._mapmlvectors) NEVER has a - // .layerBounds property, so if there is this.options.layerBounds, don't - // go copying it to this.layerBounds. Same for zoomBounds. - // bug alert: it's necessary to create a new bounds object to initialize - // this.layerBounds, to avoid changing the layerBounds of the first geometry - // added to this layer + FeatureGroup.prototype.addLayer.call(this, layerToAdd); if (!this.options.layerBounds) { this.layerBounds = this.layerBounds ? this.layerBounds.extend(layerToAdd.layerBounds) - : L.bounds(layerToAdd.layerBounds.min, layerToAdd.layerBounds.max); + : bounds(layerToAdd.layerBounds.min, layerToAdd.layerBounds.max); if (this.zoomBounds) { if (layerToAdd.zoomBounds.minZoom < this.zoomBounds.minZoom) @@ -157,20 +151,20 @@ export var FeatureLayer = L.FeatureGroup.extend({ return this; }, addRendering: function (featureToAdd) { - L.FeatureGroup.prototype.addLayer.call(this, featureToAdd); + FeatureGroup.prototype.addLayer.call(this, featureToAdd); }, onRemove: function (map) { if (this._queryFeatures) { map.off('featurepagination', this.showPaginationFeature, this); delete this._queryFeatures; - L.DomUtil.remove(this._container); + DomUtil.remove(this._container); } - L.FeatureGroup.prototype.onRemove.call(this, map); + FeatureGroup.prototype.onRemove.call(this, map); this._map.featureIndex.cleanIndex(); }, removeLayer: function (featureToRemove) { - L.FeatureGroup.prototype.removeLayer.call(this, featureToRemove); + FeatureGroup.prototype.removeLayer.call(this, featureToRemove); if (!this.options.layerBounds) { delete this.layerBounds; // this ensures that the .extent gets recalculated if needed @@ -193,7 +187,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ if (layerBounds) { layerBounds.extend(layer.layerBounds); } else { - layerBounds = L.bounds(layer.layerBounds.min, layer.layerBounds.max); + layerBounds = bounds(layer.layerBounds.min, layer.layerBounds.max); } if (zoomBounds) { if (layer.zoomBounds.minZoom < zoomBounds.minZoom) @@ -237,7 +231,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ * @returns {undefined} */ removeRendering: function (featureToRemove) { - L.FeatureGroup.prototype.removeLayer.call(this, featureToRemove); + FeatureGroup.prototype.removeLayer.call(this, featureToRemove); }, _removeFromFeaturesList: function (feature) { for (let zoom in this._features) @@ -364,10 +358,10 @@ export var FeatureLayer = L.FeatureGroup.extend({ .subtract(this._map._getNewPixelOrigin(center, this._map.getZoom())) .round(); - if (any3d) { - L.setTransform(this._layers[clampZoom], translate, scale); + if (Browser.any3d) { + DomUtil.setTransform(this._layers[clampZoom], translate, scale); } else { - L.setPosition(this._layers[clampZoom], translate); + DomUtil.setPosition(this._layers[clampZoom], translate); } }, @@ -449,7 +443,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ var style = this.options.style; if (style) { // reset any custom styles - L.Util.extend(layer.options, layer.defaultOptions); + LeafletUtil.extend(layer.options, layer.defaultOptions); this._setLayerStyle(layer, style); } }, @@ -480,7 +474,7 @@ export var FeatureLayer = L.FeatureGroup.extend({ let geom = feature.getElementsByTagName('map-geometry')[0], group = [], groupOptions = {}, - svgGroup = L.SVG.create('g'), + svgGroup = SVG.create('g'), copyOptions = Object.assign({}, vectorOptions); svgGroup._featureEl = feature; // rendered has a reference to map-feature if (geom) { diff --git a/src/mapml/layers/ImageLayer.js b/src/mapml/layers/ImageLayer.js index 31c5aed28..5acfdc94d 100644 --- a/src/mapml/layers/ImageLayer.js +++ b/src/mapml/layers/ImageLayer.js @@ -1,18 +1,27 @@ -export var ImageLayer = L.ImageOverlay.extend({ +import { + ImageOverlay, + DomUtil, + point, + setOptions, + Util, + Browser +} from 'leaflet'; + +export var ImageLayer = ImageOverlay.extend({ initialize: function (url, location, size, angle, container, options) { // (String, Point, Point, Number, Element, Object) this._container = container; this._url = url; // instead of calculating where the image goes, put it at 0,0 - //this._location = L.point(location); - // the location for WMS requests will be the upper left hand + // this._location = point(location); + // the location for WMS requests will be the upper left-hand // corner of the map. When the map is initialized, that is 0,0, // but as the user pans, of course the this._location = location; - this._size = L.point(size); + this._size = point(size); this._angle = angle; - L.setOptions(this, options); + setOptions(this, options); }, getEvents: function () { var events = { @@ -35,7 +44,7 @@ export var ImageLayer = L.ImageOverlay.extend({ } if (this.options.interactive) { - L.DomUtil.addClass(this._image, 'leaflet-interactive'); + DomUtil.addClass(this._image, 'leaflet-interactive'); this.addInteractiveTarget(this._image); } @@ -43,7 +52,7 @@ export var ImageLayer = L.ImageOverlay.extend({ this._reset(); }, onRemove: function () { - L.DomUtil.remove(this._image); + DomUtil.remove(this._image); if (this.options.interactive) { this.removeInteractiveTarget(this._image); } @@ -64,10 +73,10 @@ export var ImageLayer = L.ImageOverlay.extend({ .subtract(this._map._getNewPixelOrigin(e.center, e.zoom)) .round(); - if (L.Browser.any3d) { - L.DomUtil.setTransform(this._image, translate, scale); + if (Browser.any3d) { + DomUtil.setTransform(this._image, translate, scale); } else { - L.DomUtil.setPosition(this._image, translate); + DomUtil.setPosition(this._image, translate); } }, _reset: function (e) { @@ -85,7 +94,7 @@ export var ImageLayer = L.ImageOverlay.extend({ ) { return; } - L.DomUtil.setPosition(image, location); + DomUtil.setPosition(image, location); image.style.width = size.x + 'px'; image.style.height = size.y + 'px'; @@ -104,15 +113,15 @@ export var ImageLayer = L.ImageOverlay.extend({ var fade = Math.min(1, (now - image.loaded) / 200); - L.DomUtil.setOpacity(image, fade); + DomUtil.setOpacity(image, fade); if (fade < 1) { nextFrame = true; } if (nextFrame) { - L.Util.cancelAnimFrame(this._fadeFrame); - this._fadeFrame = L.Util.requestAnimFrame(this._updateOpacity, this); + Util.cancelAnimFrame(this._fadeFrame); + this._fadeFrame = Util.requestAnimFrame(this._updateOpacity, this); } - L.DomUtil.addClass(image, 'leaflet-image-loaded'); + DomUtil.addClass(image, 'leaflet-image-loaded'); } }); export var imageLayer = function ( diff --git a/src/mapml/layers/MapMLLayer.js b/src/mapml/layers/MapMLLayer.js index b08b67446..e27ccb2f4 100644 --- a/src/mapml/layers/MapMLLayer.js +++ b/src/mapml/layers/MapMLLayer.js @@ -1,9 +1,18 @@ -import { Util } from '../utils/Util'; -import { featureLayer } from './FeatureLayer'; -import { staticTileLayer } from './StaticTileLayer'; -import { featureRenderer } from '../features/featureRenderer'; +import { + LayerGroup, + setOptions, + DomUtil, + DomEvent, + bounds, + latLng, + latLngBounds +} from 'leaflet'; +import { Util } from '../utils/Util.js'; +import { featureLayer } from './FeatureLayer.js'; +import { staticTileLayer } from './StaticTileLayer.js'; +import { featureRenderer } from '../features/featureRenderer.js'; -export var MapMLLayer = L.LayerGroup.extend({ +export var MapMLLayer = LayerGroup.extend({ options: { zIndex: 0, opacity: '1.0' @@ -12,20 +21,20 @@ export var MapMLLayer = L.LayerGroup.extend({ initialize: function (href, layerEl, options) { // in the custom element, the attribute is actually 'src' // the _href version is the URL received from map-layer@src - L.LayerGroup.prototype.initialize.call(this, null, options); + LayerGroup.prototype.initialize.call(this, null, options); if (href) { this._href = href; } this._layerEl = layerEl; this._content = layerEl.src ? layerEl.shadowRoot : layerEl; - L.setOptions(this, options); - this._container = L.DomUtil.create('div', 'leaflet-layer'); + setOptions(this, options); + this._container = DomUtil.create('div', 'leaflet-layer'); this.changeOpacity(this.options.opacity); - L.DomUtil.addClass(this._container, 'mapml-layer'); + DomUtil.addClass(this._container, 'mapml-layer'); // this layer 'owns' a mapmlTileLayer, which is a subclass of L.GridLayer // it 'passes' what tiles to load via the content of this._mapmlTileContainer - this._mapmlTileContainer = L.DomUtil.create( + this._mapmlTileContainer = DomUtil.create( 'div', 'mapml-tile-container', this._container @@ -78,7 +87,7 @@ export var MapMLLayer = L.LayerGroup.extend({ }, onAdd: function (map) { - L.LayerGroup.prototype.onAdd.call(this, map); + LayerGroup.prototype.onAdd.call(this, map); this.getPane().appendChild(this._container); //only add the layer if there are tiles to be rendered @@ -92,9 +101,9 @@ export var MapMLLayer = L.LayerGroup.extend({ _calculateBounds: function () { delete this.bounds; delete this.zoomBounds; - let bounds, zoomBounds; + let bnds, zoomBounds; let layerTypes = ['_staticTileLayer', '_mapmlvectors', '_extentLayer']; - bounds = + bnds = this._layerEl.src && this._layerEl.shadowRoot.querySelector( ':host > map-meta[name=extent][content]' @@ -131,13 +140,13 @@ export var MapMLLayer = L.LayerGroup.extend({ for (let i = 0; i < mapExtents.length; i++) { if (mapExtents[i]._extentLayer.bounds) { let mapExtentLayer = mapExtents[i]._extentLayer; - if (!bounds) { - bounds = L.bounds( + if (!bnds) { + bnds = bounds( mapExtentLayer.bounds.min, mapExtentLayer.bounds.max ); } else { - bounds.extend(mapExtentLayer.bounds); + bnds.extend(mapExtentLayer.bounds); } if (mapExtentLayer.zoomBounds) { if (!zoomBounds) { @@ -167,10 +176,10 @@ export var MapMLLayer = L.LayerGroup.extend({ (type === '_staticTileLayer' && this._staticTileLayer) ) { if (this[type].layerBounds) { - if (!bounds) { - bounds = this[type].layerBounds; + if (!bnds) { + bnds = this[type].layerBounds; } else { - bounds.extend(this[type].layerBounds); + bnds.extend(this[type].layerBounds); } } if (this[type].zoomBounds) { @@ -196,11 +205,11 @@ export var MapMLLayer = L.LayerGroup.extend({ } } }); - if (bounds) { - this.bounds = bounds; + if (bnds) { + this.bounds = bnds; } else { let projectionBounds = M[this.options.projection].options.bounds; - this.bounds = L.bounds(projectionBounds.min, projectionBounds.max); + this.bounds = bounds(projectionBounds.min, projectionBounds.max); } // we could get here and zoomBounds might still not be defined (empty layer) if (!zoomBounds) zoomBounds = {}; @@ -221,8 +230,8 @@ export var MapMLLayer = L.LayerGroup.extend({ }, onRemove: function (map) { - L.LayerGroup.prototype.onRemove.call(this, map); - L.DomUtil.remove(this._container); + LayerGroup.prototype.onRemove.call(this, map); + DomUtil.remove(this._container); map.off('popupopen', this._attachSkipButtons); }, getAttribution: function () { @@ -365,7 +374,7 @@ export var MapMLLayer = L.LayerGroup.extend({ licenseTitle + ''; } - L.setOptions(layer, { attribution: attText }); + setOptions(layer, { attribution: attText }); var legendLink = mapml.querySelector('map-link[rel=legend]'); if (legendLink) { layer._legendUrl = legendLink.getAttribute('href'); @@ -445,24 +454,23 @@ export var MapMLLayer = L.LayerGroup.extend({ } if (popup._container.querySelector('nav[class="mapml-focus-buttons"]')) { - L.DomUtil.remove( + DomUtil.remove( popup._container.querySelector('nav[class="mapml-focus-buttons"]') ); - L.DomUtil.remove(popup._container.querySelector('hr')); + DomUtil.remove(popup._container.querySelector('hr')); } //add when popopen event happens instead - let div = L.DomUtil.create('nav', 'mapml-focus-buttons'); - + let div = DomUtil.create('nav', 'mapml-focus-buttons'); // creates |< button, focuses map - let mapFocusButton = L.DomUtil.create('button', 'mapml-popup-button', div); + let mapFocusButton = DomUtil.create('button', 'mapml-popup-button', div); mapFocusButton.type = 'button'; mapFocusButton.title = map.options.mapEl.locale.kbdFocusMap; mapFocusButton.innerHTML = ""; - L.DomEvent.on( + DomEvent.on( mapFocusButton, 'click', (e) => { - L.DomEvent.stop(e); + DomEvent.stop(e); map.featureIndex._sortIndex(); map.closePopup(); map._container.focus(); @@ -471,26 +479,26 @@ export var MapMLLayer = L.LayerGroup.extend({ ); // creates < button, focuses previous feature, if none exists focuses the current feature - let previousButton = L.DomUtil.create('button', 'mapml-popup-button', div); + let previousButton = DomUtil.create('button', 'mapml-popup-button', div); previousButton.type = 'button'; previousButton.title = map.options.mapEl.locale.kbdPrevFeature; previousButton.innerHTML = ""; - L.DomEvent.on(previousButton, 'click', layer._previousFeature, popup); + DomEvent.on(previousButton, 'click', layer._previousFeature, popup); // static feature counter that 1/1 - let featureCount = L.DomUtil.create('p', 'mapml-feature-count', div), + let featureCount = DomUtil.create('p', 'mapml-feature-count', div), totalFeatures = this._totalFeatureCount ? this._totalFeatureCount : 1; featureCount.innerText = popup._count + 1 + '/' + totalFeatures; // creates > button, focuses next feature, if none exists focuses the current feature - let nextButton = L.DomUtil.create('button', 'mapml-popup-button', div); + let nextButton = DomUtil.create('button', 'mapml-popup-button', div); nextButton.type = 'button'; nextButton.title = map.options.mapEl.locale.kbdNextFeature; nextButton.innerHTML = ""; - L.DomEvent.on(nextButton, 'click', layer._nextFeature, popup); + DomEvent.on(nextButton, 'click', layer._nextFeature, popup); // creates >| button, focuses map controls - let controlFocusButton = L.DomUtil.create( + let controlFocusButton = DomUtil.create( 'button', 'mapml-popup-button', div @@ -498,7 +506,7 @@ export var MapMLLayer = L.LayerGroup.extend({ controlFocusButton.type = 'button'; controlFocusButton.title = map.options.mapEl.locale.kbdFocusControls; controlFocusButton.innerHTML = ""; - L.DomEvent.on( + DomEvent.on( controlFocusButton, 'click', (e) => { @@ -509,14 +517,14 @@ export var MapMLLayer = L.LayerGroup.extend({ map.featureIndex.inBoundFeatures[ map.featureIndex.currentIndex ]?.path.setAttribute('tabindex', 0); - L.DomEvent.stop(e); + DomEvent.stop(e); map.closePopup(); map._controlContainer.querySelector('A:not([hidden])').focus(); }, popup ); - let divider = L.DomUtil.create('hr', 'mapml-popup-divider'); + let divider = DomUtil.create('hr', 'mapml-popup-divider'); popup._navigationBar = div; popup._content.appendChild(divider); @@ -550,7 +558,7 @@ export var MapMLLayer = L.LayerGroup.extend({ setTimeout(() => { map.closePopup(popup); group.focus(); - L.DomEvent.stop(focusEvent); + DomEvent.stop(focusEvent); }, 0); } else if ( path[0].classList.contains('mapml-popup-content') && @@ -561,7 +569,7 @@ export var MapMLLayer = L.LayerGroup.extend({ //timeout needed so focus of the feature is done even after the keypressup event occurs map.closePopup(popup); group.focus(); - L.DomEvent.stop(focusEvent); + DomEvent.stop(focusEvent); }, 0); } else if ( path[0] === popup._content.querySelector('a') && @@ -571,7 +579,7 @@ export var MapMLLayer = L.LayerGroup.extend({ setTimeout(() => { map.closePopup(popup); group.focus(); - L.DomEvent.stop(focusEvent); + DomEvent.stop(focusEvent); }, 0); } } @@ -588,7 +596,7 @@ export var MapMLLayer = L.LayerGroup.extend({ path[0].classList.contains('leaflet-popup-close-button')) || focusEvent.originalEvent.keyCode === 27 ) { - L.DomEvent.stopPropagation(focusEvent); + DomEvent.stopPropagation(focusEvent); map.closePopup(popup); map._container.focus(); if (focusEvent.originalEvent.keyCode !== 27) map._popupClosed = true; @@ -605,7 +613,7 @@ export var MapMLLayer = L.LayerGroup.extend({ map.closePopup(popup); setTimeout(() => { //timeout needed so focus of the feature is done even after the keypressup event occurs - L.DomEvent.stop(focusEvent); + DomEvent.stop(focusEvent); map._container.focus(); }, 0); } else if ( @@ -615,7 +623,7 @@ export var MapMLLayer = L.LayerGroup.extend({ ) { map.closePopup(popup); setTimeout(() => { - L.DomEvent.stop(focusEvent); + DomEvent.stop(focusEvent); map.getContainer.focus(); }, 0); } @@ -631,9 +639,9 @@ export var MapMLLayer = L.LayerGroup.extend({ if (!featureEl.querySelector('map-geometry')) return; let tL = featureEl.extent.topLeft.gcrs, bR = featureEl.extent.bottomRight.gcrs, - center = L.latLngBounds( - L.latLng(tL.horizontal, tL.vertical), - L.latLng(bR.horizontal, bR.vertical) + center = latLngBounds( + latLng(tL.horizontal, tL.vertical), + latLng(bR.horizontal, bR.vertical) ).getCenter(true); let zoomLink = document.createElement('a'); zoomLink.href = `#${featureEl.getZoomToZoom()},${center.lng},${ diff --git a/src/mapml/layers/StaticTileLayer.js b/src/mapml/layers/StaticTileLayer.js index 622956b9f..98ae79823 100644 --- a/src/mapml/layers/StaticTileLayer.js +++ b/src/mapml/layers/StaticTileLayer.js @@ -1,12 +1,14 @@ -import { Util } from '../utils/Util'; -export var StaticTileLayer = L.GridLayer.extend({ +import { GridLayer, setOptions, extend, point, bounds } from 'leaflet'; +import { Util } from '../utils/Util.js'; + +export var StaticTileLayer = GridLayer.extend({ initialize: function (options) { - L.setOptions(this, options); + setOptions(this, options); this.zoomBounds = this._getZoomBounds( options.tileContainer, options.maxZoomBound ); - L.extend(this.options, this.zoomBounds); + extend(this.options, this.zoomBounds); this._groups = this._groupTiles( this.options.tileContainer.getElementsByTagName('map-tile') ); @@ -20,12 +22,12 @@ export var StaticTileLayer = L.GridLayer.extend({ onAdd: function (map) { this._map = map; - L.GridLayer.prototype.onAdd.call(this, this._map); + GridLayer.prototype.onAdd.call(this, this._map); this._handleMoveEnd(); }, getEvents: function () { - let events = L.GridLayer.prototype.getEvents.call(this, this._map); + let events = GridLayer.prototype.getEvents.call(this, this._map); this._parentOnMoveEnd = events.moveend; events.moveend = this._handleMoveEnd; events.move = () => {}; //needed to prevent moveend from running @@ -98,14 +100,14 @@ export var StaticTileLayer = L.GridLayer.extend({ pixelCoords.y = +sCoords[1] * tileSize; pixelCoords.z = +sCoords[2]; //+String same as parseInt(String) if (sCoords[2] in layerBounds) { - layerBounds[sCoords[2]].extend(L.point(pixelCoords.x, pixelCoords.y)); + layerBounds[sCoords[2]].extend(point(pixelCoords.x, pixelCoords.y)); layerBounds[sCoords[2]].extend( - L.point(pixelCoords.x + tileSize, pixelCoords.y + tileSize) + point(pixelCoords.x + tileSize, pixelCoords.y + tileSize) ); } else { - layerBounds[sCoords[2]] = L.bounds( - L.point(pixelCoords.x, pixelCoords.y), - L.point(pixelCoords.x + tileSize, pixelCoords.y + tileSize) + layerBounds[sCoords[2]] = bounds( + point(pixelCoords.x, pixelCoords.y), + point(pixelCoords.x + tileSize, pixelCoords.y + tileSize) ); } } diff --git a/src/mapml/layers/TemplatedFeaturesLayer.js b/src/mapml/layers/TemplatedFeaturesLayer.js index 6ba317ed6..9babfda46 100644 --- a/src/mapml/layers/TemplatedFeaturesLayer.js +++ b/src/mapml/layers/TemplatedFeaturesLayer.js @@ -1,22 +1,30 @@ -import { Util } from '../utils/Util'; -import { featureLayer } from '../layers/FeatureLayer'; -import { featureRenderer } from '../features/featureRenderer'; +import { + Layer, + DomUtil, + extend, + setOptions, + Util as LeafletUtil +} from 'leaflet'; -export var TemplatedFeaturesLayer = L.Layer.extend({ +import { Util } from '../utils/Util.js'; +import { featureLayer } from '../layers/FeatureLayer.js'; +import { featureRenderer } from '../features/featureRenderer.js'; + +export var TemplatedFeaturesLayer = Layer.extend({ // this and M.ImageLayer could be merged or inherit from a common parent initialize: function (template, options) { this._template = template; - this._container = L.DomUtil.create('div', 'leaflet-layer'); - L.DomUtil.addClass(this._container, 'mapml-features-container'); + this._container = DomUtil.create('div', 'leaflet-layer'); + DomUtil.addClass(this._container, 'mapml-features-container'); this.zoomBounds = options.zoomBounds; this.extentBounds = options.extentBounds; // get rid of duplicate info, it can be confusing delete options.zoomBounds; delete options.extentBounds; this._linkEl = options.linkEl; - L.setOptions( + setOptions( this, - L.extend(options, this._setUpFeaturesTemplateVars(template)) + extend(options, this._setUpFeaturesTemplateVars(template)) ); }, @@ -69,7 +77,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ geometry.bindPopup(c, { autoClose: false, minWidth: 108 }); } }); - L.extend(this._features.options, { _leafletLayer: this._features }); + extend(this._features.options, { _leafletLayer: this._features }); this._features._layerEl = this._linkEl.getLayerEl(); } else { this._features.eachLayer((layer) => layer.addTo(map)); @@ -78,7 +86,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ }, onRemove: function () { if (this._features) this._features.eachLayer((layer) => layer.remove()); - L.DomUtil.remove(this._container); + DomUtil.remove(this._container); }, appendStyleLink: function (mapLink) { if (!mapLink.link) return; @@ -292,7 +300,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ obj[v] = this.options.feature[v]; } } - return L.Util.template(this._template.template, obj); + return LeafletUtil.template(this._template.template, obj); }, _TCRSToPCRS: function (coords, zoom) { // TCRS pixel point to Projected CRS point (in meters, presumably) diff --git a/src/mapml/layers/TemplatedImageLayer.js b/src/mapml/layers/TemplatedImageLayer.js index 9d713857b..eee7dee91 100644 --- a/src/mapml/layers/TemplatedImageLayer.js +++ b/src/mapml/layers/TemplatedImageLayer.js @@ -1,21 +1,27 @@ -import { Util } from '../utils/Util'; -import { ImageLayer, imageLayer } from './ImageLayer'; +import { + Layer, + DomUtil, + extend, + setOptions, + point, + Util as LeafletUtil +} from 'leaflet'; -export var TemplatedImageLayer = L.Layer.extend({ +import { Util } from '../utils/Util.js'; +import { ImageLayer, imageLayer } from './ImageLayer.js'; + +export var TemplatedImageLayer = Layer.extend({ initialize: function (template, options) { this._template = template; - this._container = L.DomUtil.create('div', 'leaflet-layer'); - L.DomUtil.addClass(this._container, 'mapml-image-container'); + this._container = DomUtil.create('div', 'leaflet-layer'); + DomUtil.addClass(this._container, 'mapml-image-container'); this._linkEl = options.linkEl; this.zoomBounds = options.zoomBounds; this.extentBounds = options.extentBounds; // get rid of unused duplicate information that can be confusing delete options.zoomBounds; delete options.extentBounds; - L.setOptions( - this, - L.extend(options, this._setUpExtentTemplateVars(template)) - ); + setOptions(this, extend(options, this._setUpExtentTemplateVars(template))); }, getEvents: function () { var events = { @@ -82,7 +88,7 @@ export var TemplatedImageLayer = L.Layer.extend({ .multiplyBy(scale) .subtract(obj._map._getNewPixelOrigin(obj._map.getCenter(), zoom)) .round(); - L.DomUtil.setTransform(obj._imageOverlay._image, translate, scale); + DomUtil.setTransform(obj._imageOverlay._image, translate, scale); }); }, @@ -121,14 +127,14 @@ export var TemplatedImageLayer = L.Layer.extend({ (mapZoom + 1) % step === 0 && current.zoom === previous.zoom - 1 ) { - this._addImage(bounds, steppedZoom, L.point(0, 0)); + this._addImage(bounds, steppedZoom, point(0, 0)); this._scaleImage(bounds, mapZoom); //Zooming or panning within a step increment } else if (e && mapZoom % step !== 0) { this._imageOverlay._overlayToRemove = this._imageOverlay._url; if (current.zoom !== previous.zoom) { //Zoomed from within one step increment into another - this._addImage(bounds, steppedZoom, L.point(0, 0)); + this._addImage(bounds, steppedZoom, point(0, 0)); this._pixelOrigins[steppedZoom] = bounds.min; this._scaleImage(bounds, mapZoom); } else { @@ -169,7 +175,7 @@ export var TemplatedImageLayer = L.Layer.extend({ } }, onRemove: function (map) { - L.DomUtil.remove(this._container); + DomUtil.remove(this._container); this._clearLayer(); }, getImageUrl: function (pixelBounds, zoom) { @@ -188,7 +194,7 @@ export var TemplatedImageLayer = L.Layer.extend({ obj[v] = this.options.extent[v]; } } - return L.Util.template(this._template.template, obj); + return LeafletUtil.template(this._template.template, obj); }, _TCRSToPCRS: function (coords, zoom) { // TCRS pixel point to Projected CRS point (in meters, presumably) diff --git a/src/mapml/layers/TemplatedPMTilesLayer.js b/src/mapml/layers/TemplatedPMTilesLayer.js index 2784a73e2..72e9eac42 100644 --- a/src/mapml/layers/TemplatedPMTilesLayer.js +++ b/src/mapml/layers/TemplatedPMTilesLayer.js @@ -1,8 +1,12 @@ -import { Util } from '../utils/Util'; -import * as protomapsL from '../../../node_modules/protomaps-leaflet/dist/esm/index.js'; -/* global L */ +import { Layer, GridLayer, DomUtil, extend, setOptions } from 'leaflet'; +// window.L as defined below is required for protomaps-leaflet <= 4.0.1 +const Leaflet = { GridLayer, DomUtil }; +window.L = Leaflet; -export var TemplatedPMTilesLayer = L.Layer.extend({ +import { Util } from '../utils/Util.js'; +import * as protomapsL from 'protomaps-leaflet'; + +export var TemplatedPMTilesLayer = Layer.extend({ initialize: function (template, options) { /* structure of this._template: { @@ -19,7 +23,7 @@ export var TemplatedPMTilesLayer = L.Layer.extend({ } */ this._template = template; - this._container = L.DomUtil.create( + this._container = DomUtil.create( 'div', 'leaflet-layer mapml-pmtiles-container' ); @@ -32,14 +36,14 @@ export var TemplatedPMTilesLayer = L.Layer.extend({ let paintRules = options?.pmtilesRules?.get(this._template.template); if (paintRules?.rules) { - L.extend(this._pmtilesOptions, { + extend(this._pmtilesOptions, { paintRules: paintRules.rules.PAINT_RULES }); - L.extend(this._pmtilesOptions, { + extend(this._pmtilesOptions, { labelRules: paintRules.rules.LABEL_RULES }); } else if (paintRules?.theme?.theme) { - L.extend(this._pmtilesOptions, { theme: paintRules.theme.theme }); + extend(this._pmtilesOptions, { theme: paintRules.theme.theme }); } else { console.warn( 'pmtiles symbolizer rules or theme not found for map-link@tref -> ' + @@ -52,7 +56,7 @@ export var TemplatedPMTilesLayer = L.Layer.extend({ delete options.zoomBounds; delete options.extentBounds; this._linkEl = options.linkEl; - L.setOptions(this, options); + setOptions(this, options); }, /** * @@ -93,7 +97,7 @@ export var TemplatedPMTilesLayer = L.Layer.extend({ }, onRemove: function (map) { this._pmtilesLayer.remove(); - L.DomUtil.remove(this._container); + DomUtil.remove(this._container); }, isVisible: function () { if (this._template.projection !== 'OSMTILE') return false; diff --git a/src/mapml/layers/TemplatedTileLayer.js b/src/mapml/layers/TemplatedTileLayer.js index ccc4eeb0d..f5f7d418a 100644 --- a/src/mapml/layers/TemplatedTileLayer.js +++ b/src/mapml/layers/TemplatedTileLayer.js @@ -1,9 +1,24 @@ -import { Util } from '../utils/Util'; -import { featureLayer } from '../layers/FeatureLayer'; -import { FeatureRenderer } from '../features/featureRenderer'; +import { + TileLayer, + DomUtil, + extend, + bind, + setOptions, + SVG, + point, + Point, + Util as LeafletUtil, + Browser, + bounds, + GridLayer +} from 'leaflet'; -export var TemplatedTileLayer = L.TileLayer.extend({ - // a TemplateTileLayer is similar to a L.TileLayer except its templates are +import { Util } from '../utils/Util.js'; +import { featureLayer } from '../layers/FeatureLayer.js'; +import { FeatureRenderer } from '../features/featureRenderer.js'; + +export var TemplatedTileLayer = TileLayer.extend({ + // a TemplateTileLayer is similar to a TileLayer except its templates are // defined by the