Download data file - GeoSmartCity-CIP/gsc-client GitHub Wiki

Download Data File

The module is provides the components to download different layers viewed on the map in GML, KML, GPX, JSON and WKT files for use on desktop applications.

API

API is available at GitHub src/download/download.js.

Dependencies

This library depends on jQuery and OpenLayers.

Examples

The following example demonstrates how to get map layer in required output format. Note that all available formats are fetched just for the purpose of demonstration.

// Configure source of the Vector Layer
var vectorSource = new ol.source.Vector({
    url: 'http://openlayers.org/en/v3.18.2/examples/data/geojson/countries.geojson',
    format: new ol.format.GeoJSON()
});
// Configure Vector Layer
var layer = new ol.layer.Vector({
    source: vectorSource
});
// Configure map
var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        }),
        layer
    ],
    renderer: 'canvas',
    target: 'map',
    view: new ol.View({
        center: [0, 0],
        zoom: 2
    })
});
// Add map object and selected layer (to download from)
gsc.download.create(map, layer);
// Generate .kml string
gsc.download.kml();
// Generate .wkt string
gsc.download.wkt();
// Generate .gpx string
gsc.download.gpx();
// Generate .json string
gsc.download.json();
// Pass ol.format.GML and generate .gml string
gsc.download.gml(ol.format.GML);
// Change the layer you want to download data from
gsc.download.addLayer(ol.Layer)

For example the result of the gsc.download.kml() will be:

<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 https://developers.google.com/kml/schema/kml22gx.xsd"><Placemark id="POL"><name>Poland</name><Polygon><outerBoundaryIs><LinearRing><coordinates>1671684.3479646263,6640184.854245133 1626054.7113274448,6754182.661784717 1634729.616605983,6816405.39376582 1607186.2802769665,6913904.573349097 1566768.5108792358,6979532.83427941 1597803.7169954556,7029035.420701512 1571796.2556809138,7124274.129112371 1647851.2902637494,7179765.258116936 1821573.9272474437,7267947.776378672 1961764.6845754066,7333105.428833309 2072864.5420133455,7300508.48760427 2081257.5863411953,7253686.180805331 2188612.4334698664,7251268.076783722 2325714.074928316,7229568.38433456 2530414.3658514903,7232433.5491896 2587508.796845471,7212040.207335641 2614241.170684058,7153601.848893867 2619073.3271404128,7070435.657623602 2649953.2425669758,6999613.005002776 2649314.7139677857,6926062.751388512 2582555.8587416057,6888660.66129385 2616898.812207257,6804402.265121756 2619021.5635771938,6724260.500356969 2675005.805289493,6569348.140256124 2663069.1276112213,6520185.497277012 2607826.9416245497,6499876.064077411 2506742.3874537917,6356150.602420078 2535459.3651742414,6279511.031345595 2511160.4354043948,6289421.880163918 2405370.183718823,6355008.456351632 2325236.514312813,6330832.367176313 2272680.8015974555,6348389.571497864 2206911.465324937,6311783.589599679 2150771.932922981,6372407.959738907 2105004.260117216,6349141.540321699 2098722.389932261,6359484.564038589 2047489.8206844728,6444306.81695798 1964727.2301838885,6454772.693908454 1954165.459536404,6509230.976875272 1877822.7753893586,6528768.0347408345 1861203.5546503586,6483723.596648548 1800732.2469031638,6519788.167683334 1807675.688821904,6567999.355642543 1724447.1149328586,6583302.928204887 1671684.3479646263,6640184.854245133</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark></kml>

For example the result of the gsc.download.wkt() will be:

POLYGON((1671684.3479646263 6640184.854245133,1626054.7113274448 6754182.661784717,1634729.616605983 6816405.39376582,1607186.2802769665 6913904.573349097,1566768.5108792358 6979532.83427941,1597803.7169954556 7029035.420701512,1571796.2556809138 7124274.129112371,1647851.2902637494 7179765.258116936,1821573.9272474437 7267947.776378672,1961764.6845754066 7333105.428833309,2072864.5420133455 7300508.48760427,2081257.5863411953 7253686.180805331,2188612.4334698664 7251268.076783722,2325714.074928316 7229568.38433456,2530414.3658514903 7232433.5491896,2587508.796845471 7212040.207335641,2614241.170684058 7153601.848893867,2619073.3271404128 7070435.657623602,2649953.2425669758 6999613.005002776,2649314.7139677857 6926062.751388512,2582555.8587416057 6888660.66129385,2616898.812207257 6804402.265121756,2619021.5635771938 6724260.500356969,2675005.805289493 6569348.140256124,2663069.1276112213 6520185.497277012,2607826.9416245497 6499876.064077411,2506742.3874537917 6356150.602420078,2535459.3651742414 6279511.031345595,2511160.4354043948 6289421.880163918,2405370.183718823 6355008.456351632,2325236.514312813 6330832.367176313,2272680.8015974555 6348389.571497864,2206911.465324937 6311783.589599679,2150771.932922981 6372407.959738907,2105004.260117216 6349141.540321699,2098722.389932261 6359484.564038589,2047489.8206844728 6444306.81695798,1964727.2301838885 6454772.693908454,1954165.459536404 6509230.976875272,1877822.7753893586 6528768.0347408345,1861203.5546503586 6483723.596648548,1800732.2469031638 6519788.167683334,1807675.688821904 6567999.355642543,1724447.1149328586 6583302.928204887,1671684.3479646263 6640184.854245133))

For example the result of the gsc.download.json() will be:

{"type":"FeatureCollection","features":[{"type":"Feature","id":"POL","geometry":{"type":"Polygon","coordinates":[[[1671684.3479646263,6640184.854245133],[1626054.7113274448,6754182.661784717],[1634729.616605983,6816405.39376582],[1607186.2802769665,6913904.573349097],[1566768.5108792358,6979532.83427941],[1597803.7169954556,7029035.420701512],[1571796.2556809138,7124274.129112371],[1647851.2902637494,7179765.258116936],[1821573.9272474437,7267947.776378672],[1961764.6845754066,7333105.428833309],[2072864.5420133455,7300508.48760427],[2081257.5863411953,7253686.180805331],[2188612.4334698664,7251268.076783722],[2325714.074928316,7229568.38433456],[2530414.3658514903,7232433.5491896],[2587508.796845471,7212040.207335641],[2614241.170684058,7153601.848893867],[2619073.3271404128,7070435.657623602],[2649953.2425669758,6999613.005002776],[2649314.7139677857,6926062.751388512],[2582555.8587416057,6888660.66129385],[2616898.812207257,6804402.265121756],[2619021.5635771938,6724260.500356969],[2675005.805289493,6569348.140256124],[2663069.1276112213,6520185.497277012],[2607826.9416245497,6499876.064077411],[2506742.3874537917,6356150.602420078],[2535459.3651742414,6279511.031345595],[2511160.4354043948,6289421.880163918],[2405370.183718823,6355008.456351632],[2325236.514312813,6330832.367176313],[2272680.8015974555,6348389.571497864],[2206911.465324937,6311783.589599679],[2150771.932922981,6372407.959738907],[2105004.260117216,6349141.540321699],[2098722.389932261,6359484.564038589],[2047489.8206844728,6444306.81695798],[1964727.2301838885,6454772.693908454],[1954165.459536404,6509230.976875272],[1877822.7753893586,6528768.0347408345],[1861203.5546503586,6483723.596648548],[1800732.2469031638,6519788.167683334],[1807675.688821904,6567999.355642543],[1724447.1149328586,6583302.928204887],[1671684.3479646263,6640184.854245133]]]},"properties":{"name":"Poland"}}]}
⚠️ **GitHub.com Fallback** ⚠️