Commit 058d0a40 authored by zksx's avatar zksx
Browse files

got sld styling to work

parent 776ac91e
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -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 () => {
        let collections = await FetchObjects(collectionUrls);


        // Add extra properties to each collection
        for(const key in collections){
          collections[key].id = key;
          collections[key].title = props.target.collections.find(collection => collection.id === key).title;
          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)
+3 −10
Original line number Diff line number Diff line
@@ -302,7 +302,7 @@ export default L.Map.AstroMap = L.Map.extend({

        let title = featureCollections[i].title;

        let sld_file =  featureCollections[i].styleSheets;
        let sld_text = featureCollections[i].styleSheets;
        // set style if available

        let myStyle = null;
@@ -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
        if(featureCollections[i].features.length > 0) {



          if (sld_file) {
            let sldtext = fetch(sld_file);
            let res = sldtext.res

            console.log("good style wow");
            this.SLDStyler = new L.SLDStyler(sldtext);

          if (sld_text != null) {
            this.SLDStyler = new L.SLDStyler(sld_text);
            myStyle = this.SLDStyler.getStyleFunction();

          }