Skip to content

Commit

Permalink
refactor: changed name for getStartPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin committed Mar 6, 2025
1 parent d3b1a09 commit ff61a0e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
28 changes: 27 additions & 1 deletion source/js/options/startPosition/optionSetStartPosition.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { MapInterface, CreateMarkerInterface, MarkerInterface, LatLngObject } from "@helsingborg-stad/openstreetmap";
import { OptionSetStartPositionInterface } from "./optionSetStartPositionInterface";
import { OptionFeature } from "../optionFeature";
import { createListItem } from "../../helper/createListItem";

class OptionSetStartPosition implements OptionFeature, OptionSetStartPositionInterface {
protected condition: string = 'set_start_position';
private markerCssClass: string = 'marker-start-position';
private marker: undefined|MarkerInterface;
private list: HTMLUListElement|null;

constructor(
private mapInstance: MapInterface,
private container: HTMLElement,
private zoomInstance: Setting,
private handleSelectedInstance: HandleSelectedInterface,
private createMarkerInstance: CreateMarkerInterface
) {
this.list = this.container.querySelector('[data-js-start-position-list]');

this.mapInstance.addListener('click', (e) => {
if (
this.handleSelectedInstance.getCurrentSelectedValue() !== this.condition ||
Expand All @@ -29,16 +35,36 @@ class OptionSetStartPosition implements OptionFeature, OptionSetStartPositionInt
}

public addMarker(latlng: LatLngObject): void {
if (this.marker) {
return;
}

this.marker = this.createMarkerInstance.create({
position: latlng,
icon: this.getMarkerMarkup(),
draggable: true,
});

this.addListItem();
this.marker.addTo(this.mapInstance);
}

public getStartPosition(): MarkerInterface|undefined {
private addListItem(): void {
if (!this.list) {
return;
}

const listItem = createListItem('Start position');
this.list.appendChild(listItem);

listItem.addEventListener('click', () => {
if (this.marker) {
this.mapInstance.flyTo(this.marker.getPosition(), parseInt(this.zoomInstance.getValue()));
}
});
}

public getStartPositionMarker(): MarkerInterface|undefined {
return this.marker;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MapInterface, CreateMarkerInterface, MarkerInterface } from "@helsingborg-stad/openstreetmap";

interface OptionSetStartPositionInterface {
getStartPosition(): MarkerInterface|undefined;
getStartPositionMarker(): MarkerInterface|undefined;
addMarker(latlng: LatLngObject): void;
}
2 changes: 1 addition & 1 deletion source/js/options/startPosition/saveStartPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SaveStartPostion implements SaveOptionDataInterface {
constructor(private optionSetStartPositionInstance: OptionSetStartPositionInterface) {}

public save(): SavedStartPosition {
return this.optionSetStartPositionInstance.getStartPosition()?.getPosition() ?? null;
return this.optionSetStartPositionInstance.getStartPositionMarker()?.getPosition() ?? null;
}
}

Expand Down

0 comments on commit ff61a0e

Please sign in to comment.