Skip to content

Commit

Permalink
add iconConnected event key
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgryan committed Jul 11, 2024
1 parent e8059bf commit f46bae3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/geojson/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<l-geojson id="feature" geojson='{"type":"Feature","properties":{"name":"Coors Field","amenity":"Baseball Stadium","popupContent":"This is where the Rockies play!"},"geometry":{"type":"Point","coordinates":[-104.99404,39.75621]}}'></l-geojson>
</l-map>
<script>
document.getElementById("feature").addEventListener("map:addTo", (ev) => {
document.getElementById("feature").addEventListener("l:layer:connected", (ev) => {
console.log({ message: "Hello, World!", ev })
})
</script>
Expand Down
1 change: 1 addition & 0 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// NOTE: These event keys are part of the public API of leaflet-html
export const layerConnected = "l:layer:connected";
export const popupConnected = "l:popup:connected";
export const iconConnected = "l:icon:connected";
export const layerRemoved = "l:layer:removed";
3 changes: 2 additions & 1 deletion src/l-icon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { icon } from "leaflet";
import { iconConnected } from "./events.js";
import {
bool,
chain,
Expand Down Expand Up @@ -53,7 +54,7 @@ class LIcon extends HTMLElement {

this.icon = icon(options);

const event = new CustomEvent("icon:add", {
const event = new CustomEvent(iconConnected, {
cancelable: true,
bubbles: true,
detail: {
Expand Down
3 changes: 2 additions & 1 deletion src/l-icon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { it, expect } from "vitest";
import * as L from "leaflet";
import "./index.js";
import { iconConnected } from "./events.js";

it("default", () => {
const el = document.createElement("l-icon");
Expand All @@ -15,7 +16,7 @@ it("default", () => {
it("emits icon:add event", async () => {
const el = document.createElement("l-icon");
let promise = new Promise((resolve) => {
el.addEventListener("icon:add", (ev) => {
el.addEventListener(iconConnected, (ev) => {
resolve(ev.detail.icon);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/l-marker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as L from "leaflet";
import { layerConnected, popupConnected } from "./events.js";
import { layerConnected, popupConnected, iconConnected } from "./events.js";
import LLayer from "./l-layer.js";
import {
chain,
Expand All @@ -19,7 +19,7 @@ class LMarker extends LLayer {
constructor() {
super();
this.layer = null;
this.addEventListener("icon:add", (ev) => {
this.addEventListener(iconConnected, (ev) => {
ev.stopPropagation();
this.layer.setIcon(ev.detail.icon);
});
Expand Down

0 comments on commit f46bae3

Please sign in to comment.