Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_layer and get_layer_ids API #94

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ class ImJoyPlugin():
api.export(ImJoyPlugin())
```

### get_layer_ids()

Get all the layer ids.

**Returns**
An array of layer ids.

### get_layer(key)

Get a layer by its id or name.

**Arguments**
- `key`: String, the id or name of the layer

**Returns**
The layer object corresponding to the id or name.
If the layer is not found, it will return `null`.

### add_widget(options)

Add a widget panel with buttons, file tree or graph.
Expand Down
14 changes: 14 additions & 0 deletions src/components/ImageViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,18 @@ export default {
config._add_layer_promise = { resolve, reject };
});
},
getLayer(key) {
for (let config of this.$store.state.layer_configs) {
// name or id
if (config.name === key || config.id === key) {
const layer = this.$store.state.layers[config.id];
return layer.getLayerAPI();
}
}
},
getLayerIds() {
return this.$store.state.layer_configs.map(config => config.id);
},
updateExtent(config) {
//TODO: calculate the extent for all layers
const projection = new Projection({
Expand Down Expand Up @@ -528,6 +540,8 @@ export default {
if (window.self !== window.top) {
setupImJoyAPI({
addLayer: this.addLayer,
getLayer: this.getLayer,
getLayerIds: this.getLayerIds,
selectLayer: this.selectLayer,
removeLayer: this.removeLayer,
clearLayers: this.clearLayers,
Expand Down
1 change: 0 additions & 1 deletion src/components/layers/VectorLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ export default {
});
return routeFeatures;
},

get_selected_features(config) {
config = config || {};
if (config.decimals === undefined) config.decimals = 2;
Expand Down
4 changes: 4 additions & 0 deletions src/imjoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function toArray(data) {

export async function setupImJoyAPI({
addLayer,
getLayer,
getLayerIds,
selectLayer,
removeLayer,
clearLayers,
Expand Down Expand Up @@ -103,6 +105,8 @@ export async function setupImJoyAPI({
}
},
add_layer: addLayer,
get_layer: getLayer,
get_layer_ids: getLayerIds,
select_layer: selectLayer,
remove_layer: removeLayer,
clear_layers: clearLayers,
Expand Down
Loading