block by ThomasG77 265dd602949870b26808c02a8478dadc

Finland map with local OpenStreetMap basemap OpenLayers

Full Screen

index.html

<!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: '//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="//www.openstreetmap.org/copyright">OpenStreetMap contributors</a>',
              params: {
                'LAYERS': 'osm-finland',
                'FORMAT': 'image/png'
              }
            })
          })
        ],
        target: 'map',
        view: view
      });

      view.fit(extent);

    </script>
  </body>
</html>