Skip to content

How to use leaflet with open Kartverket/Geonorge WMTS map tiles in non-default projections like EPSG:32633 (UTM33), similar to the ones seen on norgeskart.no.

License

Notifications You must be signed in to change notification settings

cpetrich/leaflet-kartverket-UTM33

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Leaflet Map with UTM33 CRS

Here is a working example for getting leaflet to produce a map with open WMTS tiles from Kartverket, similar to https://norgeskart.no/ (The open WMTS tiles differ slightly in layout and shading and are distributed as paletted png files, which makes them smaller than the ones on norgeskart.no.) Norgeskart uses the default projection of Norway, EPSG:32633 (UMT33), which differs from the leaflet default CRS EPSG:3857 (google projection). The code uses proj4leaflet (which depends on proj4js) to define the CRS.

Here we go, also see index.html for a working example:

    <div style="width: 100vw; height: 100vh" id="map"></div>
    <!-- The Javascript code is licensed under the MIT license (c) Chris Petrich, 2021. SPDX short identifier: MIT -->
    <script type="text/javascript">
      const crsStr = 'EPSG:25833';
      const crsProj4 = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
      // The origin is the <TopLeftCorner> in the response to a GetCapabilities call to
      // https://opencache.statkart.no/gatekeeper/gk/gk.open_wmts?Version=1.0.0&service=wmts&request=getcapabilities
      const crsTileOrg = [-2500000, 9045984];
      // crsBaseResolution is the <ScaleDenominator> at zoom level 0 from the GetCapabilities call times 0.00028
      const crsBaseResolution = 21664;
      // according to the GetCapabilities info, zoom levels 0 through 18 are defined for EPSG:25833
      const crsMaxZoom = 18;
      const crs = new L.Proj.CRS(crsStr, crsProj4,
                        { origin: crsTileOrg, 
                          resolutions: Array.from(Array(crsMaxZoom+2),(e,zoomLevel) => crsBaseResolution/Math.pow(2,zoomLevel))
                        });
      const map = L.map('map', {
          center: [68.44, 17.4], // Narvik, Norway
          zoom: 13,
          crs: crs,
      });
      // map tile IDs are the GetCapabilities <ows:Identifier>
      const owsId = 'norgeskart_bakgrunn';
      const url = 'https://opencache{s}.statkart.no/gatekeeper/gk/gk.open_wmts?&layer='+owsId+'&style=default&tilematrixset='+crsStr+'&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix='+crsStr+':{z}&TileCol={x}&TileRow={y}';
      const kartverketTiles = L.tileLayer(url, {
          subdomains: ['', '2', '3'],
          maxZoom: crsMaxZoom,
          attribution: '<a href="https://www.kartverket.no/">Kartverket</a>',
      });
      map.addLayer(kartverketTiles);
    </script>

Resources used

About

How to use leaflet with open Kartverket/Geonorge WMTS map tiles in non-default projections like EPSG:32633 (UTM33), similar to the ones seen on norgeskart.no.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages