Skip to content

Commit

Permalink
feat: add resetViewOnly prop to retain data but still reset map pos…
Browse files Browse the repository at this point in the history
…ition (#496)
  • Loading branch information
jessicamcinchak authored Sep 6, 2024
1 parent f1d0421 commit a313267
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/my-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export class MyMap extends LitElement {
@property({ type: Boolean })
hideResetControl = false;

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

@property({ type: String })
resetControlImage: ResetControlImageEnum = "unicode";

Expand Down Expand Up @@ -383,18 +386,22 @@ export class MyMap extends LitElement {
const draw = configureDraw(this.drawType, this.drawPointer, this.drawColor);
const modify = configureModify(this.drawPointer, this.drawColor);

// add a custom 'reset' control to the map
// Add a custom 'reset' control to the map
const handleReset = () => {
// Reset the view port of the map based on available data or center/zoom by default
if (this.showFeaturesAtPoint) {
fitToData(map, outlineSource, this.featureBuffer);
} else if (geojsonSource.getFeatures().length > 0) {
fitToData(map, geojsonSource, this.geojsonBuffer);
} else if (this.resetViewOnly && drawingSource.getFeatures().length > 0) {
fitToData(map, drawingSource, this.drawGeojsonDataBuffer);
} else {
map.getView().setCenter(centerCoordinate);
map.getView().setZoom(this.zoom);
}

if (this.drawMode) {
// If in drawMode, also clear features from the drawingSource by default
if (this.drawMode && !this.resetViewOnly) {
drawingSource.clear();
this.dispatch("geojsonChange", {});
map.addInteraction(draw);
Expand Down

0 comments on commit a313267

Please sign in to comment.