Created
September 25, 2013 09:48
-
-
Save atlefren/6697409 to your computer and use it in GitHub Desktop.
Small utility for displaying tiles from Statkart in OpenLayers 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta http-equiv="X-UA-Compatible" content="IE=8"> | |
| <meta charset="UTF-8"> | |
| <title>OpenLayers 3 with Statkart tiles</title> | |
| </head> | |
| <link rel="stylesheet" href="http://ol3js.org/en/master/build/ol.css" type="text/css"> | |
| <style type="text/css"> | |
| html, body { | |
| height: 100%; | |
| margin: 0; | |
| } | |
| .map_fullscreen { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| </style> | |
| <body> | |
| <div id="map" class="map_fullscreen"></div> | |
| <script src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></script> | |
| <script type="text/javascript"> | |
| (function () { | |
| //this could (should?) be moved to a separate file | |
| var ol3utils = window.ol3utils || {}; | |
| ol3utils.SkTiles = function (options) { | |
| /** | |
| Tiles from Statkart. Available layers are: | |
| - matrikkel_bakgrunn | |
| - topo2 | |
| - topo2graatone | |
| - europa | |
| - toporaster2 | |
| - sjo_hovedkart2 | |
| - kartdata2 | |
| - norges_grunnkart | |
| - norges_grunnkart_graatone | |
| See http://statkart.no/Kart/Kartverksted/Visningstjenester/ | |
| **/ | |
| return new ol.layer.Tile({ | |
| source: new ol.source.XYZ({ | |
| attributions: [ | |
| new ol.Attribution({ | |
| html: "© <a href='http://statkart.no'>Kartverket</a>" | |
| }) | |
| ], | |
| url: 'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=' + options.layers + '&zoom={z}&x={x}&y={y}' | |
| }) | |
| }) | |
| }; | |
| //actually set up the map | |
| var map = new ol.Map({ | |
| target: 'map', | |
| layers: [ | |
| new ol3utils.SkTiles({layers: "topo2"}) | |
| ], | |
| renderer: ol.RendererHint.CANVAS, | |
| view: new ol.View2D({ | |
| center: ol.proj.transform([15, 64.5], 'EPSG:4326', 'EPSG:3857'), | |
| zoom: 5 | |
| }) | |
| }); | |
| }()); | |
| </script> | |
| </body> | |
| </html> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider this MIT-lisenced