-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path78_selectFeaturesHover.html
81 lines (70 loc) · 2.13 KB
/
78_selectFeaturesHover.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
<!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>
<script>
// :
//기본 : Map View Source Layer
//추가 : format(GeoJSON) style
</script>
<body>
<!-- 기본틀로 사용하는 양식 -->
<div id="map" class="map"></div>
<span id="status"></span>
<script>
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var highlightStyle = new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255,255,255,0.7)'
}),
stroke: new ol.style.Stroke({
color: '#3399CC',
width: 3
})
});
var vector = new ol.layer.Vector({
source: new ol.source.VectorSource({
url: 'data/geojson/countries.geojson',
format: new ol.format.GeoJSON()
})
});
var map = new ol.Map({
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
var selected = null;
var status = document.getElementById('status');
map.on('pointermove', function (e) {
if (selected !== null) {
selected.setStyle(undefined);
selected = null;
}
map.forEachFeatureAtPixel(e.pixel, function (f) {
selected = f;
f.setStyle(highlightStyle);
return true;
});
if (selected) {
status.innerHTML = ' Hovering: ' + selected.get('name');
} else {
status.innerHTML = ' ';
}
});
</script>
</body>
</html>