GBDX

OpenLayers html example - basic

This simple html example shows how create an OpenLayers map using an IDAHO TMS layer.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>IDAHO OpenLayers demo</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.css">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.js"></script>
    <style>
        #map
        {
            border: 1px solid #ddd;
            background-color: #ddd;
            width: 100%;
            height: 400px
        }
    </style>

</head>
<body>
<div id="map"></div>
<script type="application/javascript">
    var token = "INSERT TOKEN HERE";
    var layerurl = 'http://idaho.geobigdata.io/v1/tile/idaho-images/fda14d57-a65e-46d7-b9c5-9836ffea0cc0/{z}/{x}/{y}?bands=4,2,1&token='+token;
    var map = new ol.Map({
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM({
                    url: layerurl
                })
            })
        ],
        target: 'map',
        view: new ol.View({
            center: ol.proj.transform([-122.32, 37.55], 'EPSG:4326', 'EPSG:3857'),
            zoom: 13
        })
    });
</script>
</body>
</html>

To use this example, replace "insert token here" with a valid GBDX token string.

var token = "INSERT TOKEN HERE";

To learn more about tokens, see Authentication Course.