Skip to content

Commit

Permalink
test reduce geojson size
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusindrayana committed Apr 10, 2024
1 parent 3eeacee commit ea34e03
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [x] Informasi Gempa
- [ ] Informasi Tsunami
- [ ] Data Geojson Garis Pantai/Pesisir
- [ ] Reduce Geojson Size
- [ ] PWA
- [ ] Push Notification
- [ ] Broadcast System
Expand Down
54 changes: 51 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ export default function Home() {
const areas = data.area;

// Hapus data array objek yang sama
const uniqueData = areas.filter((obj, index, self) =>
index === self.findIndex((t) => isEqual(t.properties, obj.properties))
);
// const uniqueData = areas.filter((obj, index, self) =>
// index === self.findIndex((t) => isEqual(t.properties.mhid, obj.properties.mhid))
// );

const uniqueData = areas;

for (let x = 0; x < uniqueData.length; x++) {
const element = uniqueData[x];
Expand Down Expand Up @@ -338,6 +340,7 @@ export default function Home() {
sendWave();
}

const hoverWilayah = useRef<any>(null);
function loadGeoJsonData() {
fetch('/geojson/all_kabkota_ind.geojson')
.then(response => response.json())
Expand All @@ -359,6 +362,51 @@ export default function Home() {
'line-width': 1
}
});

map.current!.addLayer({
'id': 'wilayah-fill',
'type': 'fill',
'source': 'wilayah',
'layout': {

},
'paint': {
'fill-color': 'red',
'fill-opacity': [
'case',
['boolean', ['feature-state', 'hover'], false],
0.1,
0
],

}
});

// map.current!.on('mousemove', 'wilayah-fill', (e: any) => {
// if (e.features.length > 0) {
// if (hoverWilayah.current !== null) {
// map.current!.setFeatureState(
// { source: 'wilayah', id: hoverWilayah.current },
// { hover: false }
// );
// }
// hoverWilayah.current = e.features[0].id;
// map.current!.setFeatureState(
// { source: 'wilayah', id: hoverWilayah.current },
// { hover: true }
// );
// }
// });

// map.current!.on('mouseleave', 'wilayah-fill', () => {
// if (hoverWilayah.current !== null) {
// map.current!.setFeatureState(
// { source: 'wilayah', id: hoverWilayah.current },
// { hover: false }
// );
// }
// hoverWilayah.current = null;
// });
}
// getTitikStationJson();
getTitikGempaJson();
Expand Down
25 changes: 20 additions & 5 deletions app/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function checkMultiHighlightArea(titikGempa,id) {

for (let index = 0; index < allPolygon.length; index++) {
const polygon = allPolygon[index];

for (let it = 0; it < titikGempa.length; it++) {
const tg = titikGempa[it];

Expand Down Expand Up @@ -127,9 +128,10 @@ function checkMultiHighlightArea(titikGempa,id) {

if(radius > 0){
var buffer = turf.buffer(turf.point(coordinate), radius, { units: 'meters' });

var intersection = turf.booleanIntersects(polygon, buffer);

//var intersection = turf.booleanPointInPolygon(turf.centroid(polygon), buffer);
var intersection = turf.booleanIntersects(polygon, buffer);
if (intersection) {
const item = highlightSelectedArea.find(e => e.properties.mhid === polygon.properties.mhid);
if(item){
Expand All @@ -138,13 +140,26 @@ function checkMultiHighlightArea(titikGempa,id) {
}
const at = tg.areaTerdampak.find(e => e.mhid === polygon.properties.mhid);
if(at) {
at.distance = turf.distance(turf.point(at.center),turf.point(coordinate));
at.color = "red";
at.hit = true;
}



}
// const distance = turf.distance(turf.centroid(polygon),turf.point(coordinate))
// if (distance < (radius/1000)) {
// const item = highlightSelectedArea.find(e => e.properties.mhid === polygon.properties.mhid);
// if(item){
// item.properties.color = "red";
// item.properties.hit = true;
// }
// const at = tg.areaTerdampak.find(e => e.mhid === polygon.properties.mhid);
// if(at) {
// at.distance = turf.distance(turf.point(at.center),turf.point(coordinate));
// at.color = "red";
// at.hit = true;

// }
// }
}


Expand Down

0 comments on commit ea34e03

Please sign in to comment.