Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/my-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export class MyMap extends LitElement {
@property({ type: Boolean })
drawMode = false;

@property({ type: Object })
drawGeojsonData = {
type: "Feature",
geometry: {},
};

@property({ type: Number })
drawGeojsonDataBuffer = 100;

@property({ type: Boolean })
showFeaturesAtPoint = false;

Expand Down Expand Up @@ -254,11 +263,24 @@ export class MyMap extends LitElement {
}

if (this.drawMode) {
// ensure we start from an empty array of features
drawingSource.clear();
// check if single polygon feature was provided to load as the initial drawing
const loadInitialDrawing = Object.keys(this.drawGeojsonData.geometry).length > 0;
if (loadInitialDrawing) {
let feature = new GeoJSON().readFeature(this.drawGeojsonData, {
featureProjection: "EPSG:3857",
});
drawingSource.addFeature(feature);
// fit map to extent of intial feature, overriding zoom & lat/lng center
fitToData(map, drawingSource, this.drawGeojsonDataBuffer);
} else {
drawingSource.clear();
}

map.addLayer(drawingLayer);

map.addInteraction(draw);
if (!loadInitialDrawing) {
map.addInteraction(draw);
}
map.addInteraction(snap);
map.addInteraction(modify);

Expand Down