Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 24 additions & 7 deletions src/components/my-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Vector as VectorLayer } from "ol/layer";
import Map from "ol/Map";
import { fromLonLat, transformExtent } from "ol/proj";
import { Vector as VectorSource } from "ol/source";
import { Circle, Fill, Stroke, Style } from "ol/style";
import { Circle, Fill, Stroke, Style, Icon } from "ol/style";
import View from "ol/View";
import { last } from "rambda";

Expand All @@ -35,6 +35,9 @@ import {
} from "./snapping";
import { AreaUnitEnum, fitToData, formatArea, hexToRgba } from "./utils";
import styles from "./styles.scss";
import pinUrl from "./pin.svg";

type MarkerImageEnum = "circle" | "pin";

@customElement("my-map")
export class MyMap extends LitElement {
Expand Down Expand Up @@ -147,6 +150,9 @@ export class MyMap extends LitElement {
@property({ type: Boolean })
useScaleBarStyle = false;

@property({ type: String })
markerImage: MarkerImageEnum = "circle";

// set class property (map doesn't require any reactivity using @state)
map?: Map;

Expand Down Expand Up @@ -448,6 +454,22 @@ export class MyMap extends LitElement {
});
}

const markerCircle = new Circle({
radius: 9,
fill: new Fill({ color: this.markerColor }),
});

const markerPin = new Icon({ src: pinUrl });

const markerImage = () => {
switch (this.markerImage) {
case "circle":
return markerCircle;
case "pin":
return markerPin;
}
};

// show a marker at a point
if (this.showMarker) {
const markerPoint = new Point(
Expand All @@ -457,12 +479,7 @@ export class MyMap extends LitElement {
source: new VectorSource({
features: [new Feature(markerPoint)],
}),
style: new Style({
image: new Circle({
radius: 9,
fill: new Fill({ color: this.markerColor }),
}),
}),
style: new Style({ image: markerImage() }),
});

map.addLayer(markerLayer);
Expand Down
3 changes: 3 additions & 0 deletions src/components/my-map/pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.