Skip to content

Commit

Permalink
HDX-10036 dealing with protocol independent URLs for HDX PBFs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru-m-g committed Jul 31, 2024
1 parent befce2e commit 9021b5f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/shape-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,24 @@
return bounds;
}

/**
* Compute full URL for HDX vector tiles
* @param {string} url
* @returns {string}
*/
function computeHDXVectorTilesUrl(url) {
let tilesBaseUrl = url;
if (url.startsWith('//')) {
tilesBaseUrl = vectorTileHDXLayerConfig.serverUrl.startsWith('https://') ? 'https:' + url : 'http:' + url;
}
else if (!url.startsWith('https://') && !url.startsWith('http://')) {
tilesBaseUrl = vectorTileHDXLayerConfig.serverUrl + url;
}
return tilesBaseUrl + '?geom=wkb_geometry&fields=ogc_fid';
}

async function getFieldListAndBuildLayer(layerData, info, firstAdded, options, layers) {
const value = layerData.url;
const tilesBaseUrl = value.indexOf('//') >= 0 ? value : vectorTileHDXLayerConfig.serverUrl + value;
const tilesURL = tilesBaseUrl + '?geom=wkb_geometry&fields=ogc_fid';
const tilesURL = computeHDXVectorTilesUrl(layerData.url);
const bounds = getBounds(layerData.bounding_box);
const res = await fetch(`${vectorTileHDXLayerConfig.serverUrl}/gis/layer-type/${layerData.layer_id}`);
let geomType;
Expand Down

0 comments on commit 9021b5f

Please sign in to comment.