@@ -1398,6 +1398,12 @@ export var MapMLLayer = L.Layer.extend({
1398
1398
}
1399
1399
function _processContent ( content ) {
1400
1400
var mapml = this . responseXML || content ;
1401
+ var base = new URL (
1402
+ mapml . querySelector ( 'map-base' )
1403
+ ? mapml . querySelector ( 'map-base' ) . getAttribute ( 'href' )
1404
+ : mapml . baseURI || this . responseURL ,
1405
+ this . responseURL
1406
+ ) . href ;
1401
1407
if ( mapml . querySelector && mapml . querySelector ( 'map-feature' ) )
1402
1408
layer . _content = mapml ;
1403
1409
if ( ! this . responseXML && this . responseText )
@@ -1406,147 +1412,137 @@ export var MapMLLayer = L.Layer.extend({
1406
1412
layer . error = 'true' ;
1407
1413
throw new Error ( 'Error parsing content' ) ;
1408
1414
} else if ( this . readyState === this . DONE && mapml . querySelector ) {
1409
- // if everything is ok, continue with the processing
1410
- if (
1411
- this . readyState === this . DONE &&
1412
- mapml . querySelector &&
1413
- ! mapml . querySelector ( 'parsererror' )
1414
- ) {
1415
- setLayerTitle ( ) ;
1416
- var serverExtent = mapml . querySelectorAll ( 'map-extent' ) ,
1417
- projection ,
1418
- projectionMatch ,
1419
- serverMeta ;
1420
-
1421
- if ( ! serverExtent . length ) {
1422
- serverMeta = mapml . querySelector ( 'map-meta[name=projection]' ) ;
1423
- }
1415
+ setLayerTitle ( ) ;
1416
+ thinkOfAGoodName ( ) ;
1417
+ parseLicenseAndLegend ( ) ;
1418
+ setZoomInOrOutLinks ( ) ;
1419
+ resetTemplatedLayers ( ) ;
1420
+ processTiles ( ) ;
1421
+ M . _parseStylesheetAsHTML ( mapml , base , layer . _container ) ;
1422
+ getExtentLayerControls ( ) ;
1423
+ layer . _styles = getAlternateStyles ( ) ;
1424
+ layer . _validateExtent ( ) ;
1425
+ copyRemoteContentToShadowRoot ( ) ;
1426
+ // update controls if needed based on mapml-viewer controls/controlslist attribute
1427
+ if ( layer . _layerEl . parentElement ) {
1428
+ // if layer does not have a parent Element, do not need to set Controls
1429
+ layer . _layerEl . parentElement . _toggleControls ( ) ;
1430
+ }
1431
+ layer . fire ( 'extentload' , layer , false ) ;
1432
+ layer . _layerEl . dispatchEvent (
1433
+ new CustomEvent ( 'extentload' , { detail : layer , bubbles : true } )
1434
+ ) ;
1435
+ }
1436
+ // local functions
1437
+ function thinkOfAGoodName ( ) {
1438
+ var serverExtent = mapml . querySelectorAll ( 'map-extent' ) ,
1439
+ projection ,
1440
+ projectionMatch ,
1441
+ serverMeta ;
1424
1442
1425
- // check whether all map-extent elements have the same units
1426
- if ( serverExtent . length >= 1 ) {
1427
- for ( let i = 0 ; i < serverExtent . length ; i ++ ) {
1428
- if (
1429
- serverExtent [ i ] . tagName . toLowerCase ( ) === 'map-extent' &&
1430
- serverExtent [ i ] . hasAttribute ( 'units' )
1431
- ) {
1432
- projection = serverExtent [ i ] . getAttribute ( 'units' ) ;
1433
- }
1434
- projectionMatch =
1435
- projection && projection === layer . options . mapprojection ;
1436
- if ( ! projectionMatch ) {
1437
- break ;
1438
- }
1439
- }
1440
- } else if ( serverMeta ) {
1443
+ if ( ! serverExtent . length ) {
1444
+ serverMeta = mapml . querySelector ( 'map-meta[name=projection]' ) ;
1445
+ }
1446
+
1447
+ // check whether all map-extent elements have the same units
1448
+ if ( serverExtent . length >= 1 ) {
1449
+ for ( let i = 0 ; i < serverExtent . length ; i ++ ) {
1441
1450
if (
1442
- serverMeta . tagName . toLowerCase ( ) === 'map-meta ' &&
1443
- serverMeta . hasAttribute ( 'content ' )
1451
+ serverExtent [ i ] . tagName . toLowerCase ( ) === 'map-extent ' &&
1452
+ serverExtent [ i ] . hasAttribute ( 'units ' )
1444
1453
) {
1445
- projection = M . _metaContentToObject (
1446
- serverMeta . getAttribute ( 'content' )
1447
- ) . content ;
1448
- projectionMatch =
1449
- projection && projection === layer . options . mapprojection ;
1454
+ projection = serverExtent [ i ] . getAttribute ( 'units' ) ;
1455
+ }
1456
+ projectionMatch =
1457
+ projection && projection === layer . options . mapprojection ;
1458
+ if ( ! projectionMatch ) {
1459
+ break ;
1450
1460
}
1451
- } else {
1452
- // default projection set to parent projection when no map-meta projection element present
1453
- projection = layer . options . mapprojection ;
1454
- projectionMatch = true ;
1455
- serverMeta = projection ;
1456
- console . log (
1457
- `A projection was not assigned to the '${ layer . _title } ' Layer. Please specify a projection for that layer using a map-meta element. See more here - https://maps4html.org/web-map-doc/docs/elements/meta/`
1458
- ) ;
1459
- // TODO: Add a more obvious warning.
1460
1461
}
1461
-
1462
- var metaExtent = mapml . querySelector ( 'map-meta[name=extent]' ) ,
1463
- selectedAlternate =
1464
- ! projectionMatch &&
1465
- mapml . querySelector (
1466
- 'map-head map-link[rel=alternate][projection=' +
1467
- layer . options . mapprojection +
1468
- ']'
1469
- ) ,
1470
- base = new URL (
1471
- mapml . querySelector ( 'map-base' )
1472
- ? mapml . querySelector ( 'map-base' ) . getAttribute ( 'href' )
1473
- : mapml . baseURI || this . responseURL ,
1474
- this . responseURL
1475
- ) . href ;
1476
-
1462
+ } else if ( serverMeta ) {
1477
1463
if (
1478
- ! projectionMatch &&
1479
- selectedAlternate &&
1480
- selectedAlternate . hasAttribute ( 'href' )
1464
+ serverMeta . tagName . toLowerCase ( ) === 'map-meta' &&
1465
+ serverMeta . hasAttribute ( 'content' )
1481
1466
) {
1482
- layer . fire (
1483
- 'changeprojection' ,
1484
- {
1485
- href : new URL ( selectedAlternate . getAttribute ( 'href' ) , base ) . href
1486
- } ,
1487
- false
1467
+ projection = M . _metaContentToObject (
1468
+ serverMeta . getAttribute ( 'content' )
1469
+ ) . content ;
1470
+ projectionMatch =
1471
+ projection && projection === layer . options . mapprojection ;
1472
+ }
1473
+ } else {
1474
+ // default projection set to parent projection when no map-meta projection element present
1475
+ projection = layer . options . mapprojection ;
1476
+ projectionMatch = true ;
1477
+ serverMeta = projection ;
1478
+ console . log (
1479
+ `A projection was not assigned to the '${ layer . _title } ' Layer. Please specify a projection for that layer using a map-meta element. See more here - https://maps4html.org/web-map-doc/docs/elements/meta/`
1480
+ ) ;
1481
+ // TODO: Add a more obvious warning.
1482
+ }
1483
+
1484
+ var metaExtent = mapml . querySelector ( 'map-meta[name=extent]' ) ,
1485
+ selectedAlternate =
1486
+ ! projectionMatch &&
1487
+ mapml . querySelector (
1488
+ 'map-head map-link[rel=alternate][projection=' +
1489
+ layer . options . mapprojection +
1490
+ ']'
1488
1491
) ;
1489
- return ;
1490
- } else if ( ! serverMeta ) {
1491
- layer . _extent = { } ;
1492
- if ( projectionMatch ) {
1493
- layer . _extent . crs = M [ projection ] ;
1494
- }
1495
- layer . _extent . _mapExtents = [ ] ; // stores all the map-extent elements in the layer
1496
- layer . _extent . _templateVars = [ ] ; // stores all template variables coming from all extents
1497
- for ( let j = 0 ; j < serverExtent . length ; j ++ ) {
1498
- if (
1499
- serverExtent [ j ] . querySelector (
1500
- 'map-link[rel=tile],map-link[rel=image],map-link[rel=features],map-link[rel=query]'
1501
- ) &&
1502
- serverExtent [ j ] . hasAttribute ( 'units' )
1503
- ) {
1504
- layer . _extent . _mapExtents . push ( serverExtent [ j ] ) ;
1505
- projectionMatch = projectionMatch || selectedAlternate ;
1506
- let templateVars = _initTemplateVars . call (
1507
- layer ,
1508
- serverExtent [ j ] ,
1509
- metaExtent ,
1510
- projection ,
1511
- mapml ,
1512
- base ,
1513
- projectionMatch
1514
- ) ;
1515
- layer . _extent . _mapExtents [ j ] . _templateVars = templateVars ;
1516
- layer . _extent . _templateVars =
1517
- layer . _extent . _templateVars . concat ( templateVars ) ;
1518
- }
1519
- }
1520
- } else {
1521
- if ( typeof serverMeta === 'string' ) {
1522
- // when map-meta projection not present for layer
1523
- layer . _extent = { serverMeta } ;
1524
- } else {
1525
- // when map-meta projection present for layer
1526
- layer . _extent = serverMeta ;
1492
+
1493
+ if (
1494
+ ! projectionMatch &&
1495
+ selectedAlternate &&
1496
+ selectedAlternate . hasAttribute ( 'href' )
1497
+ ) {
1498
+ layer . fire (
1499
+ 'changeprojection' ,
1500
+ {
1501
+ href : new URL ( selectedAlternate . getAttribute ( 'href' ) , base ) . href
1502
+ } ,
1503
+ false
1504
+ ) ;
1505
+ return ;
1506
+ } else if ( ! serverMeta ) {
1507
+ layer . _extent = { } ;
1508
+ if ( projectionMatch ) {
1509
+ layer . _extent . crs = M [ projection ] ;
1510
+ }
1511
+ layer . _extent . _mapExtents = [ ] ; // stores all the map-extent elements in the layer
1512
+ layer . _extent . _templateVars = [ ] ; // stores all template variables coming from all extents
1513
+ for ( let j = 0 ; j < serverExtent . length ; j ++ ) {
1514
+ if (
1515
+ serverExtent [ j ] . querySelector (
1516
+ 'map-link[rel=tile],map-link[rel=image],map-link[rel=features],map-link[rel=query]'
1517
+ ) &&
1518
+ serverExtent [ j ] . hasAttribute ( 'units' )
1519
+ ) {
1520
+ layer . _extent . _mapExtents . push ( serverExtent [ j ] ) ;
1521
+ projectionMatch = projectionMatch || selectedAlternate ;
1522
+ let templateVars = _initTemplateVars . call (
1523
+ layer ,
1524
+ serverExtent [ j ] ,
1525
+ metaExtent ,
1526
+ projection ,
1527
+ mapml ,
1528
+ base ,
1529
+ projectionMatch
1530
+ ) ;
1531
+ layer . _extent . _mapExtents [ j ] . _templateVars = templateVars ;
1532
+ layer . _extent . _templateVars =
1533
+ layer . _extent . _templateVars . concat ( templateVars ) ;
1527
1534
}
1528
1535
}
1529
- parseLicenseAndLegend ( ) ;
1530
- setZoomInOrOutLinks ( ) ;
1531
- resetTemplatedLayers ( ) ;
1532
- processTiles ( ) ;
1533
- M . _parseStylesheetAsHTML ( mapml , base , layer . _container ) ;
1534
- getExtentLayerControls ( ) ;
1535
- layer . _styles = getAlternateStyles ( ) ;
1536
- layer . _validateExtent ( ) ;
1537
- copyRemoteContentToShadowRoot ( ) ;
1538
- // update controls if needed based on mapml-viewer controls/controlslist attribute
1539
- if ( layer . _layerEl . parentElement ) {
1540
- // if layer does not have a parent Element, do not need to set Controls
1541
- layer . _layerEl . parentElement . _toggleControls ( ) ;
1536
+ } else {
1537
+ if ( typeof serverMeta === 'string' ) {
1538
+ // when map-meta projection not present for layer
1539
+ layer . _extent = { serverMeta } ;
1540
+ } else {
1541
+ // when map-meta projection present for layer
1542
+ layer . _extent = serverMeta ;
1542
1543
}
1543
1544
}
1544
- layer . fire ( 'extentload' , layer , false ) ;
1545
- layer . _layerEl . dispatchEvent (
1546
- new CustomEvent ( 'extentload' , { detail : layer , bubbles : true } )
1547
- ) ;
1548
1545
}
1549
- // local functions
1550
1546
function getExtentLayerControls ( ) {
1551
1547
// add multiple extents
1552
1548
if ( layer . _extent . _mapExtents ) {
0 commit comments