diff --git a/docs/api.md b/docs/api.md index d76a8fa..b781a09 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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. diff --git a/src/components/ImageViewer.vue b/src/components/ImageViewer.vue index 7beb875..874503f 100644 --- a/src/components/ImageViewer.vue +++ b/src/components/ImageViewer.vue @@ -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({ @@ -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, diff --git a/src/components/layers/VectorLayer.vue b/src/components/layers/VectorLayer.vue index 5643990..c619995 100644 --- a/src/components/layers/VectorLayer.vue +++ b/src/components/layers/VectorLayer.vue @@ -867,7 +867,6 @@ export default { }); return routeFeatures; }, - get_selected_features(config) { config = config || {}; if (config.decimals === undefined) config.decimals = 2; diff --git a/src/imjoyAPI.js b/src/imjoyAPI.js index 2269e67..c491435 100644 --- a/src/imjoyAPI.js +++ b/src/imjoyAPI.js @@ -53,6 +53,8 @@ function toArray(data) { export async function setupImJoyAPI({ addLayer, + getLayer, + getLayerIds, selectLayer, removeLayer, clearLayers, @@ -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,