Skip to content

Commit db12ea7

Browse files
author
Stefan Kuethe
committed
Refactor
1 parent 828630d commit db12ea7

File tree

5 files changed

+51
-78
lines changed

5 files changed

+51
-78
lines changed

examples/standalone/layers/geojson_vector_layer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
m.add_control(zoom_slider)
2121
m.add_layer(geojson_layer)
2222
m.add_tooltip()
23-
# m.add_control(ol.DrawControl())
23+
m.add_control(ol.DrawControl())
2424
# m.remove_control(zoom_slider.id)
2525
# m.add_call("addModifyInteraction", geojson_layer.id)
26-
m.add_modify_interaction(geojson_layer.id)
26+
# m.add_modify_interaction(geojson_layer.id)
2727
m.save("/tmp/ol-example.html")

src/openlayers/js/openlayers.standalone.js

Lines changed: 47 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/ipywidget-ts/custom-controls/draw.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ function createSelectElement(): HTMLSelectElement {
5959
}
6060

6161
function toggleDrawInteraction(map: Map, select: HTMLSelectElement): void {
62-
// let draw: Draw;
63-
// let snap: Snap;
64-
65-
// const modify = new Modify({ source: source });
6662
map.addInteraction(modify);
6763

6864
function addInteraction() {

srcjs/ipywidget-ts/layers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const drawSource = new VectorSource({ wrapX: false });
2626
const drawVectorLayer = new VectorLayer({
2727
source: drawSource
2828
});
29-
drawVectorLayer.set("id", "draw-features");
30-
drawVectorLayer.set("type", "VectorLayer");
29+
drawVectorLayer.setProperties({ id: "draw", type: "VectorLayer" });
3130

32-
export { layerCatalog, drawSource, drawVectorLayer };
31+
export { layerCatalog, drawVectorLayer };

srcjs/ipywidget-ts/map.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Map, View } from "ol";
22
// import { defaults as defaultControls } from 'ol/control/defaults.js';
33
import GeoJSON from "ol/format/GeoJSON";
44
import Overlay from "ol/Overlay";
5-
import Draw from 'ol/interaction/Draw.js';
65
import { useGeographic } from "ol/proj";
76
import { isEmpty } from "ol/extent";
87
import Modify from "ol/interaction/Modify";
@@ -19,9 +18,6 @@ import { addEventListernersToMapWidget } from "./events";
1918
import { addSelectFeaturesToMap } from "./select-features";
2019
import { addDragAndDropToMap as addDragAndDropVectorLayersToMap } from "./drag-and-drop";
2120

22-
// TODO: Remove draw from here
23-
import { drawSource, drawVectorLayer } from "./layers";
24-
2521
// --- Types
2622
import type Layer from "ol/layer/Layer";
2723
import type Control from "ol/control/Control";
@@ -33,7 +29,6 @@ import type { FlatStyle } from "ol/style/flat";
3329
import type { MyMapOptions } from ".";
3430

3531
import type { AnyModel } from "@anywidget/types";
36-
import type { Type as GeomType } from "ol/geom/Geometry";
3732

3833
type Metadata = {
3934
layers: any[];
@@ -69,7 +64,6 @@ export default class MapWidget {
6964
_container: HTMLElement;
7065
_map: Map;
7166
_metadata: Metadata = { layers: [], controls: [] };
72-
_draw: Draw | undefined;
7367
_model: AnyModel | undefined;
7468

7569
constructor(mapElement: HTMLElement, mapOptions: MyMapOptions, model?: AnyModel | undefined) {
@@ -272,20 +266,4 @@ export default class MapWidget {
272266
this._map.addInteraction(modify);
273267
}
274268
}
275-
276-
// See https://openlayers.org/en/latest/examples/draw-and-modify-features.html
277-
// TODO: Remove: Use DrawControl instead
278-
addDrawInteraction(type: GeomType): void {
279-
if (this._draw)
280-
this._map.removeInteraction(this._draw);
281-
else
282-
this._map.addLayer(drawVectorLayer);
283-
284-
this._draw = new Draw({
285-
source: drawSource,
286-
type: type
287-
});
288-
this._map.addInteraction(this._draw);
289-
console.log("draw interaction added", type);
290-
}
291269
}

0 commit comments

Comments
 (0)