-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeSymbolStyle.html
More file actions
108 lines (94 loc) · 3.25 KB
/
typeSymbolStyle.html
File metadata and controls
108 lines (94 loc) · 3.25 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
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link href="https://developer.geon.kr/js/odf/odf.css" rel="stylesheet">
<script type="text/javascript" src="https://developer.geon.kr/js/odf/odf.min.js"></script>
</head>
<body>
<div id="map" class="odf-view" style="height:550px;"></div>
<div class="btnDiv">
속성 : <select class="selectCustom" id="attributes" onChange="setStyle()">
<option value="">선택
</select>
</div>
</body>
<script>
/* 맵객체 생성 (외부에서 사용할 때는 proxyURL, proxyParam 옵션이 필요합니다.) */
var mapContainer = document.getElementById('map');
var coord = new odf.Coordinate(199312.9996,551784.6924);
var mapOption = {
center : coord,
zoom : 11,
projection : 'EPSG:5186',
//proxyURL: 'proxyUrl.jsp',
//proxyParam: 'url',
vWorldURL : 'https://gsapi.geon.kr/map/api/vworld/wmts',
basemap : {
vWorld : ['vWorldBase', 'vWorldWhite', 'vWorldMidnight', 'vWorldHybrid', 'vWorldSatellite'],
},
};
var map = new odf.Map(mapContainer, mapOption);
/*포인트 레이어 추가*/
var pointLayer = odf.LayerFactory.produce('geoserver', {
method: 'get',
server: 'https://geoserver.geon.kr/geoserver',
layer: 'geonpaas:L100000256', // 발행된 레이어 명칭 (ex. 저장소명:레이어명)
crtfckey: '',
service: 'wfs',
limit: 50,
});
pointLayer.setMap(map);
pointLayer.fit();
//레이어의 속성 종류 조회 -wfs레이어만 가능
var attributes = pointLayer.getAttributes();//INT 타입의 속성만 조회
for (var i = 0; i < attributes.length; i++) {
var attr = attributes[i];
var option = document.createElement('option');
option.value = attr.name;
option.innerHTML = attr.name;
document.getElementById('attributes').appendChild(option);
}
/*동적 스타일 생성*/
function setStyle() {
var attr = document.getElementById('attributes').value;
if (attr === "") {
return;
}
//값의 종류 조회
var range = pointLayer.getAttributesFeaturesValueRange(attr).values;
//선택된 색상계열로 feature의 개수 만큼 색 생성
var colorList = odf.ColorFactory.produce(
'random', //색 계열 'red', 'blue', 'yellow', 'green', 'purple', 'brown', 'black', 'random' 중 하나
Object.keys(range).length
);
//선택된 속성별로 색 부여
var keys = Object.keys(range);
keys.forEach((item, idx) => (range[item].color = colorList[idx++]));
//동적 스타일 생성
var styleFunction = odf.StyleFactory.produceFunction([
//기본스타일
{
seperatorFunc: 'default',
style: {
image: {
icon: {
size: [100, 100], //이미지가 그려지는 도형 크기 ※ 그림을 그린 도화지의 크기
src: 'images/icon_smile_white.png' //이미지 경로
},
},
},
callbackFunc: function (style, feature, resolution) {
//기본 style opption
var iconOption = this.style.image.icon;
//생성된 색상으로 채우기 값 변경
iconOption.color = range[feature.getProperties()[attr]].color;
//새로운 circle옵션으로 circle 스타일 생성하여 set--circle 스타일은 새로 생성하여 setImage해야 적용됨
style.setImage(odf.StyleFactory.produceIcon(iconOption));
},
},
]);
pointLayer.setStyle(styleFunction);
}
</script>
</html>