irishmarineinstitute / erddap-leaflet-velocity-demo Goto Github PK
View Code? Open in Web Editor NEWA demonstration of connecting Erddap to Leaflet Velocity maps
A demonstration of connecting Erddap to Leaflet Velocity maps
Reported by @fullergalway
Allows reading from non-CORS enabled Erddap servers
Reported by @fullergalway
Reported by @fullergalway
While this now uses a JSONP formatted response, it doesn't get around CORS when accessing other ERDDAP servers as it still is using the fetch
API.
erddap-leaflet-velocity-demo/erddapToLeafletVelocity.js
Lines 18 to 27 in 643186f
JSONP gets around CORS by loading data within a script tag and when the script finishes loading it fires the JSONP callback function (erddapData
) that it has been wrapped in.
Starting with this, this function will work to load JSONP data from ERDDAP and return a Promise, that you can .then(
off of and not be limited by CORS.
function jsonp(url) {
return new Promise(function(resolve, reject) {
let script = document.createElement('script')
const name = "_jsonp_" + Math.round(100000 * Math.random());
//url formatting
if (url.match(/\?/)) url += "&.jsonp="+name
else url += "&.jsonp="+name
script.src = url;
window[name] = function(data) {
resolve(data);
document.body.removeChild(script);
delete window[name];
}
document.body.appendChild(script);
});
}
I believe a remaining limitation will be when accessing http from https sites as that will be blocked by mixed content.
Re #1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.