Commit eaae20dc authored by Jacob Cain's avatar Jacob Cain
Browse files

paging fix, remove default &limit=10 if present

parent d27671c6
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ export default function Sidebar(props) {

  // Callback function to update selected title
  const updateAvailableQueriables = (queriables) => {
    console.log(queriables);
    setAvailableQueriables(queriables);
  };

+6 −2
Original line number Diff line number Diff line
@@ -173,8 +173,12 @@ export default L.Map.AstroMap = L.Map.extend({
    for(const feature of myFeatures) {

      // Check if feature or feature.geometry is null or undefined
      if(!feature || !feature.geometry){
        console.warn("Invalid feature or missing geometry: ", feature);
      if(!feature){
        console.log("Invalid/Null Feature", feature);
        continue;
      }
      else if(!feature.geometry){
        console.log("Feature with missing geometry", feature)
        continue;
      }

+31 −80
Original line number Diff line number Diff line
@@ -17,8 +17,9 @@ export async function FetchObjects(objInfo) {

    // For each url given
    for(const key in objInfo) {

        // Fetch JSON from url and read into object
        // The stylesheet ones \/ get 404s so I'm discarding them for now
        if (!key.includes(": stylesheet")){
            fetchPromise[key] = fetch(
                objInfo[key]
            ).then((res) => {
@@ -31,6 +32,7 @@ export async function FetchObjects(objInfo) {
                console.log(err);
            });
        }
    }

    // Wait for each query to complete
    for(const key in objInfo){
@@ -50,86 +52,35 @@ export async function FetchObjects(objInfo) {
 * @param {string} queryString - The query to narrow the results returned from the collection.
 */
export async function FetchFootprints(collection, page, step){
    let collectionUrl;
    let offsetMulitiplier;
    const stacDefaultLimit = 10;
    const pyDefaultLimit = 25;
    let baseURL = collection.url;
    let pageInfo = "";
    if(collection.url.slice(-1) !== "?") {
        pageInfo += "&"
    }
    pageInfo += "page=" + page;
    if (step != 10){
      pageInfo += "&limit=" + step;
    }

    // check for pyGeo API
    if (!collection.url.includes('stac')) 
    {

        // set offset for 5 & 10 steps
        offsetMulitiplier = (page * 10 - step);
        pageInfo = "&offset=" + offsetMulitiplier;

        
        // checks for 5 change in step
        if (step <= 10)
        {
               
            // splice limit and change to new limit
            collectionUrl = collection.url.split('&limit=')[0];
            collection.url = collectionUrl;
                
                
            // update page pageInfo
            pageInfo = "&offset=" + offsetMulitiplier + "&limit=" + step;
            

    // get rid of default limit present in some pygeoapi urls
    if(baseURL.slice(-9) == "&limit=10") {
        baseURL = baseURL.slice(0, -9);
    }
        // checks for 50 & 100 step
        else if (step == 50 || step == 100)
        {

            // splice limit and change to new limit
            collectionUrl = collection.url.split('&limit=')[0];
            collection.url = collectionUrl;

            // check for first page 
            if (page == 1)
            {
                // set multiplier to 0
                offsetMulitiplier = 0;
    if(collection.url.slice(-1) !== "?") {
        pageInfo += "&"
    }
            // check for second page
            else if (page == 2)
            {   
                // set multiplier to step
                offsetMulitiplier = step;

            }
            else
    if (collection.url.includes('stac'))
    {
                // check for 50 and set pages according
                if (step == 50)
                {
                    offsetMulitiplier = page * step - 50;
                }
                // check for 100 and set pages according
                else 
                {
                    offsetMulitiplier = page * step - 100;
        pageInfo += "page=" + page;
        if (step !== stacDefaultLimit) {
            pageInfo += "&limit=" + step;
        }
    }

            // update page pageInfo
            pageInfo = "&offset=" + offsetMulitiplier + "&limit=" + step;
    else {
        pageInfo += "offset=" + step * (page - 1);
        if (step !== pyDefaultLimit) {
            pageInfo += "&limit=" + step;
        }
        
        
    }

    // reset offset
    offsetMulitiplier = 0;

    let jsonRes = await FetchObjects(collection.url + pageInfo);
    let jsonRes = await FetchObjects(baseURL + pageInfo);
    return jsonRes.features;
}