Skip to content

Commit

Permalink
feat(demo): add external data remove button #39
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Dec 2, 2024
1 parent 34382c5 commit 41bb50a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<header>
<input id="custom-url" type="url" placeholder="GeoJSON source URL..." />
<button id="load-data">Load external data</button>
<button id="remove-data">Remove external data</button>
|
<input id="feature-id" type="text" value="us2000ahxc" />
<button id="select-feature">Select feature manually</button>
Expand Down Expand Up @@ -104,6 +105,7 @@
})

document.getElementById('load-data').addEventListener('click', loadData)
document.getElementById('remove-data').addEventListener('click', removeData)
document.getElementById('select-feature').addEventListener('click', selectFeature)
})

Expand Down Expand Up @@ -138,6 +140,18 @@
features: [...geojson.features, ...vidoGeojson.features]
})
}

const removeData = () => {
if(teritorioCluster.ticking)
return

const source = map.getSource('earthquakes')

source.setData({
type: 'FeatureCollection',
features: geojson.features
})
}

const markerRender = (element, feature, markerSize) => {
element.textContent = feature.properties?.mag
Expand Down
9 changes: 7 additions & 2 deletions src/teritorio-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,13 @@ export class TeritorioCluster extends EventTarget {
// Get cluster's leaves
if (feature.properties.cluster) {
const source = this.map.getSource(this.sourceId) as GeoJSONSource
const leaves = await source.getClusterLeaves(Number.parseInt(id), feature.properties.point_count, 0) as MapGeoJSONFeature[]
this.clusterLeaves.set(id, leaves)

Check failure on line 346 in src/teritorio-cluster.ts

View workflow job for this annotation

GitHub Actions / 🛠️ Setup Development Environment

Trailing spaces not allowed
try {
const leaves = await source.getClusterLeaves(Number.parseInt(id), feature.properties.point_count, 0) as MapGeoJSONFeature[]
this.clusterLeaves.set(id, leaves)
} catch(error) {

Check failure on line 350 in src/teritorio-cluster.ts

View workflow job for this annotation

GitHub Actions / 🛠️ Setup Development Environment

Closing curly brace appears on the same line as the subsequent block

Check failure on line 350 in src/teritorio-cluster.ts

View workflow job for this annotation

GitHub Actions / 🛠️ Setup Development Environment

Expected space(s) after "catch"
console.error(error)
}
}
}

Expand Down

0 comments on commit 41bb50a

Please sign in to comment.