population.html
11.3 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="kr">
<head>
<title>RF-Project</title>
<!-- link에 들어가 있는건 지도 데이터를 위한 css 파일 -->
<!-- script에 들어가 있는건 지도 데이터를 위한 js 파일 -->
<!-- 직접 다운받아 넣을 수도 있는데 우선은 그냥 웹에서 불러올 수 있도록 해놨다. -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
<!--css 내용 여기에 direct로 넣었다-->
<style>
#mapbase {position:relative; width:40%; height:0; padding-bottom:40%; }
h1 {
font-size: 20px;
}
.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 {
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
<!--BOOTSTRAP 사용 부분-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div id="bodyWrap">
<div id="header">
<h1><a href="/market_analysis/maplist">Statistics on Return Farm Project</a></h1>
<br>
<h3>농산물 시장 유통에 대한 통계분석 입니다.</h3>
<br>
</div>
<div id="menubar">
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="/market_analysis/market">Market</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/market_analysis/population">Population</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/market_analysis/returnfarm">Return Farm</a>
</li>
</ul>
</div>
</div>
<!--population 단독 부분-->
<!--return farm 단독 부분-->
<div id="contentWrap">
<!--검색 바 만든 부분-->
<div id="searchmenu">
<form action="{% url 'population' %}" method="GET">
<div class="form-group">
<select name="maptype">
<option value="9">시도</option>
<option value="10">시군구</option>
</select>
<select name="densitytype">
<option value="edu">귀농가구원 연령별</option>
</select>
<input type="submit">
</div>
</form>
</div>
<!--지도 생성 부분-->
<div id="mapbase">
<script type="text/javascript">
// map 객체 생성 map안에 넣어주는건 div id
// 위도, 경도, zoom 수준
var map = L.map('mapbase', {zoomDelta: 0.25, zoomSnap: 0}).setView([36.5205243,128.0540569], 7);
// tilelayer를 씌우는 작업 OSM을 사용했음
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 10,
id: 'mapbox/light-v9',
tileSize: 512,
zoomOffset:-1,
accessToken: 'pk.eyJ1IjoidGpzZGszMTA1IiwiYSI6ImNrYWM5bXljZzB1N28ycnA5bTVsNHZsbnkifQ.W3-irWof5WMR8BcfBR4Ftw'
}).addTo(map);
// mapdata 가져오는 부분
// replace 쓰는 방법 : (바꾸기 전 문자, 바꾸고 난 후 문자)
var statesdata = "{{maps.mapdata}}".replace(/"/g,"\"");
statesdata = JSON.parse(statesdata);
let key = Object.keys(statesdata.features[1].properties);
</script>
</div>
<!--지도에 밀도 데이터 받는 부분-->
<div id="density_mapping">
<script>
var densitydatas = "{{exportdata}}".replace(/"/g,"\"");
densitydatas = JSON.parse(densitydatas);
for(var i=0; i < densitydatas.length; i++)
{
for(var j=0; j<statesdata.features.length; j++)
{
if (statesdata.features[j]['properties'][key[2]]==densitydatas[i]['C1_NM'] && densitydatas[i]['ITM_NM']=='귀농가구원수')
{
statesdata.features[j]['properties']['density']=densitydatas[i]['DT'];
break;
}
}
}
</script>
</div>
<!--지도의 큰 모양 바꾸는 부분-->
<div id="map_design">
<script>
var geojson;
function getColor(d) {
return d > parseInt(density_max*0.9) ? '#FF0015' :
d > parseInt(density_max*0.8) ? '#F20D20' :
d > parseInt(density_max*0.7) ? '#E6192A' :
d > parseInt(density_max*0.6) ? '#D92635' :
d > parseInt(density_max*0.5) ? '#CC3340' :
d > parseInt(density_max*0.4) ? '#BF404A' :
d > parseInt(density_max*0.3) ? '#B34D55' :
d > parseInt(density_max*0.2) ? '#A65960' :
d > parseInt(density_max*0.1) ? '#99666A' :
'#8C7375';
}
function style(feature) {
return {
fillColor: getColor(feature.properties.density),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
L.geoJson(statesdata, {style: style}).addTo(map);
// mouseover event listener
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
// mouseout define
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(statesdata, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
</script>
</div>
<!--information, legend, zoom 넣는 부분-->
<div class="map_info">
<script>
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (props) {
this._div.innerHTML = '<h4>Korea Return Farm Density</h4>' + (props ?
'<b>' + props[key[2]] + '</b><br />' + props.density + ' 개의 교육 예정'
: 'Hover over a state');
};
info.addTo(map);
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, parseInt(density_max*0.1), parseInt(density_max*0.2), parseInt(density_max*0.3), parseInt(density_max*0.4),parseInt(density_max*0.5), parseInt(density_max*0.6), parseInt(density_max*0.7), parseInt(density_max*0.8),parseInt(density_max*0.9)],
labels = [],
from, to;
// loop through our density intervals and generate a label with a colored square for each interval
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i+1];
labels.push(
'<i style="background: '+ getColor(from + 1) + '"></i> ' + from + (to ? '–' + to :'+'));
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(map);
</script>
</div>
</div>
</body>
</html>