forked from ptv-logistics/SpatialTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
07-ThematicTiles.html
139 lines (119 loc) · 4.22 KB
/
07-ThematicTiles.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Leaflet NonTiledLayer Example</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<link href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" rel="stylesheet">
<style>
body {
padding: 0;
margin: 0;
}
html,
body,
#map {
height: 100%;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.legend {
text-align: left;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body>
<div id="map" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="./NonTiledLayer.js"></script>
<script src="./NonTiledLayer.WMS.js"></script>
<script src="./token.js"></script>
<script>
// initialize leaflet
var map = new L.Map('map');
// center Karlsruhe
map.setView(new L.LatLng(50, 10), 4);
// using the xmap WMS servlet
var xMapUrl = 'https://xmap-eu-n-test.cloud.ptvgroup.com';
var xMapAttribution = '<a href="http://www.ptvgroup.com">PTV<\/a>, HERE';
// add the xServer layers
// set the layer groups for default and sandbox
var baseLayers = {
"PTV classic": getLayers(xMapUrl + '/WMS/WMS', "", xMapAttribution),
"PTV sandbox": getLayers(xMapUrl + '/WMS/WMS', "sandbox", xMapAttribution).addTo(map),
"PTV silkysand": getLayers(xMapUrl + '/WMS/WMS', "silkysand", xMapAttribution)
};
L.control.layers(baseLayers, null).addTo(map);
// add dymamic tile layer
var myTileLayerUrl = '07-ThematicTilesHandler.ashx?x={x}&y={y}&z={z}',
myTileLayer = new L.TileLayer(myTileLayerUrl, {
maxZoom: 20, zIndex: 100
});
map.addLayer(myTileLayer);
// using legend code from http://leafletjs.com/examples/choropleth-example.html
var legend = L.control({ position: 'bottomright' });
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 50, 100, 250, 500, 1000, 2500],
labels = [];
div.innerHTML = '<h4>Population density</h4>';
// loop through our density intervals and generate a label with a colored square for each interval
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + getColor(grades[i] + 1) + '"></i> ' +
grades[i] + (grades[i + 1] ? '–' + grades[i + 1] + '<br>' : '+');
}
return div;
};
legend.addTo(map);
// get color depending on population density value
function getColor(d) {
return d > 2500 ? '#800080' :
d > 1000 ? '#8B0000' :
d > 500 ? '#FF0000' :
d > 250 ? '#FFA500' :
d > 100 ? '#FFFF00' :
d > 50 ? '#90EE90' :
'#008000';
}
// returns a layer group for xmap back- and foreground layers
function getLayers(url, style, attribution) {
var background = new L.TileLayer.WMS(url, {
maxZoom: 19,
minZoom: 0,
noWrap: true,
layers: style? 'xmap-' + style + '-bg' : 'xmap-ajaxbg',
format: 'image/gif',
transparent: false,
attribution: attribution
});
var foreground = new L.NonTiledLayer.WMS(url + '?xtok=' + token, {
layers: style? 'xmap-' + style + '-fg' : 'xmap-ajafbg',
format: 'image/gif',
transparent: true,
attribution: attribution
});
return L.layerGroup([background, foreground]);
}
</script>
</body>
</html>