1

I would like to build a Leaflet Webapp that is highly adaptable and easy to configure. Therefore I would like to use Google Spreadsheets to store the configuration and retrieve the stored information during initialization of the Leaflet-Map to set the used layers, initial centerpoint and so on.

Has anyone done this before or could give me hints? I have googled a lot about it but haven't found anything like this so far.

4

You could get the Google doc as json like this if you have published the spreadsheet as website:

https://spreadsheets.google.com/feeds/list/your_spreadsheet_id/od6/public/basic?alt=json

You will find a lot of hints how to get the spreadsheet as json. for example:

https://blogs.it.ox.ac.uk/acit-rs-team/2014/10/08/how-to-get-data-out-of-a-google-spreadsheet-using-jsonp/

Then use a ajax request to get the json and extract the information you need.

var url = "https://spreadsheets.google.com/feeds/list/your_spreadsheet_ID/od6/public/basic?alt=json";
    $.ajax({
        url: url,
        dataType: "jsonp",
        success: function (data) {
// do whatever you want with the data
}});

Here you will find a working jsfiddle:

http://jsfiddle.net/expedio/2m023xsz/

Please note that this jsfiddle is just a 'quick and dirty' test to show that you can do this. It needs to be polished before it's ready for a stable use. You would have to build in checks to see if the users have inserted wrong information in the config table in order not to run into JS-errors.

If you would use an AppScript to publish the Spreadsheet as userdefined JSON it would also be much easier to get the information you need in order to create the layers dynamically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.