From b00eb0b21d8cb018a43ee20edeb94065927dfbf5 Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 16 Nov 2023 17:05:51 -0800 Subject: [PATCH 1/6] add worldview param and places wip --- examples/languages.html | 2 +- examples/worldview.html | 77 ++++++++++++++++++++++++++++++++++ spec/VectorBasemapLayerSpec.js | 28 ++++++++++++- src/Util.js | 19 +++++---- src/VectorBasemapLayer.js | 18 ++++++-- 5 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 examples/worldview.html diff --git a/examples/languages.html b/examples/languages.html index b79882f..168a7aa 100644 --- a/examples/languages.html +++ b/examples/languages.html @@ -44,7 +44,7 @@ }).setView([35.7088, 48.8790], 4); - const apiKey = "< YOUR ARCGIS API KEY HERE >"; + const apiKey = "AAPKcc58d292d8d24415af677a38d7adbcc1vMHlBBqqnttVrFKhCQWB8nT8YPjlQs3HPY3fKeV7-__w6LuMKgmag1MubRUgaAaA"; const basemapStyle = "arcgis/outdoor"; diff --git a/examples/worldview.html b/examples/worldview.html new file mode 100644 index 0000000..b5806d9 --- /dev/null +++ b/examples/worldview.html @@ -0,0 +1,77 @@ + + + + + Esri Leaflet Vector: Display basemap places + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/spec/VectorBasemapLayerSpec.js b/spec/VectorBasemapLayerSpec.js index 277b35e..a9310a2 100644 --- a/spec/VectorBasemapLayerSpec.js +++ b/spec/VectorBasemapLayerSpec.js @@ -5,6 +5,8 @@ const basemapKey = 'ArcGIS:Streets'; const basemapKeyV2 = 'arcgis/streets'; const customBasemap = 'f04f33b9626240f084cb52f0b08758ef'; const language = 'zh_s'; +const worldview = 'morocco'; +// const places = 'attributed'; describe('VectorBasemapLayer', function () { it('should have a L.esri.vectorBasemapLayer alias', function () { @@ -129,14 +131,18 @@ describe('VectorBasemapLayer', function () { expect(layer.options.version).to.equal(2); }); - it('should save the language from the constructor', function () { + it('should save the language and worldview parameters from the constructor', function () { const layer = new L.esri.Vector.vectorBasemapLayer(basemapKeyV2, { apikey: apikey, version: 2, - language: language + language: language, + worldview: worldview, + //places: places }); expect(layer.options.language).to.equal(language); + expect(layer.options.worldview).to.equal(worldview); + //expect(layer.options.places).to.equal(places); }); it('should error if a language is provided when accessing the v1 service', function () { @@ -148,6 +154,24 @@ describe('VectorBasemapLayer', function () { }).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 error if a worldview is provided when accessing the v1 service', function () { + expect(function () { + L.esri.Vector.vectorBasemapLayer(basemapKey, { + apikey: apikey, + worldview: worldview + }); + }).to.throw('The worldview parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); + }); + + /* it('should error if a places parameter is provided when accessing the v1 service', function () { + expect(function () { + L.esri.Vector.vectorBasemapLayer(basemapKey, { + apikey: apikey, + places: places + }); + }).to.throw('The places 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, { diff --git a/src/Util.js b/src/Util.js index c8e3631..77f7728 100644 --- a/src/Util.js +++ b/src/Util.js @@ -20,7 +20,7 @@ export function getBasemapStyleUrl (style, apikey) { return url; } -export function getBasemapStyleV2Url (style, apikey, language) { +export function getBasemapStyleV2Url (style, token, options) { if (style.includes(':')) { throw new Error(style + ' is a v1 style enumeration. Set version:1 to request this style'); } @@ -30,20 +30,25 @@ export function getBasemapStyleV2Url (style, apikey, language) { // style is an itemID url = url + 'items/' + style; - if (language) { + if (options.language) { throw new Error('The \'language\' parameter is not supported for custom basemap styles'); } } else { url = url + style; } - if (apikey) { - url = url + '?token=' + apikey; + if (!token) throw new Error('A token is required to access basemap styles.'); - if (language) { - url = url + '&language=' + language; - } + url = url + '?token=' + token; + if (options.language) { + url = url + '&language=' + options.language; + } + if (options.worldview) { + url = url + '&worldview=' + options.worldview; } + /* if (options.places) { + url = url + '&places=' + options.places; + } */ return url; } /* diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index fb3e9ae..c36cc01 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -23,11 +23,17 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ 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) { + // Validate v2 service params + if (options.version !== 2) { + if (options.language) { throw new Error('The language parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); } + if (options.worldview) { + throw new Error('The worldview parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); + } + /* if (options.places) { + throw new Error('The places 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) { @@ -51,7 +57,11 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ _createLayer: function () { let styleUrl; if (this.options.version && this.options.version === 2) { - styleUrl = getBasemapStyleV2Url(this.options.key, this.options.apikey, this.options.language); + styleUrl = getBasemapStyleV2Url(this.options.key, this.options.apikey, { + language: this.options.language, + worldview: this.options.worldview + // places: this.options.places + }); } else { styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); } From bd9b0c2ff915ba2edf62df84535419e4932c874b Mon Sep 17 00:00:00 2001 From: George Owen Date: Thu, 16 Nov 2023 17:10:50 -0800 Subject: [PATCH 2/6] obfuscate apikey --- examples/languages.html | 2 +- examples/worldview.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/languages.html b/examples/languages.html index 168a7aa..7c5362f 100644 --- a/examples/languages.html +++ b/examples/languages.html @@ -44,7 +44,7 @@ }).setView([35.7088, 48.8790], 4); - const apiKey = "AAPKcc58d292d8d24415af677a38d7adbcc1vMHlBBqqnttVrFKhCQWB8nT8YPjlQs3HPY3fKeV7-__w6LuMKgmag1MubRUgaAaA"; + const apiKey = ""; const basemapStyle = "arcgis/outdoor"; diff --git a/examples/worldview.html b/examples/worldview.html index b5806d9..bece019 100644 --- a/examples/worldview.html +++ b/examples/worldview.html @@ -43,7 +43,7 @@ minZoom: 2 }).setView([35.7088, 48.8790], 4); - const apiKey = "AAPKcc58d292d8d24415af677a38d7adbcc1vMHlBBqqnttVrFKhCQWB8nT8YPjlQs3HPY3fKeV7-__w6LuMKgmag1MubRUgaAaA"; + const apiKey = ""; const basemapStyle = "arcgis/light-gray"; From b87a1dffcc29d78000d12c5835f1e12768b47274 Mon Sep 17 00:00:00 2001 From: George Owen Date: Tue, 21 Nov 2023 09:53:27 -0800 Subject: [PATCH 3/6] add places param support --- examples/basemap-places.html | 72 ++++++++++++++++++++++++++++++++++ spec/VectorBasemapLayerSpec.js | 10 ++--- src/Util.js | 4 +- src/VectorBasemapLayer.js | 8 ++-- 4 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 examples/basemap-places.html diff --git a/examples/basemap-places.html b/examples/basemap-places.html new file mode 100644 index 0000000..cc09fa9 --- /dev/null +++ b/examples/basemap-places.html @@ -0,0 +1,72 @@ + + + + + Esri Leaflet Vector: Display basemap places + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/spec/VectorBasemapLayerSpec.js b/spec/VectorBasemapLayerSpec.js index a9310a2..1b6ccbc 100644 --- a/spec/VectorBasemapLayerSpec.js +++ b/spec/VectorBasemapLayerSpec.js @@ -6,7 +6,7 @@ const basemapKeyV2 = 'arcgis/streets'; const customBasemap = 'f04f33b9626240f084cb52f0b08758ef'; const language = 'zh_s'; const worldview = 'morocco'; -// const places = 'attributed'; +const places = 'attributed'; describe('VectorBasemapLayer', function () { it('should have a L.esri.vectorBasemapLayer alias', function () { @@ -137,12 +137,12 @@ describe('VectorBasemapLayer', function () { version: 2, language: language, worldview: worldview, - //places: places + places: places }); expect(layer.options.language).to.equal(language); expect(layer.options.worldview).to.equal(worldview); - //expect(layer.options.places).to.equal(places); + expect(layer.options.places).to.equal(places); }); it('should error if a language is provided when accessing the v1 service', function () { @@ -163,14 +163,14 @@ describe('VectorBasemapLayer', function () { }).to.throw('The worldview parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); }); - /* it('should error if a places parameter is provided when accessing the v1 service', function () { + it('should error if a places parameter is provided when accessing the v1 service', function () { expect(function () { L.esri.Vector.vectorBasemapLayer(basemapKey, { apikey: apikey, places: places }); }).to.throw('The places 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 () { diff --git a/src/Util.js b/src/Util.js index 77f7728..e277290 100644 --- a/src/Util.js +++ b/src/Util.js @@ -46,9 +46,9 @@ export function getBasemapStyleV2Url (style, token, options) { if (options.worldview) { url = url + '&worldview=' + options.worldview; } - /* if (options.places) { + if (options.places) { url = url + '&places=' + options.places; - } */ + } return url; } /* diff --git a/src/VectorBasemapLayer.js b/src/VectorBasemapLayer.js index c36cc01..0b56a39 100644 --- a/src/VectorBasemapLayer.js +++ b/src/VectorBasemapLayer.js @@ -31,9 +31,9 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ if (options.worldview) { throw new Error('The worldview parameter is only supported by the basemap styles service v2. Provide a v2 style enumeration to use this option.'); } - /* if (options.places) { + if (options.places) { throw new Error('The places 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) { @@ -59,8 +59,8 @@ export var VectorBasemapLayer = VectorTileLayer.extend({ if (this.options.version && this.options.version === 2) { styleUrl = getBasemapStyleV2Url(this.options.key, this.options.apikey, { language: this.options.language, - worldview: this.options.worldview - // places: this.options.places + worldview: this.options.worldview, + places: this.options.places }); } else { styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey); From dc5d3ee3c13d9a568f37c5c666d694ba79920bbc Mon Sep 17 00:00:00 2001 From: George Owen Date: Mon, 4 Dec 2023 12:41:32 -0800 Subject: [PATCH 4/6] Update src/Util.js Co-authored-by: Gavin Rehkemper --- src/Util.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Util.js b/src/Util.js index e277290..6d558d4 100644 --- a/src/Util.js +++ b/src/Util.js @@ -20,6 +20,14 @@ export function getBasemapStyleUrl (style, apikey) { return url; } +/** + * Utility to establish a URL for the basemap styles API v2 + * + * @param {string} style + * @param {string} token + * @param {Object} [options] Optional list of options: language, worldview, or places. + * @returns {string} the URL + */ export function getBasemapStyleV2Url (style, token, options) { if (style.includes(':')) { throw new Error(style + ' is a v1 style enumeration. Set version:1 to request this style'); From 6ceeb035954945d41fd332ac60b24096ccc77c05 Mon Sep 17 00:00:00 2001 From: George Owen Date: Mon, 4 Dec 2023 13:56:33 -0800 Subject: [PATCH 5/6] update worldview example --- examples/worldview.html | 25 ++++++++++--------------- src/Util.js | 4 ++-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/worldview.html b/examples/worldview.html index bece019..e015969 100644 --- a/examples/worldview.html +++ b/examples/worldview.html @@ -38,34 +38,29 @@
-