161 lines
3.7 KiB
HTML
161 lines
3.7 KiB
HTML
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<base target="_top">
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>Kepadatan Penduduk Kota Pontianak</title>
|
|
|
|
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
|
|
|
<style>
|
|
html, body {
|
|
height: 100%;
|
|
margin: 0;
|
|
}
|
|
|
|
#map {
|
|
width: 100%;
|
|
height: 100vh;
|
|
}
|
|
</style>
|
|
|
|
<style>
|
|
.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 { text-align: left; line-height: 18px; color: #555; } .legend i { width: 18px; height: 18px; float: left; margin-right: 8px; opacity: 0.7; }</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id='map'></div>
|
|
|
|
<script type="text/javascript" src="pontianak.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
const map = L.map('map').setView([-0.02, 109.34], 12);
|
|
|
|
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
maxZoom: 19,
|
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
}).addTo(map);
|
|
|
|
// control that shows state info on hover
|
|
const info = L.control();
|
|
|
|
info.onAdd = function (map) {
|
|
this._div = L.DomUtil.create('div', 'info');
|
|
this.update();
|
|
return this._div;
|
|
};
|
|
|
|
info.update = function (props) {
|
|
const contents = props
|
|
? `<b>${props.Ket}</b><br />Jumlah Penduduk: ${props.jmlPenddk} jiwa`
|
|
: 'Arahkan kursor ke wilayah';
|
|
|
|
this._div.innerHTML = `<h4>Kepadatan Penduduk Kota Pontianak</h4>${contents}`;
|
|
};
|
|
|
|
info.addTo(map);
|
|
|
|
|
|
// get color depending on population density value
|
|
function getColor(d) {
|
|
return d > 100000 ? '#800026' :
|
|
d > 80000 ? '#BD0026' :
|
|
d > 60000 ? '#E31A1C' :
|
|
d > 40000 ? '#FC4E2A' :
|
|
d > 20000 ? '#FD8D3C' :
|
|
d > 10000 ? '#FEB24C' :
|
|
d > 5000 ? '#FED976' :
|
|
'#FFEDA0';
|
|
}
|
|
|
|
function style(feature) {
|
|
return {
|
|
weight: 2,
|
|
opacity: 1,
|
|
color: 'white',
|
|
dashArray: '3',
|
|
fillOpacity: 0.7,
|
|
fillColor: getColor(feature.properties.jmlPenddk)
|
|
};
|
|
}
|
|
|
|
function highlightFeature(e) {
|
|
const layer = e.target;
|
|
|
|
layer.setStyle({
|
|
weight: 5,
|
|
color: '#666',
|
|
dashArray: '',
|
|
fillOpacity: 0.7
|
|
});
|
|
|
|
layer.bringToFront();
|
|
|
|
info.update(layer.feature.properties);
|
|
}
|
|
|
|
/* global statesData */
|
|
const geojson = L.geoJson(datapontianak, {
|
|
style,
|
|
onEachFeature
|
|
}).addTo(map);
|
|
|
|
map.fitBounds(geojson.getBounds());
|
|
|
|
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
|
|
});
|
|
}
|
|
|
|
map.attributionControl.addAttribution('Population data © <a href="http://census.gov/">US Census Bureau</a>');
|
|
|
|
|
|
const legend = L.control({position: 'bottomright'});
|
|
|
|
legend.onAdd = function (map) {
|
|
|
|
const div = L.DomUtil.create('div', 'info legend');
|
|
const grades = [0, 5000, 10000, 20000, 40000, 60000, 80000, 100000];
|
|
const labels = [];
|
|
let from, to;
|
|
|
|
for (let 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>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|