-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetFeatureInfoWMS.html
More file actions
83 lines (75 loc) · 2.49 KB
/
Copy pathGetFeatureInfoWMS.html
File metadata and controls
83 lines (75 loc) · 2.49 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<meta charset="utf-8">
<link rel="stylesheet" href="ol/ol.css" type="text/css">
<style>
#map {
width: 100%;
height: 400px;
}
</style>
<title>OpenLayers example</title>
<script src="ol/ol.js" type="text/javascript"></script>
</head>
<body>
<div id="map" class="map"></div>
<div id="info">No information</div>
<script type="text/javascript">
var wmsSource = new ol.source.ImageWMS({
url: 'http://39.97.184.163/geoserver/WebGIS/wms',
params: {
'LAYERS': 'WebGIS:province_boundary,WebGIS:china_boundary,WebGIS:river,WebGIS:road,WebGIS:railway,WebGIS:capital'
},
serverType: 'geoserver',
crossOrigin: 'anonymous'
});
var wmsLayer = new ol.layer.Image({
source: wmsSource
});
var view = new ol.View({
projection:'EPSG:4326',
center: [104, 28],
zoom: 3
});
var map = new ol.Map({
controls: ol.control.defaults().extend([
new ol.control.ScaleLine({
units: 'degrees'
})
]),
layers: [wmsLayer],
target: 'map',
view: view
});
map.on('singleclick', function (evt) {
document.getElementById('info').innerHTML = '';
var viewResolution = /** @type {number} */ (view.getResolution());
var url = wmsSource.getFeatureInfoUrl(
evt.coordinate, viewResolution, 'EPSG:4326', {
'INFO_FORMAT': 'text/html'
});
if (url) {
fetch(url)
.then(function (response) {
return response.text();
})
.then(function (html) {
document.getElementById('info').innerHTML = html;
});
}
});
map.on('pointermove', function (evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
var hit = map.forEachLayerAtPixel(pixel, function () {
return true;
});
map.getTargetElement().style.cursor = hit ? 'pointer' : '';
});
</script>
</body>
</html>