Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Labels, layer switcher, etc

Russ Garrettb39f3bf71c19
diff --git a/package-lock.json b/package-lock.json
index 3a12497..0aca435 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1334,29 +1334,40 @@
"core-js": "^2.5.7"
}
},
- "@mapbox/geojson-area": {
- "version": "0.2.2",
- "resolved": "https://registry.npmjs.org/@mapbox/geojson-area/-/geojson-area-0.2.2.tgz",
- "integrity": "sha1-GNeBSqNr8j+7zDefjiaiKSfevxA=",
- "requires": {
- "wgs84": "0.0.0"
- }
- },
"@mapbox/geojson-rewind": {
- "version": "0.4.0",
- "resolved": "https://registry.npmjs.org/@mapbox/geojson-rewind/-/geojson-rewind-0.4.0.tgz",
- "integrity": "sha512-b+1uPWBERW4Pet/969BNu61ZPDyH2ilIxBjJDFzxyS9TyszF9UrTQyYIl/G38clux3rtpAGGFSGTCSF/qR6UjA==",
+ "version": "0.5.0",
+ "resolved": "https://registry.npmjs.org/@mapbox/geojson-rewind/-/geojson-rewind-0.5.0.tgz",
+ "integrity": "sha512-73l/qJQgj/T/zO1JXVfuVvvKDgikD/7D/rHAD28S9BG1OTstgmftrmqfCx4U+zQAmtsB6HcDA3a7ymdnJZAQgg==",
"requires": {
- "@mapbox/geojson-area": "0.2.2",
- "concat-stream": "~1.6.0",
- "minimist": "1.2.0",
- "sharkdown": "^0.1.0"
+ "concat-stream": "~2.0.0",
+ "minimist": "^1.2.5"
},
"dependencies": {
+ "concat-stream": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz",
+ "integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==",
+ "requires": {
+ "buffer-from": "^1.0.0",
+ "inherits": "^2.0.3",
+ "readable-stream": "^3.0.2",
+ "typedarray": "^0.0.6"
+ }
+ },
"minimist": {
- "version": "1.2.0",
- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
- "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
+ },
+ "readable-stream": {
+ "version": "3.6.0",
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
+ "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
+ "requires": {
+ "inherits": "^2.0.3",
+ "string_decoder": "^1.1.1",
+ "util-deprecate": "^1.0.1"
+ }
}
}
},
@@ -1371,9 +1382,9 @@
"integrity": "sha1-zlblOfg1UrWNENZy6k1vya3HsjQ="
},
"@mapbox/mapbox-gl-supported": {
- "version": "1.4.1",
- "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-1.4.1.tgz",
- "integrity": "sha512-yyKza9S6z3ELKuf6w5n6VNUB0Osu6Z93RXPfMHLIlNWohu3KqxewLOq4lMXseYJ92GwkRAxd207Pr/Z98cwmvw=="
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-1.5.0.tgz",
+ "integrity": "sha512-/PT1P6DNf7vjEEiPkVIRJkvibbqWtqnyGaBz3nfRdcxclNSnSdaLU5tfAgcD7I8Yt5i+L19s406YLl1koLnLbg=="
},
"@mapbox/point-geometry": {
"version": "0.1.0",
@@ -1709,11 +1720,6 @@
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
"dev": true
},
- "ansicolors": {
- "version": "0.2.1",
- "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.2.1.tgz",
- "integrity": "sha1-vgiVmQl7dKXJxKhKDNvNtivYeu8="
- },
"any-base": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz",
@@ -2876,15 +2882,6 @@
"integrity": "sha512-X9rxMaWZNbJB5qjkDqPtNv/yfViTeUL6ILk0QJNxLV3OhKC5Acn5vxsuUvllR6B48mog8lmS+whwHq/QIYSL9w==",
"dev": true
},
- "cardinal": {
- "version": "0.4.4",
- "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-0.4.4.tgz",
- "integrity": "sha1-ylu2iltRG5D+k7ms6km97lwyv+I=",
- "requires": {
- "ansicolors": "~0.2.1",
- "redeyed": "~0.4.0"
- }
- },
"chalk": {
"version": "1.1.3",
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
@@ -3112,6 +3109,7 @@
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
+ "dev": true,
"requires": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
@@ -3312,7 +3310,8 @@
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
- "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
+ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
+ "dev": true
},
"create-ecdh": {
"version": "4.0.3",
@@ -3792,9 +3791,9 @@
}
},
"earcut": {
- "version": "2.2.1",
- "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.1.tgz",
- "integrity": "sha512-5jIMi2RB3HtGPHcYd9Yyl0cczo84y+48lgKPxMijliNQaKAHEZJbdzLmKmdxG/mCdS/YD9DQ1gihL8mxzR0F9w=="
+ "version": "2.2.2",
+ "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.2.tgz",
+ "integrity": "sha512-eZoZPPJcUHnfRZ0PjLvx2qBordSiO8ofC3vt+qACLM95u+4DovnbYNpQtJh0DNsWj8RnxrQytD4WA8gj5cRIaQ=="
},
"ee-first": {
"version": "1.1.1",
@@ -3934,11 +3933,6 @@
"estraverse": "^4.1.1"
}
},
- "esprima": {
- "version": "1.0.4",
- "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
- "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0="
- },
"esrecurse": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz",
@@ -5000,9 +4994,9 @@
"dev": true
},
"gl-matrix": {
- "version": "3.1.0",
- "resolved": "https://registry.npmjs.org/gl-matrix/-/gl-matrix-3.1.0.tgz",
- "integrity": "sha512-526NA+3EA+ztAQi0IZpSWiM0fyQXIp7IbRvfJ4wS/TjjQD0uv0fVybXwwqqSOlq33UckivI0yMDlVtboWm3k7A=="
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/gl-matrix/-/gl-matrix-3.3.0.tgz",
+ "integrity": "sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA=="
},
"glob": {
"version": "7.1.3",
@@ -5480,6 +5474,12 @@
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
"dev": true
},
+ "in-browser-language": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/in-browser-language/-/in-browser-language-1.0.3.tgz",
+ "integrity": "sha512-kVKHZiWj+pDMLW/YaIP/r8OyaYVZZ4BZ/kD+fQrEp+FCoH/mprIIQhsEnUVkPuNEXCP5ZeWArOWz0KzDaLgICg==",
+ "dev": true
+ },
"infer-owner": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/infer-owner/-/infer-owner-1.0.4.tgz",
@@ -5782,7 +5782,8 @@
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
- "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
+ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
+ "dev": true
},
"isexe": {
"version": "2.0.0",
@@ -5947,6 +5948,21 @@
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"dev": true
},
+ "lodash.invert": {
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/lodash.invert/-/lodash.invert-4.3.0.tgz",
+ "integrity": "sha1-j/4g1LYW9WvqjxqgxuvYDc90Ku4="
+ },
+ "lodash.isequal": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
+ "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
+ },
+ "lodash.sortby": {
+ "version": "4.7.0",
+ "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
+ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
+ },
"loglevel": {
"version": "1.6.6",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.6.6.tgz",
@@ -6017,33 +6033,40 @@
}
},
"mapbox-gl": {
- "version": "1.5.0",
- "resolved": "https://registry.npmjs.org/mapbox-gl/-/mapbox-gl-1.5.0.tgz",
- "integrity": "sha512-seTQUttE7XaL93on+zfLv06HmROsIdTh3riEPrBdbylSirLmBRnofG+iV873ZbJQElf+d2USyHpWAJm37RehEQ==",
+ "version": "1.10.1",
+ "resolved": "https://registry.npmjs.org/mapbox-gl/-/mapbox-gl-1.10.1.tgz",
+ "integrity": "sha512-0aHt+lFUpYfvh0kMIqXqNXqoYMuhuAsMlw87TbhWrw78Tx2zfuPI0Lx31/YPUgJ+Ire0tzQ4JnuBL7acDNXmMg==",
"requires": {
- "@mapbox/geojson-rewind": "^0.4.0",
+ "@mapbox/geojson-rewind": "^0.5.0",
"@mapbox/geojson-types": "^1.0.2",
"@mapbox/jsonlint-lines-primitives": "^2.0.2",
- "@mapbox/mapbox-gl-supported": "^1.4.0",
+ "@mapbox/mapbox-gl-supported": "^1.5.0",
"@mapbox/point-geometry": "^0.1.0",
- "@mapbox/tiny-sdf": "^1.1.0",
+ "@mapbox/tiny-sdf": "^1.1.1",
"@mapbox/unitbezier": "^0.0.0",
"@mapbox/vector-tile": "^1.3.1",
"@mapbox/whoots-js": "^3.1.0",
- "csscolorparser": "~1.0.2",
- "earcut": "^2.2.0",
+ "csscolorparser": "~1.0.3",
+ "earcut": "^2.2.2",
"geojson-vt": "^3.2.1",
- "gl-matrix": "^3.0.0",
+ "gl-matrix": "^3.2.1",
"grid-index": "^1.1.0",
- "minimist": "0.0.8",
+ "minimist": "^1.2.5",
"murmurhash-js": "^1.0.0",
"pbf": "^3.2.1",
"potpack": "^1.0.1",
"quickselect": "^2.0.0",
"rw": "^1.3.3",
- "supercluster": "^6.0.1",
- "tinyqueue": "^2.0.0",
+ "supercluster": "^7.0.0",
+ "tinyqueue": "^2.0.3",
"vt-pbf": "^3.1.1"
+ },
+ "dependencies": {
+ "minimist": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
+ }
}
},
"mapnik": {
@@ -6204,7 +6227,8 @@
"minimist": {
"version": "0.0.8",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
- "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
+ "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
+ "dev": true
},
"minipass": {
"version": "2.9.0",
@@ -7155,7 +7179,8 @@
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
- "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
+ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
+ "dev": true
},
"promise-inflight": {
"version": "1.0.1",
@@ -7164,9 +7189,9 @@
"dev": true
},
"protocol-buffers-schema": {
- "version": "3.3.2",
- "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.3.2.tgz",
- "integrity": "sha512-Xdayp8sB/mU+sUV4G7ws8xtYMGdQnxbeIfLjyO9TZZRJdztBGhlmbI5x1qcY4TG5hBkIKGnc28i7nXxaugu88w=="
+ "version": "3.4.0",
+ "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.4.0.tgz",
+ "integrity": "sha512-G/2kcamPF2S49W5yaMGdIpkG6+5wZF0fzBteLKgEHjbNzqjZQ85aAs1iJGto31EJaSTkNvHs5IXuHSaTLWBAiA=="
},
"proxy-addr": {
"version": "2.0.5",
@@ -7341,6 +7366,7 @@
"version": "2.3.6",
"resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
+ "dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@@ -7362,14 +7388,6 @@
"readable-stream": "^2.0.2"
}
},
- "redeyed": {
- "version": "0.4.4",
- "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-0.4.4.tgz",
- "integrity": "sha1-N+mQpvKyGyoRwuakj9QTVpjLqX8=",
- "requires": {
- "esprima": "~1.0.4"
- }
- },
"redom": {
"version": "3.24.2",
"resolved": "https://registry.npmjs.org/redom/-/redom-3.24.2.tgz",
@@ -7824,23 +7842,6 @@
"safe-buffer": "^5.0.1"
}
},
- "sharkdown": {
- "version": "0.1.1",
- "resolved": "https://registry.npmjs.org/sharkdown/-/sharkdown-0.1.1.tgz",
- "integrity": "sha512-exwooSpmo5s45lrexgz6Q0rFQM574wYIX3iDZ7RLLqOb7IAoQZu9nxlZODU972g19sR69OIpKP2cpHTzU+PHIg==",
- "requires": {
- "cardinal": "~0.4.2",
- "minimist": "0.0.5",
- "split": "~0.2.10"
- },
- "dependencies": {
- "minimist": {
- "version": "0.0.5",
- "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
- "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY="
- }
- }
- },
"shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
@@ -8144,14 +8145,6 @@
}
}
},
- "split": {
- "version": "0.2.10",
- "resolved": "http://registry.npmjs.org/split/-/split-0.2.10.tgz",
- "integrity": "sha1-Zwl8YB1pfOE2j0GPBs0gHPBSGlc=",
- "requires": {
- "through": "2"
- }
- },
"split-string": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",
@@ -8296,9 +8289,9 @@
}
},
"supercluster": {
- "version": "6.0.2",
- "resolved": "https://registry.npmjs.org/supercluster/-/supercluster-6.0.2.tgz",
- "integrity": "sha512-aa0v2HURjBTOpbcknilcfxGDuArM8khklKSmZ/T8ZXL0BuRwb5aRw95lz+2bmWpFvCXDX/+FzqHxmg0TIaJErw==",
+ "version": "7.0.0",
+ "resolved": "https://registry.npmjs.org/supercluster/-/supercluster-7.0.0.tgz",
+ "integrity": "sha512-8VuHI8ynylYQj7Qf6PBMWy1PdgsnBiIxujOgc9Z83QvJ8ualIYWNx2iMKyKeC4DZI5ntD9tz/CIwwZvIelixsA==",
"requires": {
"kdbush": "^3.0.0"
}
@@ -8374,11 +8367,6 @@
}
}
},
- "through": {
- "version": "2.3.8",
- "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
- "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
- },
"through2": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz",
@@ -9326,11 +9314,6 @@
"integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==",
"dev": true
},
- "wgs84": {
- "version": "0.0.0",
- "resolved": "https://registry.npmjs.org/wgs84/-/wgs84-0.0.0.tgz",
- "integrity": "sha1-NP3FVZF7blfPKigu0ENxDASc3HY="
- },
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
diff --git a/package.json b/package.json
index 83d49af..8a404c0 100644
--- a/package.json
+++ b/package.json
@@ -38,8 +38,11 @@
"in-browser-language": "^1.0.3"
},
"dependencies": {
- "mapbox-gl": "^1.5.0",
+ "mapbox-gl": "^1.10.1",
"redom": "^3.24.2",
- "title-case": "^2.1.1"
+ "title-case": "^2.1.1",
+ "lodash.invert": "^4.3.0",
+ "lodash.isequal": "^4.5.0",
+ "lodash.sortby": "^4.7.0"
}
}
diff --git a/src/index.js b/src/index.js
index f58a7e8..75bf31c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,13 +4,15 @@ import mapboxgl from 'mapbox-gl';
import {mount} from 'redom';
import EditButton from './editbutton.js';
+import URLHash from './urlhash.js';
import InfoBox from './infobox.js';
import InfoPopup from './infopopup.js';
import KeyControl from './key/key.js';
-import LayerSwitcher from './layerswitcher.js';
+import LayerSwitcher from './layerswitcher/layerswitcher.js';
import map_style from './style/style.json';
import style_base from './style/style_base.js';
+import style_labels from './style/style_labels.js';
import style_oim_power from './style/style_oim_power.js';
import style_oim_power_heatmap from './style/style_oim_power_heatmap.js';
import style_oim_telecoms from './style/style_oim_telecoms.js';
@@ -53,25 +55,32 @@ function init() {
Telecoms: 'telecoms_',
'Oil & Gas': 'petroleum_',
Water: 'water_',
+ Labels: 'place_',
};
- const layers_enabled = ['Power', 'Telecoms'];
+ const layers_enabled = ['Power', 'Telecoms', 'Labels'];
const layer_switcher = new LayerSwitcher(layers, layers_enabled);
+ var url_hash = new URLHash(layer_switcher);
+ layer_switcher.urlhash = url_hash;
- map_style.layers = style_base.concat(oim_layers);
+ map_style.layers = style_base.concat(oim_layers, style_labels);
+
+ layer_switcher.setInitialVisibility(map_style);
if (DEV) {
map_style['sprite'] = 'http://localhost:8080/style/sprite';
//map_style['sources']['openinframap']['url'] = 'http://localhost:8081/capabilities/openinframap.json'
}
- var map = new mapboxgl.Map({
+ var map = new mapboxgl.Map(Object.assign({
container: 'map',
style: map_style,
- hash: true,
+ hash: false,
minZoom: 2,
maxZoom: 17.9,
center: [12, 26],
- });
+ }, url_hash.getPosition()));
+
+ url_hash.onAdd(map);
map.addControl(new mapboxgl.NavigationControl(), 'top-right');
map.addControl(
new mapboxgl.GeolocateControl({
diff --git a/src/layerswitcher.css b/src/layerswitcher.css
deleted file mode 100644
index 21a6f81..0000000
--- a/src/layerswitcher.css
+++ /dev/null
@@ -1,34 +0,0 @@
-.layer-switcher {
- min-height: 30px;
- min-width: 30px;
- background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-layers"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>')
- white;
- background-repeat: no-repeat;
- background-size: 15px 15px;
- background-position: center;
-}
-
-.layer-switcher-list {
- background: white;
- padding-left: 8px;
- padding-right: 8px;
- position: relative;
- display: none;
- margin: 0 !important;
-}
-
-.layer-switcher-list h3 {
- margin: 0px;
- margin-top: 3px;
-}
-
-.layer-switcher-list ul {
- list-style: none;
- padding: 0;
- user-select: none;
-}
-
-.layer-switcher-list input {
- margin: 0;
- margin-right: 5px;
-}
diff --git a/src/layerswitcher/layerswitcher.css b/src/layerswitcher/layerswitcher.css
new file mode 100644
index 0000000..d1bcc0a
--- /dev/null
+++ b/src/layerswitcher/layerswitcher.css
@@ -0,0 +1,47 @@
+.layer-switcher {
+ min-height: 30px;
+ min-width: 30px;
+ background: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%228%22%20height%3D%228%22%20viewBox%3D%220%200%208%208%22%3E%0A%20%20%3Cpath%20d%3D%22M0%200v4h4v-4h-4zm5%202v3h-3v1h4v-4h-1zm2%202v3h-3v1h4v-4h-1z%22%20/%3E%0A%3C/svg%3E')
+ white;
+ background-repeat: no-repeat;
+ background-size: 15px 15px;
+ background-position: center;
+}
+
+.layer-switcher-list {
+ background: white;
+ padding-left: 8px;
+ padding-right: 8px;
+ position: relative;
+ display: none;
+ margin: 0 !important;
+ font-size: 15px;
+}
+
+.layer-switcher-list h3 {
+ margin: 0px;
+ margin-top: 6px;
+}
+
+.layer-switcher-list ul {
+ list-style: none;
+ padding: 0;
+ user-select: none;
+ margin-bottom: 4px;
+}
+
+.layer-switcher-list li {
+ display: block;
+ width: 100%;
+ height: 25px;
+}
+
+.layer-switcher-list input {
+ margin-left: 8px;
+ margin-top: 4px;
+ float: right;
+}
+
+.layer-switcher-list label {
+ float: left;
+}
diff --git a/src/layerswitcher.js b/src/layerswitcher/layerswitcher.js
similarity index 61%
rename from src/layerswitcher.js
rename to src/layerswitcher/layerswitcher.js
index ec40c30..427109f 100644
--- a/src/layerswitcher.js
+++ b/src/layerswitcher/layerswitcher.js
@@ -1,12 +1,41 @@
import {el, text} from 'redom';
+import invert from 'lodash.invert';
+import isEqual from 'lodash.isequal';
import './layerswitcher.css';
class LayerSwitcher {
- constructor(layers, visible = []) {
+ constructor(layers, default_visible = []) {
this._layers = layers;
- this._visible = visible;
+ this._identifiers = this._initLayerIdentifiers();
+ this._default_visible = default_visible;
this._container = el('div', {class: 'mapboxgl-ctrl layer-switcher-list'});
this._container.appendChild(el('h3', 'Layers'));
+ this._visible = [...default_visible];
+ }
+
+ _initLayerIdentifiers() {
+ let identifiers = {};
+ Object.keys(this._layers)
+ .sort()
+ .forEach(layer_name => {
+ let size = 1;
+ let ident = null;
+ do {
+ ident = layer_name.slice(0, size);
+ size++;
+ } while (ident in identifiers);
+ identifiers[ident] = layer_name;
+ });
+ return identifiers;
+ }
+
+ _getLayerIdentifiers() {
+ let identifiers = [];
+ let id_map = invert(this._identifiers);
+ this._visible.sort().forEach(layer_name => {
+ identifiers.push(id_map[layer_name]);
+ });
+ return identifiers;
}
_updateVisibility() {
@@ -24,10 +53,13 @@ class LayerSwitcher {
}
}
}
+ if (this.urlhash) {
+ this.urlhash._updateHash();
+ }
}
setInitialVisibility(style) {
- /**
+ /**
* Modify a map style before adding to the map to set initial visibility states.
* This prevents flash-of-invisible-layers.
*/
@@ -47,6 +79,29 @@ class LayerSwitcher {
}
}
+ getURLString() {
+ if (!isEqual(this._visible.sort(), this._default_visible.sort())) {
+ return this._getLayerIdentifiers().join(',');
+ }
+ return null;
+ }
+
+ setURLString(string) {
+ if (string) {
+ const ids = string.split(',');
+ if (ids.length == 0) {
+ this._visible = [...this._default_visible];
+ } else {
+ this._visible = ids.map(id => this._identifiers[id]).filter(id => id);
+ }
+ } else {
+ this._visible = [...this._default_visible];
+ }
+ if (this._map) {
+ this._updateVisibility();
+ }
+ }
+
onAdd(map) {
this._map = map;
if (map.isStyleLoaded()) {
@@ -91,7 +146,8 @@ class LayerSwitcher {
this._updateVisibility();
};
- list.appendChild(el('li', [checkbox, label]));
+ let li = el('li', [label, checkbox]);
+ list.appendChild(li);
i++;
}
this._container.appendChild(list);
diff --git a/src/style/style_labels.js b/src/style/style_labels.js
new file mode 100644
index 0000000..4a38974
--- /dev/null
+++ b/src/style/style_labels.js
@@ -0,0 +1,259 @@
+const text_color = 'hsl(0, 0%, 20%)';
+const text_halo_color = 'rgb(242,243,240)';
+
+const layers = [
+ {
+ id: 'place_suburb',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 12,
+ maxzoom: 17,
+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'suburb']],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0],
+ 'text-size': {base: 1, stops: [[12, 9], [17, 17]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_village',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 12,
+ maxzoom: 17,
+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'village']],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0.2],
+ 'text-size': {base: 1, stops: [[12, 9], [17, 18]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_town',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 10,
+ maxzoom: 15,
+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'town']],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0.2],
+ 'text-size': {base: 1, stops: [[10, 9], [15, 18]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_city',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 7.5,
+ maxzoom: 14,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['all', ['!=', 'capital', 2], ['==', 'class', 'city'], ['>', 'rank', 3]],
+ ],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0.2],
+ 'text-size': 12,
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_capital',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 5.5,
+ maxzoom: 12,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['all', ['==', 'capital', 2], ['==', 'class', 'city']],
+ ],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0.2],
+ 'text-size': 14,
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_city_large',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 7,
+ maxzoom: 12,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['all', ['!=', 'capital', 2], ['<=', 'rank', 3], ['==', 'class', 'city']],
+ ],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-justify': 'center',
+ 'text-offset': [0.5, 0.2],
+ 'text-size': 14,
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_state',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ minzoom: 5,
+ maxzoom: 12,
+ filter: ['all', ['==', '$type', 'Point'], ['==', 'class', 'state']],
+ layout: {
+ 'text-field': '{name:latin}\n{name:nonlatin}',
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-size': 15,
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-blur': 1,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_country_other',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ maxzoom: 8,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['==', 'class', 'country'],
+ ['!has', 'iso_a2'],
+ ],
+ layout: {
+ 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],
+ 'text-font': ['Metropolis Light Italic', 'Noto Sans Italic'],
+ 'text-size': {base: 1, stops: [[0, 9], [6, 13]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_country_minor',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ maxzoom: 8,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['==', 'class', 'country'],
+ ['>=', 'rank', 2],
+ ['has', 'iso_a2'],
+ ],
+ layout: {
+ 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-size': {base: 1, stops: [[0, 10], [6, 12]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2,
+ },
+ },
+ {
+ id: 'place_country_major',
+ type: 'symbol',
+ source: 'openmaptiles',
+ 'source-layer': 'place',
+ maxzoom: 5,
+ filter: [
+ 'all',
+ ['==', '$type', 'Point'],
+ ['<=', 'rank', 1],
+ ['==', 'class', 'country'],
+ ['has', 'iso_a2'],
+ ],
+ layout: {
+ 'text-anchor': 'center',
+ 'text-field': ['case', ['has', 'name:en'], ['get', 'name:en'], ['get', 'name:latin']],
+ 'text-font': ['Metropolis Regular', 'Noto Sans Regular'],
+ 'text-size': {base: 1.4, stops: [[0, 10], [3, 12], [4, 14]]},
+ visibility: 'visible',
+ },
+ paint: {
+ 'text-color': text_color,
+ 'text-halo-color': text_halo_color,
+ 'text-halo-width': 2.4,
+ },
+ },
+];
+
+export default layers;
diff --git a/src/urlhash.js b/src/urlhash.js
new file mode 100644
index 0000000..7a699f4
--- /dev/null
+++ b/src/urlhash.js
@@ -0,0 +1,99 @@
+
+
+class URLHash {
+
+ constructor(layerSwitcher) {
+ this.layerSwitcher = layerSwitcher;
+ this._onHashChange();
+ }
+
+ onAdd(map) {
+ this._map = map;
+ map.on('moveend', () => {
+ this._updateHash();
+ });
+
+ window.addEventListener(
+ 'hashchange',
+ () => {
+ this._onHashChange();
+ },
+ false,
+ );
+ }
+
+ _onHashChange() {
+ const loc = window.location.hash.replace('#', '').split('/');
+ if (loc.length >= 3) {
+ let layerString = "";
+ if (this._map) {
+ this._map.jumpTo({
+ center: [+loc[2], +loc[1]],
+ zoom: +loc[0],
+ });
+ }
+ for (let i = 3; i < loc.length; i++) {
+ let component = loc[i];
+ let matches = component.match(/([a-z])=(.*)/);
+ if (matches) {
+ if (matches[1] == 'm') {
+ markerString = matches[2];
+ } else {
+ return false;
+ }
+ } else {
+ layerString = component;
+ }
+ }
+ this.layerSwitcher.setURLString(layerString);
+ return true;
+ }
+ this.layerSwitcher.setURLString("");
+ return false;
+ }
+
+ _updateHash() {
+ try {
+ window.history.replaceState(
+ window.history.state,
+ '',
+ this.getHashString(),
+ );
+ } catch (e) {
+ console.log(e);
+ }
+ }
+
+ getHashString() {
+ const center = this._map.getCenter(),
+ zoom = Math.round(this._map.getZoom() * 100) / 100,
+ // derived from equation: 512px * 2^z / 360 / 10^d < 0.5px
+ precision = Math.ceil(
+ (zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10,
+ ),
+ m = Math.pow(10, precision),
+ lng = Math.round(center.lng * m) / m,
+ lat = Math.round(center.lat * m) / m,
+ bearing = this._map.getBearing(),
+ pitch = this._map.getPitch();
+ let hash = `#${zoom}/${lat}/${lng}`;
+ let layers = this.layerSwitcher.getURLString();
+ if (layers) {
+ hash += '/' + layers;
+ }
+ return hash;
+ }
+
+ getPosition() {
+ const loc = window.location.hash.replace('#', '').split('/');
+ if (loc.length >= 3) {
+ return {
+ center: [+loc[2], +loc[1]],
+ zoom: +loc[0],
+ };
+ }
+ return {};
+ }
+};
+
+export default URLHash;