Skip to content

Commit e3ea2f1

Browse files
committed
Add skeleton for box selection
1 parent c517ff2 commit e3ea2f1

4 files changed

Lines changed: 134 additions & 47 deletions

File tree

marimo/box-selection.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
3+
import marimo
4+
5+
__generated_with = "0.13.2"
6+
app = marimo.App(width="medium")
7+
8+
9+
@app.cell
10+
def _():
11+
import openlayers as ol
12+
import marimo as mo
13+
return mo, ol
14+
15+
16+
@app.cell
17+
def _(ol):
18+
layer = ol.VectorLayer(
19+
source=ol.sources.VectorSource(
20+
url="https://openlayers.org/data/vector/ecoregions.json"
21+
)
22+
)
23+
return (layer,)
24+
25+
26+
@app.cell
27+
def _(layer, ol):
28+
m = ol.MapWidget(layers=[layer])
29+
return (m,)
30+
31+
32+
@app.cell
33+
def _(m, mo):
34+
w = mo.ui.anywidget(m)
35+
return (w,)
36+
37+
38+
@app.cell
39+
def _(w):
40+
w
41+
return
42+
43+
44+
@app.cell
45+
def _(w):
46+
w.value["view_state"]
47+
return
48+
49+
50+
@app.cell
51+
def _(m):
52+
m.add_call("addBoxSelection")
53+
return
54+
55+
56+
@app.cell
57+
def _():
58+
return
59+
60+
61+
if __name__ == "__main__":
62+
app.run()

src/openlayers/js/openlayers.anywidget.js

Lines changed: 45 additions & 45 deletions
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { parseClickEvent } from "./utils";
1616
import { featureToGeoJSON } from "./utils";
1717
import { addTooltipToMap } from "./tooltip";
1818
import { addEventListernersToMapWidget } from "./events";
19-
import { addSelectFeaturesToMap } from "./select-features";
19+
import { addSelectFeaturesToMap, addBoxSelectionToMap } from "./select-features";
2020
import { addDragAndDropToMap as addDragAndDropVectorLayersToMap } from "./drag-and-drop";
2121

2222
// --- Types
@@ -258,6 +258,10 @@ export default class MapWidget {
258258
addSelectFeaturesToMap(this._map, this._model);
259259
}
260260

261+
addBoxSelection(): void {
262+
addBoxSelectionToMap(this._map, this._model);
263+
}
264+
261265
addClickInteraction(): void {
262266
const model = this._model;
263267
this._map.on("click", (e) => {

srcjs/ipywidget-ts/select-features.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import Fill from 'ol/style/Fill.js';
77
import Stroke from 'ol/style/Stroke.js';
88
import VectorLayer from "ol/layer/Vector";
99

10+
// Box selection
11+
import { platformModifierKeyOnly } from 'ol/events/condition.js';
12+
1013
import { featureToGeoJSON } from "./utils";
14+
import DragBox from 'ol/interaction/DragBox.js';
1115

1216
// TODO: Should be a parameter
1317
const highlightStyle = new Style({
@@ -58,4 +62,21 @@ function addSelectFeaturesToMap(map: Map, model?: AnyModel): void {
5862
});
5963
}
6064

61-
export { addSelectFeaturesToMap };
65+
function addBoxSelectionToMap(map: Map, model?: AnyModel): void {
66+
console.warn("Box selection not implemented yet");
67+
68+
const dragBox = new DragBox({
69+
condition: platformModifierKeyOnly,
70+
});
71+
map.addInteraction(dragBox);
72+
dragBox.on('boxend', function () {
73+
const extent = dragBox.getGeometry().getExtent();
74+
console.log("box extent", extent);
75+
});
76+
77+
dragBox.on('boxstart', function () {
78+
// select.clearSelection();
79+
});
80+
}
81+
82+
export { addSelectFeaturesToMap, addBoxSelectionToMap };

0 commit comments

Comments
 (0)