Wednesday, April 29, 2015

Using Open Layers to display Map

Here is a simple example on how to load a map using "Open Layers" open source GIS API.

==== JavaScript Code ========

$(document).ready(function () {

LoadMap();

}); 


function LoadMap() {

var map = new ol.Map({

target: 'map',

layers: [


new ol.layer.Tile({

source: new ol.source.MapQuest({ layer: 'sat' })

})

],


view: new ol.View({

center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),

zoom: 4

})

});

}

=================================================

======== Code from Index.html =============================

<link rel="stylesheet" href="http://openlayers.org/en/v3.2.1/css/ol.css" type="text/css">

<script src="http://openlayers.org/en/v3.2.1/build/ol.js" type="text/javascript"></script>

<script src="scripts/mainJavaScript.js"></script>

<div id="map" class="map"></div>

============================================================

These lines should display a "World Map".

Happy Coding.

Cheers
Adam




 

All Blogs so far ...