Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Created May 5, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/265dd602949870b26808c02a8478dadc to your computer and use it in GitHub Desktop.
Save ThomasG77/265dd602949870b26808c02a8478dadc to your computer and use it in GitHub Desktop.
Finland map with local OpenStreetMap basemap OpenLayers
<!DOCTYPE html>
<html>
<head>
<title>Finland map with local OpenStreetMap basemap</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/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>
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var newProjCode = 'EPSG:3067';
proj4.defs('EPSG:3067', '+proj=utm +zone=35 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
var newProj = ol.proj.get(newProjCode);
var fromLonLat = ol.proj.getTransform('EPSG:4326', newProj);
// very approximate calculation of projection extent
var extent = ol.extent.applyTransform(
[19.08, 58.84, 31.59, 70.09], fromLonLat);
newProj.setExtent(extent);
var view = new ol.View({
projection: newProj
});
// https://avaa.tdata.fi/web/avaa/openstreetmap
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://avaa.tdata.fi/geoserver/osm_finland/wms',
// crossOrigin: 'anonymous',
attributions: 'Map: <a href="https://avaa.tdata.fi/web/avaa/openstreetmap">Ministry of Education and Culture</a>, Data: <a href="http://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>',
params: {
'LAYERS': 'osm-finland',
'FORMAT': 'image/png'
}
})
})
],
target: 'map',
view: view
});
view.fit(extent);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment