This example shows how to add a graticule overlay to a map.
This example shows how to add a graticule overlay to a map.
<!DOCTYPE html>
<html>
<head>
<title>Map Graticule</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
import Graticule from 'ol/Graticule.js';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import {fromLonLat} from 'ol/proj.js';
import OSM from 'ol/source/OSM.js';
import Stroke from 'ol/style/Stroke.js';
var map = new Map({
layers: [
new TileLayer({
source: new OSM({
wrapX: false
})
})
],
target: 'map',
view: new View({
center: fromLonLat([4.8, 47.75]),
zoom: 5
})
});
// Create the graticule component
var graticule = new Graticule({
// the style to use for the lines, optional.
strokeStyle: new Stroke({
color: 'rgba(255,120,0,0.9)',
width: 2,
lineDash: [0.5, 4]
}),
showLabels: true
});
graticule.setMap(map);
</script>
</body>
</html>