1
+ import { Util } from './mapml/utils/Util' ;
2
+
1
3
export class MapFeature extends HTMLElement {
2
4
static get observedAttributes ( ) {
3
5
return [ 'zoom' , 'min' , 'max' ] ;
@@ -10,7 +12,8 @@ export class MapFeature extends HTMLElement {
10
12
// for templated or queried features ** native zoom is only used for zoomTo() **
11
13
let meta = { } ,
12
14
metaEl = this . getMeta ( 'zoom' ) ;
13
- if ( metaEl ) meta = M . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
15
+ if ( metaEl )
16
+ meta = Util . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
14
17
if ( this . _parentEl . nodeName === 'MAP-LINK' ) {
15
18
// nativeZoom = zoom attribute || (sd.map-meta zoom 'value' || 'max') || this._initialZoom
16
19
return + ( this . hasAttribute ( 'zoom' )
@@ -43,7 +46,8 @@ export class MapFeature extends HTMLElement {
43
46
// for templated or queried features ** native zoom is only used for zoomTo() **
44
47
let meta = { } ,
45
48
metaEl = this . getMeta ( 'zoom' ) ;
46
- if ( metaEl ) meta = M . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
49
+ if ( metaEl )
50
+ meta = Util . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
47
51
let projectionMinZoom = 0 ;
48
52
if ( this . _parentEl . nodeName === 'MAP-LINK' ) {
49
53
// minZoom = min attribute || sd.map-meta min zoom || map-link minZoom
@@ -82,7 +86,8 @@ export class MapFeature extends HTMLElement {
82
86
// for templated or queried features ** native zoom is only used for zoomTo() **
83
87
let meta = { } ,
84
88
metaEl = this . getMeta ( 'zoom' ) ;
85
- if ( metaEl ) meta = M . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
89
+ if ( metaEl )
90
+ meta = Util . _metaContentToObject ( metaEl . getAttribute ( 'content' ) ) ;
86
91
let projectionMaxZoom =
87
92
this . getMapEl ( ) . _map . options . crs . options . resolutions . length - 1 ;
88
93
if ( this . _parentEl . nodeName === 'MAP-LINK' ) {
@@ -129,10 +134,10 @@ export class MapFeature extends HTMLElement {
129
134
}
130
135
}
131
136
getMapEl ( ) {
132
- return M . getClosest ( this , 'mapml-viewer,map[is=web-map]' ) ;
137
+ return Util . getClosest ( this , 'mapml-viewer,map[is=web-map]' ) ;
133
138
}
134
139
getLayerEl ( ) {
135
- return M . getClosest ( this , 'layer-' ) ;
140
+ return Util . getClosest ( this , 'layer-' ) ;
136
141
}
137
142
138
143
attributeChangedCallback ( name , oldValue , newValue ) {
@@ -231,7 +236,7 @@ export class MapFeature extends HTMLElement {
231
236
// layerToRemoveFrom is the L.LayerGroup or L.FeatureGroup to remove this
232
237
// feature from...
233
238
layerToRemoveFrom . removeLayer ( this . _geometry ) ;
234
- // TODO: MOVE THIS LOGIC TO layerToRemoveFrom.removeLayer(M. Geometry)
239
+ // TODO: MOVE THIS LOGIC TO layerToRemoveFrom.removeLayer(Geometry)
235
240
// if (layerToRemoveFrom._staticFeature) {
236
241
// if (layerToRemoveFrom._features[this.zoom]) {
237
242
// this._removeInFeatureList(this.zoom);
@@ -302,7 +307,7 @@ export class MapFeature extends HTMLElement {
302
307
// the fallback 'gcrs' SHOULD be specified by the MapML spec
303
308
// per https://github.com/Maps4HTML/MapML/issues/257
304
309
return csMeta
305
- ? M . _metaContentToObject ( csMeta . getAttribute ( 'content' ) ) . content
310
+ ? Util . _metaContentToObject ( csMeta . getAttribute ( 'content' ) ) . content
306
311
: 'gcrs' ;
307
312
}
308
313
@@ -341,7 +346,7 @@ export class MapFeature extends HTMLElement {
341
346
}
342
347
let topLeft = L . point ( bboxExtent [ 0 ] , bboxExtent [ 1 ] ) ;
343
348
let bottomRight = L . point ( bboxExtent [ 2 ] , bboxExtent [ 3 ] ) ;
344
- let pcrsBound = M . boundsToPCRSBounds (
349
+ let pcrsBound = Util . boundsToPCRSBounds (
345
350
L . bounds ( topLeft , bottomRight ) ,
346
351
zoom ,
347
352
map . options . projection ,
@@ -360,14 +365,14 @@ export class MapFeature extends HTMLElement {
360
365
pcrsBound . min ,
361
366
M [ projection ] . scale ( + this . zoom || maxZoom )
362
367
) ;
363
- pcrsBound = M . pixelToPCRSBounds (
368
+ pcrsBound = Util . pixelToPCRSBounds (
364
369
L . bounds ( pixel . subtract ( tileCenter ) , pixel . add ( tileCenter ) ) ,
365
370
this . zoom || maxZoom ,
366
371
projection
367
372
) ;
368
373
}
369
374
let result = Object . assign (
370
- M . _convertAndFormatPCRS (
375
+ Util . _convertAndFormatPCRS (
371
376
pcrsBound ,
372
377
map . options . crs ,
373
378
map . options . projection
@@ -389,14 +394,14 @@ export class MapFeature extends HTMLElement {
389
394
. split ( / [ < > \ ] / g) ;
390
395
switch ( shape . tagName . toUpperCase ( ) ) {
391
396
case 'MAP-POINT' :
392
- bboxExtent = M . _updateExtent ( bboxExtent , + data [ 0 ] , + data [ 1 ] ) ;
397
+ bboxExtent = Util . _updateExtent ( bboxExtent , + data [ 0 ] , + data [ 1 ] ) ;
393
398
break ;
394
399
case 'MAP-LINESTRING' :
395
400
case 'MAP-POLYGON' :
396
401
case 'MAP-MULTIPOINT' :
397
402
case 'MAP-MULTILINESTRING' :
398
403
for ( let i = 0 ; i < data . length ; i += 2 ) {
399
- bboxExtent = M . _updateExtent ( bboxExtent , + data [ i ] , + data [ i + 1 ] ) ;
404
+ bboxExtent = Util . _updateExtent ( bboxExtent , + data [ i ] , + data [ i + 1 ] ) ;
400
405
}
401
406
break ;
402
407
default :
@@ -433,7 +438,7 @@ export class MapFeature extends HTMLElement {
433
438
newZoom = this . zoom ;
434
439
} else {
435
440
// if not, calculate the maximum zoom level that can show the feature completely
436
- newZoom = M . getMaxZoom ( bound , this . getMapEl ( ) . _map , minZoom , maxZoom ) ;
441
+ newZoom = Util . getMaxZoom ( bound , this . getMapEl ( ) . _map , minZoom , maxZoom ) ;
437
442
if ( this . max < newZoom ) {
438
443
// if the calculated zoom is greater than the value of max zoom attribute, go with max zoom attribute
439
444
newZoom = this . max ;
@@ -495,7 +500,7 @@ export class MapFeature extends HTMLElement {
495
500
} else if ( el . querySelector ( 'table' ) ) {
496
501
// setting properties when table presented
497
502
let table = el . querySelector ( 'table' ) . cloneNode ( true ) ;
498
- json . properties = M . _table2properties ( table ) ;
503
+ json . properties = Util . _table2properties ( table ) ;
499
504
} else {
500
505
// when no table present, strip any possible html tags to only get text
501
506
json . properties = {
@@ -530,11 +535,11 @@ export class MapFeature extends HTMLElement {
530
535
json . geometry . geometries = [ ] ;
531
536
for ( let shape of shapes ) {
532
537
json . geometry . geometries . push (
533
- M . _geometry2geojson ( shape , source , dest , options . transform )
538
+ Util . _geometry2geojson ( shape , source , dest , options . transform )
534
539
) ;
535
540
}
536
541
} else {
537
- json . geometry = M . _geometry2geojson (
542
+ json . geometry = Util . _geometry2geojson (
538
543
shapes [ 0 ] ,
539
544
source ,
540
545
dest ,
0 commit comments