Skip to content

Commit

Permalink
use custommarkeroptions in createLeafletMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddy Järvå authored and freddyJarva committed Apr 4, 2021
1 parent 93f3682 commit 3ef4bc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/map/Leaflet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import * as L from "leaflet";
import { imageHeight, mapUnit } from "./mapcontent";
import { CustomMarker } from "./markers";
import type { InteractiveMarker, MarkerData } from "./markers";
import type {
CustomMarkerOptions,
InteractiveMarker,
MarkerData,
} from "./markers";
import "leaflet/dist/leaflet.css";
import EntranceMarkerPopup from "./EntranceMarkerPopup.svelte";
Expand Down Expand Up @@ -33,8 +37,6 @@
inactive: L.LayerGroup;
};
function addToLayerGroup(layer: L.Layer, groupName: string) {}
let coordinateToMarkers: Map<string, InteractiveMarker> = new Map();
let markerGroups: {
entrance: Array<InteractiveMarker>;
Expand Down Expand Up @@ -111,17 +113,22 @@
eventHandlers: Array<{
eventType: string;
fn: L.LeafletEventHandlerFn;
}> = []
}> = [],
className?: string
) {
let latLng = toLatLng(marker.xy);
let positionedMarker = L.latLng(latLng[0], latLng[1]);
let leafletMarker = new CustomMarker(positionedMarker, {
// Option creation
let options: CustomMarkerOptions = {
icon: iconFor(marker),
className: "marker-inactive",
});
// let leafletMarker = L.marker(positionedMarker, {
// icon: iconFor(marker),
// });
};
if (className) {
options.className = className;
}
let leafletMarker = new CustomMarker(positionedMarker, options);
eventHandlers.forEach((e) => {
leafletMarker.on(e.eventType, e.fn);
});
Expand Down
4 changes: 2 additions & 2 deletions src/map/markers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import L, { LatLngExpression } from "leaflet";
import type { Writable } from "svelte/store";

interface CustomMarkerOptions extends L.MarkerOptions {
className: string;
export interface CustomMarkerOptions extends L.MarkerOptions {
className?: string;
}
export class CustomMarker extends L.Marker {
options: CustomMarkerOptions;
Expand Down

0 comments on commit 3ef4bc0

Please sign in to comment.