population.html
13.2 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!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>
<!--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>
<style>
#mapbase {position:relative; width:80%; height:0; padding-bottom:80%; margin-left: 3%;}
h1 {
font-size: 20px;
}
.form-group{
margin-left: 3%;
margin-top: 2%;
}
.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;
}
#bodyWrap{
text-align: center;
background: #fffce2;
}
a.projectname{
font-family: "THE또박또박";
color: black;
text-decoration:none;
}
a.projectname:hover{
color: orange;
text-decoration:none;
}
h3{
font-family: "Dovemayo";
font-size: 150%;
}
a.nav-link{
font-size: 175%;
font-family: "THE또박또박";
color: black;
}
a.nav-link:hover{
color: orange;
}
p{
font-family: "Dovemayo";
font-size: medium;
}
</style>
</head>
<body>
<!--body-->
<div id="bodyWrap">
<div id="header">
<h1 class="projectname"><a class="projectname" 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" 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 단독 부분-->
<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="returnfarm_agri_population">지역별 귀농가구원수</option>
<option value="population">지역별 총 인구수</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);
//alert(key);
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;
}
else 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;
var density_max = 500000;
if (key[2]=='CTP_KOR_NM' && densitydatas[3]['ITM_NM']=='총인구')
{ density_max = 8000000;}
else if(key[2]=='CTP_KOR_NM' && densitydatas[3]['ITM_NM']=='귀농가구원수')
{ density_max = 300;}
else if(key[2]=='SIG_KOR_NM' && densitydatas[3]['ITM_NM']=='총인구')
{ density_max = 500000;}
else if(key[2]=='SIG_KOR_NM' && densitydatas[3]['ITM_NM']=='귀농가구원수')
{ density_max = 100;}
function getColor(d) {
return d > parseInt(density_max*0.9) ? '#7e5109' :
d > parseInt(density_max*0.8) ? '#9c640c' :
d > parseInt(density_max*0.7) ? '#b9770e' :
d > parseInt(density_max*0.6) ? '#d68910' :
d > parseInt(density_max*0.5) ? '#f39c12' :
d > parseInt(density_max*0.4) ? '#f5b041' :
d > parseInt(density_max*0.3) ? '#f8c471' :
d > parseInt(density_max*0.2) ? '#fad7a0' :
d > parseInt(density_max*0.1) ? '#fdebd0' :
'#fef5e7';
}
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> ' + 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>