-
Notifications
You must be signed in to change notification settings - Fork 2
/
005script.js
100 lines (84 loc) · 2.77 KB
/
005script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const initialZoom = 13
const latitude = 58.15
const longitude = 8
// Map
var map = L.map("map").setView([latitude, longitude], initialZoom);
// OsmTileLayer
const openStreetMapTileLayerLink = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
const openStreetMapAttribution = '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors';
// OtmTileLayer
const openTopoMapLayerLink = "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png";
const openTopoMapMaxZoom = 17;
const openTopoMapAttribution = 'Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)';
// Norkart API key
const apiKey = "" // User your own key from https://developer.norkart.no/
/**************************
* Defining the map Layers *
**************************/
var openStreetMap = L.tileLayer(openStreetMapTileLayerLink,
{
attribution: openStreetMapAttribution,
}
);
var openTopoMap = L.tileLayer(openTopoMapLayerLink,
{
maxZoom: openTopoMapMaxZoom,
attribution: openTopoMapAttribution,
}
);
var norkartLite = L.tileLayer.webatlas(
{
mapType: L.TileLayer.Webatlas.Type.LITE,
apikey: apiKey,
}
);
var norkartHybrid = L.tileLayer.webatlas(
{
mapType: L.TileLayer.Webatlas.Type.HYBRID,
apikey: apiKey,
}
);
var norkartAerial = L.tileLayer.webatlas(
{
mapType: L.TileLayer.Webatlas.Type.AERIAL,
apikey: apiKey,
}
);
/** All available Norkart map types
L.TileLayer.Webatlas.Type.GREY
L.TileLayer.Webatlas.Type.VECTOR
L.TileLayer.Webatlas.Type.MEDIUM
L.TileLayer.Webatlas.Type.LITE
L.TileLayer.Webatlas.Type.AERIAL
L.TileLayer.Webatlas.Type.HYBRID
*/
/***********************************
* Async henting av geojson *
***********************************/
async function getGeojson(path) {
return fetch(path).then((response) => response.json());
}
/***********************************
* Setting up a marker with a popup *
***********************************/
const myMarkersGEOJSON = await getGeojson("data/myMarkers.geojson");
var myMarkers = L.geoJSON(myMarkersGEOJSON, {
onEachFeature: function (feature, layer) {
layer.bindPopup(
"<h4>" + feature.properties.name + "</h4>" +
"<p>" + feature.properties.popupContent + "</p>"
);
},
}).addTo(map);
/***************************************
* Setting up the map and adding layers *
***************************************/
norkartAerial.addTo(map);
var baseLayers = {
OpenStreetMap: openStreetMap,
Topo: openTopoMap,
NorkartLite: norkartLite,
NorkartHybrid: norkartHybrid,
NorkartAerial: norkartAerial,
};
L.control.layers(baseLayers).addTo(map);