Skip to content

Commit

Permalink
Add remove_feature and remove_features
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Oct 17, 2023
1 parent ab5b103 commit 7965da2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ An object with the layer api functions:
- `new_feature`: Object, the new feature object
- `add_features`: Function, add an array of new features, it takes one argument:
- `new_features`: Array, an array of features
- `remove_feature`: Function, remove a feature, it takes one argument:
- `id`: String, the id of an existing feature to be removed
- `remove_features`: Function, remove an array of features, it takes one argument:
- `ids`: Array, an array of features ids
- `get_features`: Function, get all the features of the layer, it takes no argument

Example in Python:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kaibu",
"version": "0.1.46",
"version": "0.1.47",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down
13 changes: 13 additions & 0 deletions src/components/layers/VectorLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,19 @@ export default {
const geojsonFeatures = format.readFeatures(geojson_data);
me.vector_source.addFeatures(geojsonFeatures);
},
remove_feature(id) {
const feature = me.vector_source.getFeatureById(id);
if (feature) me.vector_source.removeFeature(feature);
},
remove_features(ids) {
if (!Array.isArray(ids)) {
throw new Error("Please pass an id array");
}
for (let id of ids) {
const feature = me.vector_source.getFeatureById(id);
if (feature) me.vector_source.removeFeature(feature);
}
},
get_features(config) {
config = config || {};
if (config.decimals === undefined) config.decimals = 2;
Expand Down

0 comments on commit 7965da2

Please sign in to comment.