Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load a list of graphs from server #150

Closed
michaelchin opened this issue Sep 28, 2022 · 4 comments
Closed

load a list of graphs from server #150

michaelchin opened this issue Sep 28, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request medium Medium priority

Comments

@michaelchin
Copy link
Contributor

michaelchin commented Sep 28, 2022

load the list of graphs from https://gws.gplates.org/mobile/get_graphs

@michaelchin michaelchin added enhancement New feature or request medium Medium priority labels Sep 28, 2022
@michaelchin
Copy link
Contributor Author

similar to city data, after you fetch data from server, save the data into local storage. we can use the data from local storage if network is not available. See the code below.

export const loadRasterMaps = (callback: Function) => {
fetch(serverURL.replace(/\/+$/, '') + '/mobile/get_rasters')
.then((response) => response.json())
.then((jsonData) => {
//console.log(json_data)
rasterMaps.length = 0
//rasterMaps.splice(0, rasterMaps.length)
rasterMaps.push(...convertJsonToRasterMaps(jsonData))
callback(false) //network fail=false
//save the data to local storage
getDefaultStore()
.then((store) => {
store.set('rasters', jsonData)
})
.catch((error) => {
console.log(error)
})
})
.catch(async (error) => {
console.log(error)
//network failed, not try local storage
try {
let store = await getDefaultStore()
let localData = await store.get('rasters')
console.log('localData')
console.log(localData)
if (localData) {
rasterMaps.push(...convertJsonToRasterMaps(localData))
} else {
rasterMaps.push(...convertJsonToRasterMaps(failSafeRasterMaps))
}
} catch (err) {
console.log(err)
}
callback(true) //network fail=true
})
}

@yiyanw
Copy link
Contributor

yiyanw commented Sep 29, 2022

@michaelchin this URL has a different security policy, I got the error on this URL when I use the same way to request it.

Access to fetch at 'https://gws.gplates.org/static/app-graphs.json' from origin 'http://127.0.0.1:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

the request code I used is:

let data: any = await fetch('https://gws.gplates.org/static/app-graphs.json')

@michaelchin
Copy link
Contributor Author

try this one https://gws.gplates.org/mobile/get_graphs

@michaelchin
Copy link
Contributor Author

@yiyanw could you please work on this one? See the comments below. I have added new graph data for test purpose. Meanwhile I will sort out the Cities.

//TODO: The time data fetched from the server may not be arithmetic sequence
//with 1Ma step, such as [0,4, 23,24,35...] is possible.
//the code below needs improvement
//Better to use linear interpolate on the data before cutting the range
if (rasterMapAnimateRange.upper != 0) {
DATA = data.slice(
rasterMapAnimateRange.lower,
rasterMapAnimateRange.upper
)
X_VALS = x_vals.slice(
rasterMapAnimateRange.lower,
rasterMapAnimateRange.upper
)
Y_VALS = y_vals.slice(
rasterMapAnimateRange.lower,
rasterMapAnimateRange.upper
)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants