Skip to content

Commit aba7c1e

Browse files
committed
Select layers for box selection
1 parent dfce8dc commit aba7c1e

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/openlayers/js/openlayers.anywidget.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/ipywidget-ts/map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ export default class MapWidget {
258258
addSelectFeaturesToMap(this._map, this._model);
259259
}
260260

261-
addBoxSelection(): void {
262-
addBoxSelectionToMap(this._map, this._model);
261+
addBoxSelection(layerIds?: string[]): void {
262+
addBoxSelectionToMap(this._map, layerIds, this._model);
263263
}
264264

265265
addClickInteraction(): void {

srcjs/ipywidget-ts/select-features.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,24 @@ function addSelectFeaturesToMap(map: Map, model?: AnyModel): void {
7373
});
7474
}
7575

76-
function addBoxSelectionToMap(map: Map, model?: AnyModel): void {
76+
function addBoxSelectionToMap(map: Map, layerIds?: string[], model?: AnyModel): void {
7777
console.warn("Box selection is still experimental.");
7878

79-
let selected = [] as Feature[];
79+
let layers = map.getLayers().getArray();
80+
if (layerIds) {
81+
layers = layers.filter(layer => layerIds.includes(layer.get("id")));
82+
}
8083

84+
let selected = [] as Feature[];
8185
const dragBox = new DragBox({
8286
condition: platformModifierKeyOnly,
8387
});
88+
8489
map.addInteraction(dragBox);
8590
dragBox.on('boxend', function () {
8691
const extent = dragBox.getGeometry().transform('EPSG:3857', 'EPSG:4326').getExtent();
8792
console.log("box extent", extent);
88-
for (let layer of map.getLayers().getArray()) {
93+
for (let layer of layers) {
8994
if (!(layer instanceof VectorLayer) && !(layer instanceof WebGLVectorLayer)) {
9095
console.log("skip layer", layer.get("id"));
9196
continue;

0 commit comments

Comments
 (0)