Skip to content
Snippets Groups Projects
Commit 058d0a40 authored by zksx's avatar zksx
Browse files

got sld styling to work

parent 776ac91e
No related branches found
No related tags found
No related merge requests found
...@@ -169,15 +169,39 @@ export default function FootprintResults(props) { ...@@ -169,15 +169,39 @@ export default function FootprintResults(props) {
} }
} }
async function fetchSLD(sld_url) {
try {
const response = await fetch(sld_url)
if(!response.ok) {
throw new Error('SLD response not ok ' + response.statusText);
}
const SLD_DATA = await response.text();
//const parser = new DOMParser();
//const sld_file = parser.parseFromString(SLD_DATA, text/xml);
return SLD_DATA
} catch (error) {
console.error('SLD unable to be fetched', error);
}
}
(async () => { (async () => {
let collections = await FetchObjects(collectionUrls); let collections = await FetchObjects(collectionUrls);
// Add extra properties to each collection // Add extra properties to each collection
for(const key in collections){ for(const key in collections){
collections[key].id = key; collections[key].id = key;
collections[key].title = props.target.collections.find(collection => collection.id === key).title; collections[key].title = props.target.collections.find(collection => collection.id === key).title;
collections[key].url = collectionUrls[key]; collections[key].url = collectionUrls[key];
collections[key].styleSheets = styleSheetUrls[key];
let sldtext = null;
if (styleSheetUrls[key]) {
sldtext = await fetchSLD(styleSheetUrls[key]);
collections[key].styleSheets = sldtext;
}
} }
// Updates collectionId if switching to a new set of collections (new target) // Updates collectionId if switching to a new set of collections (new target)
......
...@@ -302,7 +302,7 @@ export default L.Map.AstroMap = L.Map.extend({ ...@@ -302,7 +302,7 @@ export default L.Map.AstroMap = L.Map.extend({
let title = featureCollections[i].title; let title = featureCollections[i].title;
let sld_file = featureCollections[i].styleSheets; let sld_text = featureCollections[i].styleSheets;
// set style if available // set style if available
let myStyle = null; let myStyle = null;
...@@ -312,15 +312,8 @@ export default L.Map.AstroMap = L.Map.extend({ ...@@ -312,15 +312,8 @@ export default L.Map.AstroMap = L.Map.extend({
// [old] and it shows up as the layer title when added to the separate Leaflet control // [old] and it shows up as the layer title when added to the separate Leaflet control
if(featureCollections[i].features.length > 0) { if(featureCollections[i].features.length > 0) {
if (sld_text != null) {
this.SLDStyler = new L.SLDStyler(sld_text);
if (sld_file) {
let sldtext = fetch(sld_file);
let res = sldtext.res
console.log("good style wow");
this.SLDStyler = new L.SLDStyler(sldtext);
myStyle = this.SLDStyler.getStyleFunction(); myStyle = this.SLDStyler.getStyleFunction();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment