-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32_!_WMSGetFeatureInfo(TileLayer).html
82 lines (71 loc) · 2.8 KB
/
32_!_WMSGetFeatureInfo(TileLayer).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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="ol.js"></script>
<link rel="stylesheet" href="ol.css">
<script
src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL">
</script>
</head>
<body>
<!-- 기본틀로 사용하는 양식 -->
<div id="map" class="map"></div>
<div id="info"> </div>
<script>
var BingMapKey = "Ar-WkIA7R3sY5gwqt0oUGHrGTnxGGFCF4EOaAjgZ2D9JdF5EuXZdhpXxbE7PQnxa";
//CORS , chrome.exe --disable-web-security --allow-file-access-from-files
//1.wms 로부터 wmsSorce를 받아온다.
var wmsSource = new ol.source.TileWMS({
url: 'https://ahocevar.com/geoserver/wms',
params: {
'LAYERS': 'ne:ne'
, 'TILED': true
},
serverType: 'geoserver',
crossOrigin: 'anonymous'
});
//2.wmsSource로 Layer 생성
var wmsLayer = new ol.layer.Tile({
source: wmsSource
});
var view = new ol.View({
center: [0, 0],
zoom: 1
});
//wmsLayer로 map 생성
var map = new ol.Map({
layers: [wmsLayer],
target: 'map',
view: view
});
//3. 생성된 map에 단일클릭 이벤트 적용
map.on('singleclick', function (evt) {
document.getElementById('info').innerHTML = '';
var viewResolution = (view.getResolution()); //뷰의 해상도
var url = wmsSource.getGetFeatureInfoUrl( //coordinate, resolution, and projection 를 가지고 URL을 통해 GetFeatureInfo URL반환
evt.coordinate, viewResolution, 'EPSG:3857', {
'INFO_FORMAT': 'text/html'
});
if (url) {
document.getElementById('info').innerHTML =
'<iframe seamless src="' + url + '"></iframe>';
}
});
//4.. 생성된 map에 포인트무브(그냥 마우스가 움직일때) 이벤트 적용
map.on('pointermove', function (evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
var hit = map.forEachLayerAtPixel(pixel, function () {
return true; //Layer에 접근해서 픽셀에생상값이 있는지 없는지 찾아낸다.
});
map.getTargetElement().style.cursor = hit ? 'pointer' : ''; //이맵이 랜더링 되는 DOM 요소를 가져옵니다. 이걸알았더라면....
});
</script>
</body>
</html>