diff --git a/src/components/presentational/FootprintResults.jsx b/src/components/presentational/FootprintResults.jsx index 800aa965aa1a2b04121b19e54b62ec7556b20f48..121935140d07c01133dc9c24ce4045d5ef5c0675 100644 --- a/src/components/presentational/FootprintResults.jsx +++ b/src/components/presentational/FootprintResults.jsx @@ -119,6 +119,8 @@ export default function FootprintResults(props) { } let collectionUrls = {}; + let styleSheetUrls = []; + for (const collection of props.target.collections) { @@ -133,15 +135,37 @@ export default function FootprintResults(props) { // change filter for the pygeo api myFilter = "&limit=" + step; } + let styleSheet; + const foundStyleSheet = collection.links.find(link=> link.rel == "stylesheet"); + + if(foundStyleSheet) { + styleSheet = foundStyleSheet.href; + styleSheetUrls[collection.id] = styleSheet; + console.log("Found Style Sheet"); + } if(isInStacAPI || isInPyAPI) { let itemsUrl = collection.links.find(link => link.rel === "items").href; collectionUrls[collection.id] = itemsUrl + myFilter + pageInfo; + + let style_url = null; + for (let index = 0; index < collection.links.length; index++) { + if (collection.links[index].rel === "stylesheet") { + style_url = collection.links[index].href + } + } + collectionUrls[collection.id + ": stylesheet"] = style_url; + + // if (collection.links.find(link => link.rel === "stylesheet").href != undefined) { + // let styleUrl = collection.links.find(link => link.rel === "stylesheet").href; + // collectionUrls[collection.id].style = styleUrl; + // } + + // } } else { let itemsUrl = collection.links.find(link => link.rel === "items").href; collectionUrls[collection.id] = itemsUrl + pageInfo; - } } @@ -153,6 +177,7 @@ export default function FootprintResults(props) { 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]; } // Updates collectionId if switching to a new set of collections (new target) diff --git a/src/js/AstroMap.js b/src/js/AstroMap.js index f7241880746b39fb0486caad90285af27753b5e2..566309c4cbbc1fc8e7082c559d06c2504be4e6e4 100644 --- a/src/js/AstroMap.js +++ b/src/js/AstroMap.js @@ -2,7 +2,8 @@ import L from "leaflet"; import "proj4leaflet"; import AstroProj from "./AstroProj"; import LayerCollection from "./LayerCollection"; -import SLDText from "../slds/Global_Geology.sld"; +import FecthData from "./FetchData"; +import { data } from "autoprefixer"; /** @@ -58,8 +59,7 @@ export default L.Map.AstroMap = L.Map.extend({ // Set by layer collection or baselayerchange event this._currentLayer = null; - this.SLDStyler = new L.SLDStyler(SLDText); - + this.SLDStyler = new L.SLDStyler(); // Store layers at map creation so we only need to create layers once. let cylLayerInfo = this.parseJSON("cylindrical"); @@ -302,26 +302,27 @@ export default L.Map.AstroMap = L.Map.extend({ let title = featureCollections[i].title; + let sld_file = featureCollections[i].styleSheets; + // set style if available + + let myStyle = null; + // Add each _geoLayer that has footprints to the FootprintCollection object. // The collection title is used as the property name // [old] and it shows up as the layer title when added to the separate Leaflet control if(featureCollections[i].features.length > 0) { - let found_stylesheet = false; - let sld_file = null; - // set style if available - for (let j = 0; j < featureCollections[i].links.length; j++) { - if (featureCollections[i].links[j].rel == "stylesheet") { - found_stylesheet = true; - sld_file = fetch(featureCollections[i].links[j].href); - this.SLDStyler = new L.SLDStyler(sld_file); - } - } - let myStyle = null; - if (found_stylesheet) { + 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(); + } else{ // Set colors if available diff --git a/src/js/FetchData.js b/src/js/FetchData.js index 8708b2f4b6e619a68808da4ea69811b51472aad5..6224fac81b448e910afa7337daf746829fa17e5a 100644 --- a/src/js/FetchData.js +++ b/src/js/FetchData.js @@ -122,7 +122,7 @@ export default async function Initialize(){ // view the collection as GEOJSON let target_name = pycollection.id.split('/')[0]; if (target.name == target_name.toUpperCase()) { - pycollection.links[9].href = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links[9].href; + pycollection.links.find(link => link.rel === "items").href = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links.find(link => link.rel === "items").href; // Add a specification to the title in order to show what kind of data the user is requesting pycollection.title = pycollection.title.concat(" (Vector)"); myCollections.push(pycollection);