From e913e2ca7260d9a827a51f02d94cad63b9192298 Mon Sep 17 00:00:00 2001 From: George Owen Date: Fri, 12 May 2023 17:08:46 -0700 Subject: [PATCH 01/17] add support for v2 styles #174 --- examples/languages.html | 125 ++++++++++++++++++++++++++++++++++++++ package-lock.json | 111 +++++++++++++++++++++++++++------ package.json | 4 +- src/Util.js | 16 ++++- src/VectorBasemapLayer.js | 15 ++++- 5 files changed, 247 insertions(+), 24 deletions(-) create mode 100644 examples/languages.html diff --git a/examples/languages.html b/examples/languages.html new file mode 100644 index 0000000..ee95a9c --- /dev/null +++ b/examples/languages.html @@ -0,0 +1,125 @@ + + + + + Esri Leaflet Tutorials: Change the basemap style + + + + + + + + + + + + + + + +
+
+ + + +
+ + + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e457d49..8df1417 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "karma-safari-launcher": "~1.0.0", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.8", - "leaflet": "^1.5.0", + "leaflet": "^1.9.3", "mkdirp": "^2.1.3", "mocha": "^10.2.0", "npm-run-all": "^4.1.5", @@ -49,7 +49,7 @@ "peerDependencies": { "esri-leaflet": ">2.3.0", "leaflet": "^1.5.0", - "maplibre-gl": "^2.2.1" + "maplibre-gl": "^2.4.0" } }, "node_modules/@ampproject/remapping": { @@ -3711,6 +3711,38 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/global-prefix": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-3.0.0.tgz", + "integrity": "sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==", + "peer": true, + "dependencies": { + "ini": "^1.3.5", + "kind-of": "^6.0.2", + "which": "^1.3.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/global-prefix/node_modules/ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "peer": true + }, + "node_modules/global-prefix/node_modules/which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "peer": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/globals": { "version": "13.17.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", @@ -4589,8 +4621,7 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/istanbul-lib-coverage": { "version": "3.2.0", @@ -5093,6 +5124,15 @@ "json-buffer": "3.0.0" } }, + "node_modules/kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -5106,9 +5146,9 @@ } }, "node_modules/leaflet": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.8.0.tgz", - "integrity": "sha512-gwhMjFCQiYs3x/Sf+d49f10ERXaEFCPr+nVTryhAW8DWbMGqJqt9G4XuIaHmFW08zYvhgdzqXGr8AlW8v8dQkA==", + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.3.tgz", + "integrity": "sha512-iB2cR9vAkDOu5l3HAay2obcUHZ7xwUBBjph8+PGtmW/2lYhbLizWtG7nTeYht36WfOslixQF9D/uSIzhZgGMfQ==", "dev": true }, "node_modules/levn": { @@ -5389,9 +5429,9 @@ } }, "node_modules/maplibre-gl": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.3.0.tgz", - "integrity": "sha512-91vc5Quu9UDw0S90pJMDuE24XvXUjIYGaD5DTlhNs3egVmX0QwCpWl1R2tots3slHbZRJcQdRGUNxW7hKpi0Ow==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.4.0.tgz", + "integrity": "sha512-csNFylzntPmHWidczfgCZpvbTSmhaWvLRj9e1ezUDBEPizGgshgm3ea1T5TCNEEBq0roauu7BPuRZjA3wO4KqA==", "hasInstallScript": true, "peer": true, "dependencies": { @@ -5411,6 +5451,7 @@ "earcut": "^2.2.4", "geojson-vt": "^3.2.1", "gl-matrix": "^3.4.3", + "global-prefix": "^3.0.0", "murmurhash-js": "^1.0.0", "pbf": "^3.2.1", "potpack": "^1.0.2", @@ -11627,6 +11668,34 @@ "ini": "2.0.0" } }, + "global-prefix": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-3.0.0.tgz", + "integrity": "sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==", + "peer": true, + "requires": { + "ini": "^1.3.5", + "kind-of": "^6.0.2", + "which": "^1.3.1" + }, + "dependencies": { + "ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "peer": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "peer": true, + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "globals": { "version": "13.17.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", @@ -12250,8 +12319,7 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "istanbul-lib-coverage": { "version": "3.2.0", @@ -12665,6 +12733,12 @@ "json-buffer": "3.0.0" } }, + "kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "peer": true + }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -12675,9 +12749,9 @@ } }, "leaflet": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.8.0.tgz", - "integrity": "sha512-gwhMjFCQiYs3x/Sf+d49f10ERXaEFCPr+nVTryhAW8DWbMGqJqt9G4XuIaHmFW08zYvhgdzqXGr8AlW8v8dQkA==", + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.3.tgz", + "integrity": "sha512-iB2cR9vAkDOu5l3HAay2obcUHZ7xwUBBjph8+PGtmW/2lYhbLizWtG7nTeYht36WfOslixQF9D/uSIzhZgGMfQ==", "dev": true }, "levn": { @@ -12907,9 +12981,9 @@ } }, "maplibre-gl": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.3.0.tgz", - "integrity": "sha512-91vc5Quu9UDw0S90pJMDuE24XvXUjIYGaD5DTlhNs3egVmX0QwCpWl1R2tots3slHbZRJcQdRGUNxW7hKpi0Ow==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.4.0.tgz", + "integrity": "sha512-csNFylzntPmHWidczfgCZpvbTSmhaWvLRj9e1ezUDBEPizGgshgm3ea1T5TCNEEBq0roauu7BPuRZjA3wO4KqA==", "peer": true, "requires": { "@mapbox/geojson-rewind": "^0.5.2", @@ -12928,6 +13002,7 @@ "earcut": "^2.2.4", "geojson-vt": "^3.2.1", "gl-matrix": "^3.4.3", + "global-prefix": "^3.0.0", "murmurhash-js": "^1.0.0", "pbf": "^3.2.1", "potpack": "^1.0.2", diff --git a/package.json b/package.json index b0e3d07..35aefec 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "peerDependencies": { "esri-leaflet": ">2.3.0", "leaflet": "^1.5.0", - "maplibre-gl": "^2.2.1" + "maplibre-gl": "^2.4.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.1", @@ -44,7 +44,7 @@ "karma-safari-launcher": "~1.0.0", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.8", - "leaflet": "^1.5.0", + "leaflet": "^1.9.3", "mkdirp": "^2.1.3", "mocha": "^10.2.0", "npm-run-all": "^4.1.5", diff --git a/src/Util.js b/src/Util.js index 1b74331..a42ced5 100644 --- a/src/Util.js +++ b/src/Util.js @@ -5,10 +5,10 @@ import { request, Support, Util } from 'esri-leaflet'; utility to establish a URL for the basemap styles API used primarily by VectorBasemapLayer.js */ -export function getBasemapStyleUrl (key, apikey) { +export function getBasemapStyleUrl (style, apikey) { let url = 'https://basemaps-api.arcgis.com/arcgis/rest/services/styles/' + - key + + style + '?type=style'; if (apikey) { url = url + '&apiKey=' + apikey; @@ -16,6 +16,18 @@ export function getBasemapStyleUrl (key, apikey) { return url; } +export function getBasemapStyleV2Url (sourceAndStyle, apikey, language) { + let url = + 'https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/' + sourceAndStyle; + + if (apikey) { + url = url + '?token=' + apikey; + } + if (language) { + url = url + '&language=' + language; + } + return url; +} /* utilities to communicate with custom user styles via an ITEM ID or SERVICE URL used primarily by VectorTileLayer.js diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index 6bdd47c..404c96b 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -1,6 +1,6 @@ import { Layer, setOptions } from 'leaflet'; import { Util } from 'esri-leaflet'; -import { getBasemapStyleUrl, getAttributionData } from './Util'; +import { getBasemapStyleUrl, getAttributionData, getBasemapStyleV2Url } from './Util'; import { maplibreGLJSLayer } from './MaplibreGLLayer'; export var VectorBasemapLayer = Layer.extend({ @@ -34,6 +34,12 @@ export var VectorBasemapLayer = Layer.extend({ throw new Error('API Key or token is required for vectorBasemapLayer.'); } + if (this.options.language) { + if (!this.options.version || this.options.version !== 2) { + throw new Error('The language parameter is only supported by the basemap styles service v2. Set version:2 to use this property.'); + } + } + // set key onto "this.options" for use elsewhere in the module. if (key) { this.options.key = key; @@ -47,7 +53,12 @@ export var VectorBasemapLayer = Layer.extend({ * Creates the maplibreGLJSLayer given using "this.options" */ _createLayer: function () { - const styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); + let styleUrl; + if (this.options.version && this.options.version === 2) { + styleUrl = getBasemapStyleV2Url(this.options.key, this.options.apikey, this.options.language); + } else { + styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); + } this._maplibreGL = maplibreGLJSLayer({ style: styleUrl, From e5b7ad68689c9c17f03cb5689ff4e27592dcc280 Mon Sep 17 00:00:00 2001 From: George Owen Date: Tue, 16 May 2023 14:45:31 -0700 Subject: [PATCH 02/17] suggestions from code review --- examples/languages.html | 27 +++------------------------ package.json | 4 ++-- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/examples/languages.html b/examples/languages.html index ee95a9c..70c5b86 100644 --- a/examples/languages.html +++ b/examples/languages.html @@ -34,38 +34,17 @@ color: #323232; } - /* @@Start(basemaps-wrapper-css) */ - #languages-wrapper { - position: absolute; - top: 20px; - right: 20px; - - } - #languages { - font-size: 16px; - padding: 4px 8px; - } - /* @@End(basemaps-wrapper-css) */ -
-
- - - -
- +
+ + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/customize-vtl-style.html b/examples/customize-vtl-style.html new file mode 100644 index 0000000..7601a7d --- /dev/null +++ b/examples/customize-vtl-style.html @@ -0,0 +1,79 @@ + + + + + + Esri Leaflet: Customize a vector tile layer style + + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index 5d01d11..b600eee 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -1,9 +1,8 @@ -import { Layer, setOptions } from 'leaflet'; import { Util } from 'esri-leaflet'; import { getBasemapStyleUrl, getAttributionData, getBasemapStyleV2Url } from './Util'; -import { maplibreGLJSLayer } from './MaplibreGLLayer'; +import { VectorTileLayer } from './VectorTileLayer'; -export var VectorBasemapLayer = Layer.extend({ +export var VectorBasemapLayer = VectorTileLayer.extend({ options: { key: 'ArcGIS:Streets' // default style key enum if none provided }, @@ -15,63 +14,35 @@ export var VectorBasemapLayer = Layer.extend({ * @param {object} options optional */ initialize: function (key, options) { - if (options) { - setOptions(this, options); - } - - // support outdated casing apiKey of apikey - if (this.options.apiKey) { - this.options.apikey = this.options.apiKey; - } - - // if token is passed in, use it as an apiKey - if (this.options.token) { - this.options.apikey = this.options.token; - } - - // If no API Key or token is required: - if (!(this.options.apikey || this.options.token)) { - throw new Error('API Key or token is required for vectorBasemapLayer.'); - } - // Set endpoint to the v1 service by default - if (!this.options.version) { - this.options.version = 1; + if (!options.version) { + options.version = 1; } - - if (this.options.language) { - if (this.options.version !== 2) { + if (options.language) { + if (options.version !== 2) { throw new Error('The language parameter is only supported by the basemap styles service v2. Set version:2 to use this property.'); } } - // set key onto "this.options" for use elsewhere in the module. - if (key) { - this.options.key = key; + // If no API Key or token is provided (support outdated casing apiKey of apikey) + if (!(options.apikey || options.apiKey || options.token)) { + throw new Error('API Key or token is required for vectorBasemapLayer.'); } // determine layer order if (!options.pane) { - if (this._isLabelsStyle()) { - this.options.pane = 'esri-labels'; - } else if (this._isDetailStyle()) { - this.options.pane = 'esri-detail'; + if (key.indexOf(':Label') > -1 || key.indexOf('/label') > -1) { + options.pane = 'esri-labels'; + } else if (key.indexOf(':Detail') > -1 || key.indexOf('/detail') > -1) { + options.pane = 'esri-detail'; } else { // create layer in the tilePane by default - this.options.pane = 'tilePane'; + options.pane = 'tilePane'; } } - // this.options has been set, continue on to create the layer: - this._createLayer(); - }, - - _isLabelsStyle: function () { - return (this.options.key.indexOf(':Label') > -1 || this.options.key.indexOf('/label') > -1); - }, - - _isDetailStyle: function () { - return (this.options.key.indexOf(':Detail') > -1 || this.options.key.indexOf('/detail') > -1); + // options has been configured, continue on to create the layer: + VectorTileLayer.prototype.initialize.call(this, key, options); }, /** @@ -85,24 +56,12 @@ export var VectorBasemapLayer = Layer.extend({ styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); } - this._maplibreGL = maplibreGLJSLayer({ - style: styleUrl, - pane: this.options.pane, - opacity: this.options.opacity - }); - - this._ready = true; - this.fire('ready', {}, true); - - this._maplibreGL.on('styleLoaded', function (res) { - this._setupAttribution(); - }.bind(this)); + this._createMaplibreLayer(styleUrl); }, _setupAttribution: function () { - const map = this._map; // Set attribution - Util.setEsriAttribution(map); + Util.setEsriAttribution(this._map); if (this.options.key.length === 32) { // this is an itemId @@ -115,7 +74,7 @@ export var VectorBasemapLayer = Layer.extend({ } }); - map.attributionControl.addAttribution('' + allAttributions.join(', ') + ''); + this._map.attributionControl.addAttribution('' + allAttributions.join(', ') + ''); } else { // this is an enum if (!this.options.attributionUrls) { @@ -130,10 +89,10 @@ export var VectorBasemapLayer = Layer.extend({ index++ ) { const attributionUrl = this.options.attributionUrls[index]; - getAttributionData(attributionUrl, map); + getAttributionData(attributionUrl, this._map); } - map.attributionControl.addAttribution( + this._map.attributionControl.addAttribution( '' ); } @@ -175,22 +134,6 @@ export var VectorBasemapLayer = Layer.extend({ } }, - onAdd: function (map) { - this._map = map; - - if (this._ready) { - this._asyncAdd(); - } else { - this.once( - 'ready', - function () { - this._asyncAdd(); - }, - this - ); - } - }, - onRemove: function (map) { map.off('moveend', Util._updateMapAttribution); map.removeLayer(this._maplibreGL); diff --git a/src/VectorTileLayer.js b/src/VectorTileLayer.js index 14ceac7..25794f7 100644 --- a/src/VectorTileLayer.js +++ b/src/VectorTileLayer.js @@ -4,10 +4,6 @@ import { maplibreGLJSLayer } from './MaplibreGLLayer'; export var VectorTileLayer = Layer.extend({ options: { - // if pane is not provided, default to LeafletJS's overlayPane - // https://leafletjs.com/reference.html#map-pane - pane: 'overlayPane', - // if portalUrl is not provided, default to ArcGIS Online portalUrl: 'https://www.arcgis.com' }, @@ -28,10 +24,12 @@ export var VectorTileLayer = Layer.extend({ this.options.apikey = this.options.apiKey; } - // if apiKey is passed in, use it as a token - // (opposite from VectorBasemapLayer.js) + // if apiKey is passed in, propogate to token + // if token is passed in, propogate to apikey if (this.options.apikey) { this.options.token = this.options.apikey; + } else if (this.options.token) { + this.options.apikey = this.options.token; } // if no key passed in @@ -73,37 +71,49 @@ export var VectorTileLayer = Layer.extend({ // once style object is loaded it must be transformed to be compliant with maplibreGLJSLayer style = formatStyle(style, styleUrl, service, this.options.token); - // if a custom attribution was not provided in the options, - // then attempt to rely on the attribution of the last source in the style object - // and add it to the map's attribution control - // (otherwise it would have already been added by leaflet to the attribution control) - if (!this.getAttribution()) { - const sourcesKeys = Object.keys(style.sources); - this.options.attribution = - style.sources[sourcesKeys[sourcesKeys.length - 1]].attribution; - if (this._map && this._map.attributionControl) { - // NOTE: if attribution is an empty string (or otherwise falsy) at this point it would not appear in the attribution control - this._map.attributionControl.addAttribution(this.getAttribution()); - } - } - - // additionally modify the style object with the user's optional style override function - if (this.options.style && typeof this.options.style === 'function') { - style = this.options.style(style); - } - - this._maplibreGL = maplibreGLJSLayer({ - style: style, - pane: this.options.pane, - opacity: this.options.opacity - }); - - this._ready = true; - this.fire('ready', {}, true); + this._createMaplibreLayer(style); }.bind(this) ); }, + _setupAttribution: function () { + // if a custom attribution was not provided in the options, + // then attempt to rely on the attribution of the last source in the style object + // and add it to the map's attribution control + // (otherwise it would have already been added by leaflet to the attribution control) + const sources = this._maplibreGL.getMaplibreMap().style.stylesheet.sources; + console.log(this.getAttribution()); + if (!this.getAttribution()) { + const sourcesKeys = Object.keys(sources); + this.options.attribution = + sources[sourcesKeys[sourcesKeys.length - 1]].attribution; + console.log(this.getAttribution()); + if (this._map && this._map.attributionControl) { + // NOTE: if attribution is an empty string (or otherwise falsy) at this point it would not appear in the attribution control + this._map.attributionControl.addAttribution(this.getAttribution()); + } + } + }, + + _createMaplibreLayer: function (style) { + this._maplibreGL = maplibreGLJSLayer({ + style: style, + pane: this.options.pane, + opacity: this.options.opacity + }); + + this._ready = true; + this.fire('ready', {}, true); + + this._maplibreGL.on('styleLoaded', function () { + this._setupAttribution(); + // additionally modify the style object with the user's optional style override function + if (this.options.style && typeof this.options.style === 'function') { + this._maplibreGL._glMap.setStyle(this.options.style(this._maplibreGL._glMap.getStyle())); + } + }.bind(this)); + }, + onAdd: function (map) { this._map = map; From 89be9d1dd4bf96c7e96dd6f63a83a15a15222e84 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 10:47:58 -0700 Subject: [PATCH 10/17] clean up inheritance change #150 --- src/VectorBasemapLayer.js | 29 ++++++++++++++--------------- src/VectorTileLayer.js | 4 +--- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index b600eee..e98042f 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -3,10 +3,6 @@ import { getBasemapStyleUrl, getAttributionData, getBasemapStyleV2Url } from './ import { VectorTileLayer } from './VectorTileLayer'; export var VectorBasemapLayer = VectorTileLayer.extend({ - options: { - key: 'ArcGIS:Streets' // default style key enum if none provided - }, - /** * Populates "this.options" to be used in the rest of the module. * @@ -14,39 +10,42 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ * @param {object} options optional */ initialize: function (key, options) { - // Set endpoint to the v1 service by default + // Default to the v1 service endpoint if (!options.version) { options.version = 1; } + if (!key) { + // Default style enum if none provided + key = options.version === 1 ? 'ArcGIS:Streets' : 'arcgis/streets'; + } + // If no API Key or token is provided (support outdated casing apiKey of apikey) + if (!(options.apikey || options.apiKey || options.token)) { + throw new Error('An API Key or token is required for vectorBasemapLayer.'); + } + // Validate language param if (options.language) { if (options.version !== 2) { throw new Error('The language parameter is only supported by the basemap styles service v2. Set version:2 to use this property.'); } } - - // If no API Key or token is provided (support outdated casing apiKey of apikey) - if (!(options.apikey || options.apiKey || options.token)) { - throw new Error('API Key or token is required for vectorBasemapLayer.'); - } - - // determine layer order + // Determine layer order if (!options.pane) { if (key.indexOf(':Label') > -1 || key.indexOf('/label') > -1) { options.pane = 'esri-labels'; } else if (key.indexOf(':Detail') > -1 || key.indexOf('/detail') > -1) { options.pane = 'esri-detail'; } else { - // create layer in the tilePane by default + // Create layer in the tilePane by default options.pane = 'tilePane'; } } - // options has been configured, continue on to create the layer: + // Options has been configured, continue on to create the layer: VectorTileLayer.prototype.initialize.call(this, key, options); }, /** - * Creates the maplibreGLJSLayer given using "this.options" + * Creates the maplibreGLJSLayer using "this.options" */ _createLayer: function () { let styleUrl; diff --git a/src/VectorTileLayer.js b/src/VectorTileLayer.js index 25794f7..d7df9fe 100644 --- a/src/VectorTileLayer.js +++ b/src/VectorTileLayer.js @@ -81,13 +81,11 @@ export var VectorTileLayer = Layer.extend({ // then attempt to rely on the attribution of the last source in the style object // and add it to the map's attribution control // (otherwise it would have already been added by leaflet to the attribution control) - const sources = this._maplibreGL.getMaplibreMap().style.stylesheet.sources; - console.log(this.getAttribution()); if (!this.getAttribution()) { + const sources = this._maplibreGL.getMaplibreMap().style.stylesheet.sources; const sourcesKeys = Object.keys(sources); this.options.attribution = sources[sourcesKeys[sourcesKeys.length - 1]].attribution; - console.log(this.getAttribution()); if (this._map && this._map.attributionControl) { // NOTE: if attribution is an empty string (or otherwise falsy) at this point it would not appear in the attribution control this._map.attributionControl.addAttribution(this.getAttribution()); From 1cc4a8ec4939ace3cfebc0a962dccbacb4af17b4 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 10:50:21 -0700 Subject: [PATCH 11/17] fix attribution sources for v2 #174 --- src/VectorBasemapLayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index e98042f..8e4c904 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -105,9 +105,9 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ * @param {string} key */ _getAttributionUrls: function (key) { - if (key.indexOf('OSM:') === 0) { + if (key.indexOf('OSM:') === 0 || (key.indexOf('osm/') === 0)) { return ['https://static.arcgis.com/attribution/Vector/OpenStreetMap_v2']; - } else if (key.indexOf('ArcGIS:Imagery') === 0) { + } else if (key.indexOf('ArcGIS:Imagery') === 0 || key.indexOf('arcgis/imagery') === 0) { return [ 'https://static.arcgis.com/attribution/World_Imagery', 'https://static.arcgis.com/attribution/Vector/World_Basemap_v2' From c8e78e9495bb6469ba27af4b24002faefcca7e78 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 13:32:42 -0700 Subject: [PATCH 12/17] revert version update (goes in separate pr) --- package-lock.json | 127 ++++++++++------------------------------------ package.json | 8 +-- 2 files changed, 30 insertions(+), 105 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28cdfcf..e457d49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.1.0", - "esri-leaflet": "^3.0.10", + "esri-leaflet": "^3.0.0", "gh-release": "^7.0.2", "http-server": "^14.1.1", "karma": "^6.4.1", @@ -36,7 +36,7 @@ "karma-safari-launcher": "~1.0.0", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.8", - "leaflet": "^1.9.4", + "leaflet": "^1.5.0", "mkdirp": "^2.1.3", "mocha": "^10.2.0", "npm-run-all": "^4.1.5", @@ -48,8 +48,8 @@ }, "peerDependencies": { "esri-leaflet": ">2.3.0", - "leaflet": "^1.9.4", - "maplibre-gl": "^2.4.0" + "leaflet": "^1.5.0", + "maplibre-gl": "^2.2.1" } }, "node_modules/@ampproject/remapping": { @@ -3132,9 +3132,9 @@ } }, "node_modules/esri-leaflet": { - "version": "3.0.10", - "resolved": "https://registry.npmjs.org/esri-leaflet/-/esri-leaflet-3.0.10.tgz", - "integrity": "sha512-2ma+mMHrJA7oqJFHZDLZrCAMkaXTdFFJRsJqlsh3Z2G+nXKj2SrlzJ2YmN5qgnI9y/X5AkcSfxViBoQTX9rcSw==", + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/esri-leaflet/-/esri-leaflet-3.0.8.tgz", + "integrity": "sha512-mLb4pRfDAbkG1YhuajD22erLXIAtrF1R32hmgmlJNI3t47n6KjTppCb8lViia0O7+GDORXFuJ9Lj9RkpsaKhSA==", "dev": true, "dependencies": { "@terraformer/arcgis": "^2.1.0", @@ -3711,38 +3711,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/global-prefix": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-3.0.0.tgz", - "integrity": "sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==", - "peer": true, - "dependencies": { - "ini": "^1.3.5", - "kind-of": "^6.0.2", - "which": "^1.3.1" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/global-prefix/node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "peer": true - }, - "node_modules/global-prefix/node_modules/which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "peer": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "which": "bin/which" - } - }, "node_modules/globals": { "version": "13.17.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", @@ -4621,7 +4589,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "node_modules/istanbul-lib-coverage": { "version": "3.2.0", @@ -5124,15 +5093,6 @@ "json-buffer": "3.0.0" } }, - "node_modules/kind-of": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", - "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -5146,9 +5106,9 @@ } }, "node_modules/leaflet": { - "version": "1.9.4", - "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz", - "integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.8.0.tgz", + "integrity": "sha512-gwhMjFCQiYs3x/Sf+d49f10ERXaEFCPr+nVTryhAW8DWbMGqJqt9G4XuIaHmFW08zYvhgdzqXGr8AlW8v8dQkA==", "dev": true }, "node_modules/levn": { @@ -5429,9 +5389,9 @@ } }, "node_modules/maplibre-gl": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.4.0.tgz", - "integrity": "sha512-csNFylzntPmHWidczfgCZpvbTSmhaWvLRj9e1ezUDBEPizGgshgm3ea1T5TCNEEBq0roauu7BPuRZjA3wO4KqA==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.3.0.tgz", + "integrity": "sha512-91vc5Quu9UDw0S90pJMDuE24XvXUjIYGaD5DTlhNs3egVmX0QwCpWl1R2tots3slHbZRJcQdRGUNxW7hKpi0Ow==", "hasInstallScript": true, "peer": true, "dependencies": { @@ -5451,7 +5411,6 @@ "earcut": "^2.2.4", "geojson-vt": "^3.2.1", "gl-matrix": "^3.4.3", - "global-prefix": "^3.0.0", "murmurhash-js": "^1.0.0", "pbf": "^3.2.1", "potpack": "^1.0.2", @@ -11227,9 +11186,9 @@ } }, "esri-leaflet": { - "version": "3.0.10", - "resolved": "https://registry.npmjs.org/esri-leaflet/-/esri-leaflet-3.0.10.tgz", - "integrity": "sha512-2ma+mMHrJA7oqJFHZDLZrCAMkaXTdFFJRsJqlsh3Z2G+nXKj2SrlzJ2YmN5qgnI9y/X5AkcSfxViBoQTX9rcSw==", + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/esri-leaflet/-/esri-leaflet-3.0.8.tgz", + "integrity": "sha512-mLb4pRfDAbkG1YhuajD22erLXIAtrF1R32hmgmlJNI3t47n6KjTppCb8lViia0O7+GDORXFuJ9Lj9RkpsaKhSA==", "dev": true, "requires": { "@terraformer/arcgis": "^2.1.0", @@ -11668,34 +11627,6 @@ "ini": "2.0.0" } }, - "global-prefix": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-3.0.0.tgz", - "integrity": "sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==", - "peer": true, - "requires": { - "ini": "^1.3.5", - "kind-of": "^6.0.2", - "which": "^1.3.1" - }, - "dependencies": { - "ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "peer": true - }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "peer": true, - "requires": { - "isexe": "^2.0.0" - } - } - } - }, "globals": { "version": "13.17.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", @@ -12319,7 +12250,8 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "istanbul-lib-coverage": { "version": "3.2.0", @@ -12733,12 +12665,6 @@ "json-buffer": "3.0.0" } }, - "kind-of": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", - "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", - "peer": true - }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -12749,9 +12675,9 @@ } }, "leaflet": { - "version": "1.9.4", - "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz", - "integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.8.0.tgz", + "integrity": "sha512-gwhMjFCQiYs3x/Sf+d49f10ERXaEFCPr+nVTryhAW8DWbMGqJqt9G4XuIaHmFW08zYvhgdzqXGr8AlW8v8dQkA==", "dev": true }, "levn": { @@ -12981,9 +12907,9 @@ } }, "maplibre-gl": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.4.0.tgz", - "integrity": "sha512-csNFylzntPmHWidczfgCZpvbTSmhaWvLRj9e1ezUDBEPizGgshgm3ea1T5TCNEEBq0roauu7BPuRZjA3wO4KqA==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-2.3.0.tgz", + "integrity": "sha512-91vc5Quu9UDw0S90pJMDuE24XvXUjIYGaD5DTlhNs3egVmX0QwCpWl1R2tots3slHbZRJcQdRGUNxW7hKpi0Ow==", "peer": true, "requires": { "@mapbox/geojson-rewind": "^0.5.2", @@ -13002,7 +12928,6 @@ "earcut": "^2.2.4", "geojson-vt": "^3.2.1", "gl-matrix": "^3.4.3", - "global-prefix": "^3.0.0", "murmurhash-js": "^1.0.0", "pbf": "^3.2.1", "potpack": "^1.0.2", diff --git a/package.json b/package.json index 54011b6..b0e3d07 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ }, "peerDependencies": { "esri-leaflet": ">2.3.0", - "leaflet": "^1.9.4", - "maplibre-gl": "^2.4.0" + "leaflet": "^1.5.0", + "maplibre-gl": "^2.2.1" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.1", @@ -31,7 +31,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.1.0", - "esri-leaflet": "^3.0.10", + "esri-leaflet": "^3.0.0", "gh-release": "^7.0.2", "http-server": "^14.1.1", "karma": "^6.4.1", @@ -44,7 +44,7 @@ "karma-safari-launcher": "~1.0.0", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.8", - "leaflet": "^1.9.4", + "leaflet": "^1.5.0", "mkdirp": "^2.1.3", "mocha": "^10.2.0", "npm-run-all": "^4.1.5", From dbe86bdbb76dbc69cca1a172b04d0bd0386229a5 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 14:01:16 -0700 Subject: [PATCH 13/17] apply fixes from review meeting --- src/Util.js | 2 +- src/VectorBasemapLayer.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Util.js b/src/Util.js index 7e91b39..5e02729 100644 --- a/src/Util.js +++ b/src/Util.js @@ -26,7 +26,7 @@ export function getBasemapStyleV2Url (style, apikey, language) { } let url = 'https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/'; - if (style.length === 32) { + if (!(style.indexOf('osm/') === 0 || style.indexOf('arcgis/') === 0) && style.length === 32) { // style is an itemID url = url + 'items/' + style; diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index 8e4c904..f23664a 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -12,7 +12,8 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ initialize: function (key, options) { // Default to the v1 service endpoint if (!options.version) { - options.version = 1; + if (key.includes('/')) options.version = 2; + else options.version = 1; } if (!key) { // Default style enum if none provided @@ -25,14 +26,14 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ // Validate language param if (options.language) { if (options.version !== 2) { - throw new Error('The language parameter is only supported by the basemap styles service v2. Set version:2 to use this property.'); + throw new Error('The language parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); } } // Determine layer order if (!options.pane) { - if (key.indexOf(':Label') > -1 || key.indexOf('/label') > -1) { + if (key.includes(':Label') || key.includes('/label')) { options.pane = 'esri-labels'; - } else if (key.indexOf(':Detail') > -1 || key.indexOf('/detail') > -1) { + } else if (key.includes(':Detail') || key.includes('/detail')) { options.pane = 'esri-detail'; } else { // Create layer in the tilePane by default @@ -54,7 +55,7 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ } else { styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); } - + console.log(styleUrl); this._createMaplibreLayer(styleUrl); }, From 6754d0b3d084039ea79e70ad71b78132eebe9238 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 14:14:40 -0700 Subject: [PATCH 14/17] remove debug statement --- src/VectorBasemapLayer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index f23664a..fb3e9ae 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -55,7 +55,6 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ } else { styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); } - console.log(styleUrl); this._createMaplibreLayer(styleUrl); }, From ce368e99e28971bad0fb4abadf10944292f27614 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 25 May 2023 14:17:05 -0700 Subject: [PATCH 15/17] update unit tests --- spec/VectorBasemapLayerSpec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/VectorBasemapLayerSpec.js b/spec/VectorBasemapLayerSpec.js index d9137b2..78e4924 100644 --- a/spec/VectorBasemapLayerSpec.js +++ b/spec/VectorBasemapLayerSpec.js @@ -137,13 +137,14 @@ describe('VectorBasemapLayer', function () { apikey:apikey, language:language }); - }).to.throw('The language parameter is only supported by the basemap styles service v2. Set version:2 to use this property.'); + }).to.throw('The language parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); }); it('should not accept a v2 style enumeration when accessing the v1 service', function () { expect(function () { L.esri.Vector.vectorBasemapLayer(basemapKeyV2, { - apikey:apikey + apikey:apikey, + version:1 }); }).to.throw(basemapKeyV2 + ' is a v2 style enumeration. Set version:2 to request this style') }) From d641164123ccf4698cb7f03962f9fd88b122c2c7 Mon Sep 17 00:00:00 2001 From: George Owen Date: Fri, 26 May 2023 12:36:20 -0700 Subject: [PATCH 16/17] Apply suggestions from code review Co-authored-by: Gavin Rehkemper Co-authored-by: Patrick Arlt --- examples/languages.html | 4 ++-- src/Util.js | 2 +- src/VectorTileLayer.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/languages.html b/examples/languages.html index d0b2d79..72d256c 100644 --- a/examples/languages.html +++ b/examples/languages.html @@ -83,8 +83,8 @@ "Lithuanian": getLayer("lt"), "Norwegian": getLayer("no"), "Polish": getLayer("pl"), - "Portugese (Brazil)": getLayer("pt_br"), - "Portugese (Portugal)": getLayer("pt_p"), + "Portuguese (Brazil)": getLayer("pt_br"), + "Portuguese (Portugal)": getLayer("pt_p"), "Romanian": getLayer("ro"), "Russian": getLayer("ru"), "Serbian": getLayer("sr"), diff --git a/src/Util.js b/src/Util.js index 5e02729..f5b7a0f 100644 --- a/src/Util.js +++ b/src/Util.js @@ -26,7 +26,7 @@ export function getBasemapStyleV2Url (style, apikey, language) { } let url = 'https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/'; - if (!(style.indexOf('osm/') === 0 || style.indexOf('arcgis/') === 0) && style.length === 32) { + if (!(style.startsWith('osm/') || style.startsWith('arcgis/')) && style.length === 32) { // style is an itemID url = url + 'items/' + style; diff --git a/src/VectorTileLayer.js b/src/VectorTileLayer.js index d7df9fe..717f6c0 100644 --- a/src/VectorTileLayer.js +++ b/src/VectorTileLayer.js @@ -24,8 +24,8 @@ export var VectorTileLayer = Layer.extend({ this.options.apikey = this.options.apiKey; } - // if apiKey is passed in, propogate to token - // if token is passed in, propogate to apikey + // if apiKey is passed in, propagate to token + // if token is passed in, propagate to apiKey if (this.options.apikey) { this.options.token = this.options.apikey; } else if (this.options.token) { From 37ec4db64b77d6bdf3d44585ae57ae23cbf2c399 Mon Sep 17 00:00:00 2001 From: George Owen Date: Fri, 26 May 2023 17:00:16 -0700 Subject: [PATCH 17/17] add suggested unit test #174 --- spec/VectorBasemapLayerSpec.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/VectorBasemapLayerSpec.js b/spec/VectorBasemapLayerSpec.js index 78e4924..14d1e80 100644 --- a/spec/VectorBasemapLayerSpec.js +++ b/spec/VectorBasemapLayerSpec.js @@ -113,7 +113,7 @@ describe('VectorBasemapLayer', function () { expect(layer.options.version).to.equal(2); }); - it('should set the service version to \'1\' when a version is not provided', function () { + it('should load a v1 basemap from a v1 style key without needing to specify a version', function () { const layer = new L.esri.Vector.vectorBasemapLayer(basemapKey, { apikey: apikey }) @@ -121,6 +121,14 @@ describe('VectorBasemapLayer', function () { expect(layer.options.version).to.equal(1); }); + it('should load a v2 basemap from a v2 style key without needing to specify a version', function () { + const layer = new L.esri.Vector.vectorBasemapLayer(basemapKeyV2, { + apikey: apikey + }) + + expect(layer.options.version).to.equal(2); + }); + it('should save the language from the constructor', function () { const layer = new L.esri.Vector.vectorBasemapLayer(basemapKeyV2, { apikey: apikey,