From 9da3710a32fbee80665b9c3e662327e5381fe720 Mon Sep 17 00:00:00 2001 From: jwasilgeo Date: Tue, 3 Aug 2021 10:13:11 -0500 Subject: [PATCH 1/4] chore: added exported function comment documentation and slight reorganization --- src/Util.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Util.js b/src/Util.js index d8e2e4a..987bae3 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,8 +1,6 @@ import { latLng, latLngBounds } from 'leaflet'; import { request, Support, Util } from 'esri-leaflet'; -const WEB_MERCATOR_WKIDS = [3857, 102100, 102113]; - /* utility to establish a URL for the basemap styles API used primarily by VectorBasemapLayer.js @@ -223,6 +221,12 @@ export function getAttributionData (url, map) { } } +/* + utility to check if a service's tileInfo spatial reference is in Web Mercator + used primarily by VectorTileLayer.js +*/ +const WEB_MERCATOR_WKIDS = [3857, 102100, 102113]; + export function isWebMercator (wkid) { return WEB_MERCATOR_WKIDS.indexOf(wkid) >= 0; } From 9177081fcef1717a514b81924b1e2d23d38fdfde Mon Sep 17 00:00:00 2001 From: jwasilgeo Date: Tue, 3 Aug 2021 10:17:45 -0500 Subject: [PATCH 2/4] `formatStyle`: changed to be more forgiving if the optional `style.sprite` or `style.glyphs` properties do not exist --- src/Util.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Util.js b/src/Util.js index 987bae3..9128500 100644 --- a/src/Util.js +++ b/src/Util.js @@ -160,24 +160,27 @@ export function formatStyle (style, styleUrl, metadata, token) { } } - // resolve absolute URLs for style.sprite and style.glyphs - if (style.sprite.indexOf('http') === -1) { + if (style.sprite && style.sprite.indexOf('http') === -1) { + // resolve absolute URL for style.sprite style.sprite = styleUrl.replace( 'styles/root.json', style.sprite.replace('../', '') ); + + // add the token to the style.sprite property as a query param + style.sprite += token ? '?token=' + token : ''; } - if (style.glyphs.indexOf('http') === -1) { + if (style.glyphs && style.glyphs.indexOf('http') === -1) { + // resolve absolute URL for style.glyphs style.glyphs = styleUrl.replace( 'styles/root.json', style.glyphs.replace('../', '') ); - } - // add the token to the style.sprite and style.glyphs properties as a query param - style.sprite += token ? '?token=' + token : ''; - style.glyphs += token ? '?token=' + token : ''; + // add the token to the style.glyphs property as a query param + style.glyphs += token ? '?token=' + token : ''; + } return style; } From e2ad67fd3f9c02cf4acd5458d1cd047a48ea3186 Mon Sep 17 00:00:00 2001 From: jwasilgeo Date: Fri, 6 Aug 2021 15:29:12 -0500 Subject: [PATCH 3/4] `loadStyleFromService` and `formatStyle`: cleaned up known areas where and extra "/" might be present and lead to invalid paths --- src/Util.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Util.js b/src/Util.js index 9128500..0d10ed8 100644 --- a/src/Util.js +++ b/src/Util.js @@ -80,15 +80,20 @@ function loadStyleFromService (serviceUrl, options, callback) { console.error(error); } + var sanitizedServiceUrl = serviceUrl; + // a trailing "/" may create invalid paths + if (serviceUrl.charAt(serviceUrl.length - 1) === '/') { + sanitizedServiceUrl = serviceUrl.slice(0, serviceUrl.length - 1); + } + var defaultStylesUrl; - if ( - serviceUrl.charAt(0) !== '/' && - service.defaultStyles.charAt(service.defaultStyles.length - 1) !== '/' - ) { + // inadvertently inserting more than 1 adjacent "/" may create invalid paths + if (service.defaultStyles.charAt(0) === '/') { defaultStylesUrl = - serviceUrl + '/' + service.defaultStyles + '/root.json'; + sanitizedServiceUrl + service.defaultStyles + '/root.json'; } else { - defaultStylesUrl = serviceUrl + service.defaultStyles + '/root.json'; + defaultStylesUrl = + sanitizedServiceUrl + '/' + service.defaultStyles + '/root.json'; } loadStyleFromUrl(defaultStylesUrl, options, function (error, style) { @@ -118,6 +123,11 @@ export function formatStyle (style, styleUrl, metadata, token) { source.url = styleUrl.replace('/resources/styles/root.json', ''); } + // a trailing "/" may create invalid paths + if (source.url.charAt(source.url.length - 1) === '/') { + source.url = source.url.slice(0, source.url.length - 1); + } + // add tiles property if missing if (!source.tiles) { // right now ArcGIS Pro published vector services have a slightly different signature From 62e4ae18fc07433cc5c9e0063b2e29dbac1441ff Mon Sep 17 00:00:00 2001 From: jwasilgeo Date: Fri, 6 Aug 2021 15:43:38 -0500 Subject: [PATCH 4/4] updated CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 692df41..9a9920b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). * Updated peerDependencies to be more flexible for using v3 of `esri-leaflet`. [#99](https://github.com/Esri/esri-leaflet-vector/pull/99) +### Fixed + +* Utility functions used by `L.esri.Vector.vectorTileLayer` have been improved to be more friendly with URL structures and style reformatting assumptions. [#100](https://github.com/Esri/esri-leaflet-vector/pull/100) + ## [3.0.1] - 2021-06-03 ### Fixed