-
Notifications
You must be signed in to change notification settings - Fork 5
/
08-SpatialPicking.html
206 lines (174 loc) · 7.06 KB
/
08-SpatialPicking.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!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://code.jquery.com/jquery-1.12.0.min.js"></script>
<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);
// set cursor always interactive
$('.leaflet-container').css('cursor', 'pointer');
// add click handler
map.on('click', onMapClick);
function onMapClick(e) {
$.ajax({
url: "08-SpatialPickingHandler.ashx?lat=" + e.latlng.lat + "&lng=" + e.latlng.lng,
type: "GET",
success: function (data, status, xhr) {
displayResult(data, e.latlng);
}
});
}
var pickedFeature;
var popup = L.popup();
function displayResult(pickedPolygon, latlng) {
if (pickedFeature)
map.removeLayer(pickedFeature);
var feature = {
"type": "Feature",
"properties": {
"style": {
weight: 4,
color: "#222",
opacity: 1,
fillColor: "#fff",
fillOpacity: 0.5
}
}
};
feature.geometry = pickedPolygon.geometry;
pickedFeature = L.geoJson([feature], {
style: function (feature) {
return feature.properties && feature.properties.style;
}
}).addTo(map);
popup.setLatLng(latlng)
.setContent('<h4>' + pickedPolygon.properties.name + '</h4><b>Area: </b>' +
new Intl.NumberFormat().format(pickedPolygon.properties.area) + ' km2<br><b>Population: </b>' + new Intl
.NumberFormat().format(pickedPolygon.properties.pop))
.openOn(map);
};
// 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>