Skip to content

Commit

Permalink
Show neighbouring properties as points on map
Browse files Browse the repository at this point in the history
Creates a property showNeighbourMark which when switched on creates
a marker for each point passed in on the geojsonData property.

This will be useful in BOPS as it can be difficult to know when drawing
a polygon whether you have selected the neighbouring properties. BOPS
will pass the coordinates of the neighbours via the geojsonData prop.
  • Loading branch information
cdccollins committed Jan 25, 2024
1 parent c237a53 commit 693bb73
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/components/my-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
hexToRgba,
makeGeoJSON,
} from "./utils";
import { GeoJSONFeatureCollection } from "ol/format/GeoJSON";

type MarkerImageEnum = "circle" | "pin";
type ResetControlImageEnum = "unicode" | "trash";
Expand Down Expand Up @@ -130,7 +131,10 @@ export class MyMap extends LitElement {
featureBuffer = 40;

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

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

@property({ type: String })
markerImage: MarkerImageEnum = "circle";
Expand Down Expand Up @@ -587,14 +591,9 @@ export class MyMap extends LitElement {
}
};

// show a marker at a point
if (this.showMarker) {
const showNewMarker = (lon: number, lat: number) => {
const markerPoint = new Point(
transform(
[this.markerLongitude, this.markerLatitude],
projection,
"EPSG:3857",
),
transform([lon, lat], projection, "EPSG:3857"),
);
const markerLayer = new VectorLayer({
source: new VectorSource({
Expand All @@ -604,6 +603,21 @@ export class MyMap extends LitElement {
});

map.addLayer(markerLayer);
};

// show a marker at a point
if (this.showCentreMarker) {
showNewMarker(this.markerLongitude, this.markerLatitude);
}

if (this.showGeojsonDataMarkers) {
this.geojsonData.features.forEach((feature: GeoJSONFeatureCollection) => {
console.log(feature.geometry.coordinates);
showNewMarker(
feature.geometry.coordinates[0],
feature.geometry.coordinates[1],
);
});
}

// XXX: force re-render for safari due to it thinking map is 0 height on load
Expand Down

0 comments on commit 693bb73

Please sign in to comment.