Skip to content

Commit b3f0dcf

Browse files
committed
Parse draw features
1 parent 483a887 commit b3f0dcf

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

src/openlayers/js/openlayers.standalone.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/draw-control.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ let draw: Draw;
2525
let snap: Snap;
2626

2727
const source = new VectorSource({ wrapX: false });
28+
source.on("addfeature", (e) => {
29+
const features = source.getFeatures().map(f => featureToGeoJSON(f));
30+
console.log("draw features", features);
31+
})
2832
const modify = new Modify({ source: source });
2933
const vectorLayer = new VectorLayer({
3034
source: source,
@@ -96,8 +100,7 @@ class DrawControl extends Control {
96100
this.setProperties({ id: "draw", type: "DrawControl" });
97101
}
98102

99-
y(): void {
100-
// console.log("map", this.getMap());
103+
onAdd(): void {
101104
const map = this.getMap();
102105
map?.addLayer(vectorLayer);
103106
const select = createSelectElement();
@@ -116,7 +119,13 @@ class DrawControl extends Control {
116119
return snap;
117120
}
118121

119-
getGeoJSONFeatures(): any { }
122+
getGeoJSONFeatures(): any[] {
123+
return source.getFeatures().map(f => featureToGeoJSON(f));
124+
}
125+
126+
getLayer(): VectorLayer {
127+
return vectorLayer;
128+
}
120129
}
121130

122131
export { DrawControl };

srcjs/ipywidget-ts/map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class MapWidget {
9999

100100
const d = new DrawControl()
101101
this._map.addControl(d);
102-
d.y();
102+
d.onAdd();
103103

104104
for (const defaultControl of defaultControls)
105105
this._map.addControl(defaultControl);

0 commit comments

Comments
 (0)