@ -1,6 +1,11 @@
import { Polyline } from 'leaflet' ;
import { registerWithParent , buildOptions } from '../core/utils.js' ;
import { createChildRegisterHandler , type ChildEntry } from '../core/register.js' ;
import { registerWithParent , buildOptions , definePropAccessors } from '../core/utils.js' ;
import {
createChildRegisterHandler ,
type ChildEntry ,
LeafletRegisterEvent ,
} from '../core/register.js' ;
import { isPathStyleAttr , updatePathStyle } from '../core/path-style.js' ;
import type { PropDef , PropTypesFromTable } from '../types/props.js' ;
import type { LeafletLine } from './leaflet-line.js' ;
@ -21,35 +26,20 @@ export class LeafletPolyline extends TypedBase {
# obj? : Polyline ;
# observer? : MutationObserver ;
# children = new Map < HTMLElement , ChildEntry > ( ) ;
# childHandler ?: EventListener ;
# childHandler ? : ( e : LeafletRegisterEvent ) = > void ;
static get observedAttributes() {
return Object . values ( PROPS ) . map ( ( s ) = > s . attr ) ;
}
static {
for ( const [ name , spec ] of Object . entries ( PROPS ) ) {
Object . defineProperty ( LeafletPolyline . prototype , name , {
get ( this : LeafletPolyline ) {
const val = this . getAttribute ( spec . attr ) ;
if ( spec . kind === 'num' ) return val !== null ? Number ( val ) : spec . default ;
if ( spec . kind === 'bool-on' ) return this . hasAttribute ( spec . attr ) ;
return val ? ? spec . default ;
} ,
set ( this : LeafletPolyline , v : number | string | boolean ) {
if ( spec . kind === 'bool-on' ) this . toggleAttribute ( spec . attr , ! ! v ) ;
else this . setAttribute ( spec . attr , String ( v ) ) ;
} ,
configurable : true ,
enumerable : true ,
} ) ;
}
definePropAccessors ( LeafletPolyline . prototype , PROPS ) ;
}
connectedCallback() {
this . # obj = new Polyline ( this . # getCoords ( ) , buildOptions ( this , PROPS ) ) ;
this . # childHandler = createChildRegisterHandler ( this . # obj , this . # children ) as EventListener ;
this . addEventListener ( 'leaflet-register' , this . # childHandler ) ;
this . # childHandler = createChildRegisterHandler ( this . # obj , this . # children ) ;
this . addEventListener ( 'leaflet-register' , this . # childHandler as EventListener ) ;
registerWithParent ( this , this . # obj ) ;
this . addEventListener ( 'line-updated' , this . # syncCoords ) ;
@ -61,7 +51,8 @@ export class LeafletPolyline extends TypedBase {
this . # observer ? . disconnect ( ) ;
this . # observer = undefined ;
this . removeEventListener ( 'line-updated' , this . # syncCoords ) ;
if ( this . # childHandler ) this . removeEventListener ( 'leaflet-register' , this . # childHandler ) ;
if ( this . # childHandler )
this . removeEventListener ( 'leaflet-register' , this . # childHandler as EventListener ) ;
this . # children . clear ( ) ;
this . # obj ? . remove ( ) ;
this . # obj = undefined ;