-
Notifications
You must be signed in to change notification settings - Fork 5
/
07-ThematicTiles.html
154 lines (131 loc) · 5.12 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>ptv-logistics SpatialTutorial</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="https://unpkg.com/[email protected]/dist/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: 19px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body>
<div id="map" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.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);
// create xMapServer-2 base layers
var baseLayers = createBaseLayers();
// 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';
}
function createBaseLayers() {
if (!window.token) {
// no token defined - use xMap-1 background tlies
var url = 'https://api{s}-test.cloud.ptvgroup.com/WMS/GetTile/xmap-{profile}-bg/{x}/{y}/{z}.png'
var background = new L.TileLayer.WMS(url, {
maxZoom: 19,
minZoom: 0,
opacity: 1.0,
noWrap: true,
attribution: '<a target="_blank" href="http://www.ptvgroup.com">PTV</a>, TOMTOM',
profile: 'silkysand',
subdomains: '1234'
});
return L.layerGroup([background]).addTo(map);
} else {
var background = L.tileLayer(
'https://s0{s}-xserver2-europe-test.cloud.ptvgroup.com/services/rest/XMap/tile/{z}/{x}/{y}' +
'?storedProfile={profile}&layers=background,transport&xtok={token}', {
profile: 'silkysand',
token: window.token,
attribution: '<a target="_blank" href="http://www.ptvgroup.com">PTV</a>, TOMTOM',
subdomains: '1234',
maxZoom: 22,
pane: 'tilePane'
}).addTo(map);
var foreground = L.tileLayer(
'https://s0{s}-xserver2-europe-test.cloud.ptvgroup.com/services/rest/XMap/tile/{z}/{x}/{y}' +
'?storedProfile={profile}&layers=labels&xtok={token}', {
profile: 'silkysand',
token: window.token,
attribution: '<a target="_blank" href="http://www.ptvgroup.com">PTV</a>, TOMTOM',
subdomains: '1234',
maxZoom: 22,
zIndex: 200,
pane: 'shadowPane'
}).addTo(map);
return L.layerGroup([background, foreground]).addTo(map);
}
}
</script>
</body>
</html>