@ -1,5 +1,5 @@
import { Marker } from 'leaflet' ;
import { Marker } from 'leaflet' ;
import { registerWithParent , buildOptions , parseAttributeValue } from '../core/utils.js' ;
import { registerWithParent , buildOptions , numAttr, parseAttributeValue } from '../core/utils.js' ;
import { withProps } from '../core/with-props.js' ;
import { withProps } from '../core/with-props.js' ;
import {
import {
@ -31,7 +31,7 @@ export class LeafletMarker extends withProps(HTMLElement, PROPS) {
connectedCallback() {
connectedCallback() {
this . # obj = new Marker (
this . # obj = new Marker (
[ this . # num ( 'lat' ) , this . # num ( 'lng' ) ] ,
[ numAttr ( this , PROPS , 'lat' ) , numAttr ( this , PROPS , 'lng' ) ] ,
buildOptions ( this , PROPS , [ 'lat' , 'lng' ] ) ,
buildOptions ( this , PROPS , [ 'lat' , 'lng' ] ) ,
) ;
) ;
this . # obj . on ( 'dragend' , this . # onDragEnd ) ;
this . # obj . on ( 'dragend' , this . # onDragEnd ) ;
@ -51,7 +51,7 @@ export class LeafletMarker extends withProps(HTMLElement, PROPS) {
attributeChangedCallback ( name : string , _old : string | null , val : string | null ) {
attributeChangedCallback ( name : string , _old : string | null , val : string | null ) {
if ( ! this . # obj || this . # syncing ) return ;
if ( ! this . # obj || this . # syncing ) return ;
if ( name === 'lat' || name === 'lng' ) {
if ( name === 'lat' || name === 'lng' ) {
this . # obj . setLatLng ( [ this . # num ( 'lat' ) , this . # num ( 'lng' ) ] ) ;
this . # obj . setLatLng ( [ numAttr ( this , PROPS , 'lat' ) , numAttr ( this , PROPS , 'lng' ) ] ) ;
} else if ( name === 'draggable' ) {
} else if ( name === 'draggable' ) {
if ( val !== null ) this . # obj . dragging ? . enable ( ) ;
if ( val !== null ) this . # obj . dragging ? . enable ( ) ;
else this . # obj . dragging ? . disable ( ) ;
else this . # obj . dragging ? . disable ( ) ;
@ -79,13 +79,6 @@ export class LeafletMarker extends withProps(HTMLElement, PROPS) {
this . setAttribute ( 'lng' , String ( pos . lng ) ) ;
this . setAttribute ( 'lng' , String ( pos . lng ) ) ;
this . # syncing = false ;
this . # syncing = false ;
} ;
} ;
# num ( name : string ) : number {
const v = this . getAttribute ( name ) ;
return v !== null
? Number ( v )
: ( PROPS [ name as keyof typeof PROPS ] as { default : number } ) . default ;
}
}
}
customElements . define ( 'leaflet-marker' , LeafletMarker ) ;
customElements . define ( 'leaflet-marker' , LeafletMarker ) ;