Getting map and layer data

This example shows how to retrieve public map data from GIS Cloud. You'll see 20 most visited maps in GIS Cloud.

Once loaded, maps are displayed in the list below. You can see their names and ids.
Clicking on the Get layers links will retrieve layer data for each map.

The code:

function getMapsData() {
    
    // get public maps
    giscloud.maps.list({ perPage: 20, sort: "visited:desc" })
    .done(function(mapdata) {
        var i, k, map;
        
        // mapdata contains an array of giscloud.Map objects
        for (i = 0, k = mapdata.length; i < k; i++) {
            
            map = mapdata[i];
            
            // show map data on the page
            showMapData(map.id, map.name);
            
        }
    });
}


function getLayersData(mapId) {
    
    // get layers data
    giscloud.layers.byMapId(mapId)
    .done(function(layerdata) {
        var i, k, layer;
        
        // layerdata contains an array of giscloud.Layer objects
        for (i = 0, k = mapdata.length; i < k; i++) {
            
            layer = layerdata[i];
            
            // show map data on the page
            showLayersData(mapId, layer.id, layer.name);
            
        }
        
    });         
}