Skip to content

Commit 5263755

Browse files
author
Stefan Kuethe
committed
Return feature objects
1 parent 499b029 commit 5263755

File tree

8 files changed

+222
-157
lines changed

8 files changed

+222
-157
lines changed

notebooks/modify-interaction.ipynb

Lines changed: 182 additions & 121 deletions
Large diffs are not rendered by default.

src/openlayers/anywidget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class MapWidget(Map, AnyWidget):
3030
metadata = traitlets.Dict().tag(sync=True)
3131

3232
# TODO: Move to features as well
33-
features_selected = traitlets.List().tag(sync=True)
33+
# features_selected = traitlets.List().tag(sync=True)
34+
3435
features = traitlets.Dict().tag(sync=True)
3536

3637
def __init__(

src/openlayers/js/openlayers.anywidget.js

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

src/openlayers/js/openlayers.standalone.js

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

srcjs/ipywidget-ts/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DrawControl } from "./custom-controls/draw";
22

3-
import MapWidget from "./map";
3+
import type MapWidget from "./map";
44

55
function filter(obj: any): any {
66
let objFiltered: any = {}

srcjs/ipywidget-ts/map.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class MapWidget {
7070
_container: HTMLElement;
7171
_map: Map;
7272
_metadata: Metadata = { layers: [], controls: [] };
73-
_features: Features = {};
73+
// _features: Features = {};
7474
_model: AnyModel | undefined;
7575

7676
constructor(mapElement: HTMLElement, mapOptions: MyMapOptions, model?: AnyModel | undefined) {
@@ -279,8 +279,9 @@ export default class MapWidget {
279279
const feature = featureToGeoJSON(e.feature);
280280
console.log("feature changed", feature);
281281
if (this._model) {
282-
this._features[layerId] = [feature];
283-
this._model.set("features", this._features);
282+
// this._features[layerId] = [feature];
283+
// this._model.set("features", this._features);
284+
this._model.set("features", { [layerId]: [feature] });
284285
this._model.save_changes();
285286
}
286287
}

srcjs/ipywidget-ts/select-features.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function addSelectFeaturesToMap(map: Map, model?: AnyModel): void {
3333

3434
// console.log("isVectorLayer", isVectorLayer);
3535
const f = feature as Feature;
36+
f.set("layer", layer.get("id"));
3637
const selIndex = selected.indexOf(f);
3738
if (selIndex < 0) {
3839
console.log("push");
@@ -49,7 +50,8 @@ function addSelectFeaturesToMap(map: Map, model?: AnyModel): void {
4950
const output = selected.map(f => featureToGeoJSON(f));
5051
// console.log("model", model);
5152
if (model) {
52-
model.set("features_selected", output);
53+
// model.set("features_selected", output);
54+
model.set("features", { selected: output });
5355
model.save_changes();
5456
} else
5557
console.log(output);

srcjs/ipywidget-ts/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getFeatureProperties(feature: FeatureLike): FeatureProps {
3636
}
3737

3838
function featureToGeoJSON(feature: Feature): any {
39-
return new GeoJSON().writeFeature(feature);
39+
return new GeoJSON().writeFeatureObject(feature);
4040
}
4141

4242
export { parseClickEvent, getFeatureProperties, parseView, featureToGeoJSON }

0 commit comments

Comments
 (0)