-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add observedAttributes to l-image-layer
- Loading branch information
1 parent
c77ad27
commit b0a7c0e
Showing
1 changed file
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
import { mapAddTo } from "./events.js" | ||
|
||
class LImageOverlay extends HTMLElement { | ||
static observedAttributes = ["url", "bounds", "opacity"] | ||
|
||
constructor() { | ||
super() | ||
this.layer = null | ||
} | ||
|
||
connectedCallback() { | ||
console.log("l-image-overlay connected") | ||
const url = this.getAttribute("url") | ||
const bounds = JSON.parse(this.getAttribute("bounds")) | ||
const options = { | ||
opacity: parseFloat(this.getAttribute("opacity") || "1.0"), | ||
alt: this.getAttribute("alt") || "" | ||
} | ||
const layer = L.imageOverlay(url, bounds, options) | ||
this.layer = L.imageOverlay(url, bounds, options) | ||
this.dispatchEvent(new CustomEvent(mapAddTo, { | ||
cancelable: true, | ||
bubbles: true, | ||
detail: { | ||
layer | ||
layer: this.layer | ||
} | ||
})) | ||
} | ||
|
||
attributeChangedCallback(name, _oldValue, newValue) { | ||
if (this.layer !== null) { | ||
if (name === "url") { | ||
this.layer.setUrl(newValue) | ||
} else if (name === "bounds") { | ||
this.layer.setBounds(JSON.parse(newValue)) | ||
} else if (name === "opacity") { | ||
this.layer.setOpacity(parseFloat(newValue)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default LImageOverlay |