@@ -481,66 +481,91 @@ export var MapMLLayer = L.Layer.extend({
481481 return this . options . attribution ;
482482 } ,
483483 getLayerUserControlsHTML : function ( ) {
484- var fieldset = document . createElement ( 'fieldset' ) ,
485- input = document . createElement ( 'input' ) ,
486- label = document . createElement ( 'label' ) ,
487- name = document . createElement ( 'span' ) ,
488- details = document . createElement ( 'details' ) ,
489- summary = document . createElement ( 'summary' ) ,
490- summaryContainer = document . createElement ( 'div' ) ,
491- opacity = document . createElement ( 'input' ) ,
492- opacityControl = document . createElement ( 'details' ) ,
493- opacityControlSummary = document . createElement ( 'summary' ) ,
494- opacityControlSummaryLabel = document . createElement ( 'label' ) ,
484+ var fieldset = L . DomUtil . create ( 'fieldset' , 'mapml-layer-item' ) ,
485+ input = L . DomUtil . create ( 'input' ) ,
486+ layerItemName = L . DomUtil . create ( 'span' , 'mapml-layer-item-name' ) ,
487+ settingsButtonNameIcon = L . DomUtil . create ( 'span' ) ,
488+ layerItemProperty = L . DomUtil . create ( 'div' , 'mapml-layer-item-properties' , fieldset ) ,
489+ layerItemSettings = L . DomUtil . create ( 'div' , 'mapml-layer-item-settings' , fieldset ) ,
490+ itemToggleLabel = L . DomUtil . create ( 'label' , 'mapml-layer-item-toggle' , layerItemProperty ) ,
491+ layerItemControls = L . DomUtil . create ( 'div' , 'mapml-layer-item-controls' , layerItemProperty ) ,
492+ opacityControl = L . DomUtil . create ( 'details' , 'mapml-layer-item-opacity' , layerItemSettings ) ,
493+ opacity = L . DomUtil . create ( 'input' ) ,
494+ opacityControlSummary = L . DomUtil . create ( 'summary' ) ,
495+ svgSettingsControlIcon = L . SVG . create ( 'svg' ) ,
496+ settingsControlPath1 = L . SVG . create ( 'path' ) ,
497+ settingsControlPath2 = L . SVG . create ( 'path' ) ,
495498 mapEl = this . _layerEl . parentNode ;
496499 this . opacityEl = opacity ;
500+
501+ // append the paths in svg for the remove layer and toggle icons
502+ svgSettingsControlIcon . setAttribute ( 'viewBox' , '0 0 24 24' ) ;
503+ svgSettingsControlIcon . setAttribute ( 'height' , '22' ) ;
504+ svgSettingsControlIcon . setAttribute ( 'width' , '22' ) ;
505+ settingsControlPath1 . setAttribute ( 'd' , 'M0 0h24v24H0z' ) ;
506+ settingsControlPath1 . setAttribute ( 'fill' , 'none' ) ;
507+ settingsControlPath2 . setAttribute ( 'd' , 'M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z' ) ;
508+ svgSettingsControlIcon . appendChild ( settingsControlPath1 ) ;
509+ svgSettingsControlIcon . appendChild ( settingsControlPath2 ) ;
497510
498- summaryContainer . classList . add ( 'mapml-control-summary-container' ) ;
511+ layerItemSettings . hidden = true ;
512+ settingsButtonNameIcon . setAttribute ( 'aria-hidden' , true ) ;
499513
500- let removeButton = document . createElement ( 'button' ) ;
501- removeButton . type = 'button' ;
502- removeButton . title = 'Remove Layer' ;
503- removeButton . innerHTML = "<span aria-hidden='true'>✖ ;</span>" ;
504- removeButton . classList . add ( 'mapml-layer-remove-button' , 'mapml-button' ) ;
505- L . DomEvent . disableClickPropagation ( removeButton ) ;
506- L . DomEvent . on ( removeButton , 'click' , L . DomEvent . stop ) ;
507- L . DomEvent . on ( removeButton , 'click' , ( e ) => {
514+ let removeControlButton = L . DomUtil . create ( 'button' , 'mapml-layer-item-remove-control' , layerItemControls ) ;
515+ removeControlButton . type = 'button' ;
516+ removeControlButton . title = 'Remove Layer' ;
517+ removeControlButton . innerHTML = "<span aria-hidden='true'>✕ ;</span>" ;
518+ removeControlButton . classList . add ( 'mapml-button' ) ;
519+ // L.DomEvent.disableClickPropagation(removeControlButton );
520+ L . DomEvent . on ( removeControlButton , 'click' , L . DomEvent . stop ) ;
521+ L . DomEvent . on ( removeControlButton , 'click' , ( e ) => {
508522 mapEl . removeChild ( e . target . closest ( "fieldset" ) . querySelector ( "span" ) . layer . _layerEl ) ;
509523 } , this ) ;
510524
525+ let itemSettingControlButton = L . DomUtil . create ( 'button' , 'mapml-layer-item-settings-control' , layerItemControls ) ;
526+ itemSettingControlButton . type = 'button' ;
527+ itemSettingControlButton . title = 'Layer Settings' ;
528+ itemSettingControlButton . setAttribute ( 'aria-expanded' , false ) ;
529+ itemSettingControlButton . classList . add ( 'mapml-button' ) ;
530+ L . DomEvent . on ( itemSettingControlButton , 'click' , ( e ) => {
531+ if ( layerItemSettings . hidden == true ) {
532+ itemSettingControlButton . setAttribute ( 'aria-expanded' , true ) ;
533+ layerItemSettings . hidden = false ;
534+ } else {
535+ itemSettingControlButton . setAttribute ( 'aria-expanded' , false ) ;
536+ layerItemSettings . hidden = true ;
537+ }
538+ } , this ) ;
539+
511540 input . defaultChecked = this . _map ? true : false ;
512541 input . type = 'checkbox' ;
513- input . className = 'leaflet-control-layers-selector' ;
514- name . layer = this ;
542+ layerItemName . layer = this ;
515543
516544 if ( this . _legendUrl ) {
517545 var legendLink = document . createElement ( 'a' ) ;
518546 legendLink . text = ' ' + this . _title ;
519547 legendLink . href = this . _legendUrl ;
520548 legendLink . target = '_blank' ;
521549 legendLink . draggable = false ;
522- name . appendChild ( legendLink ) ;
550+ layerItemName . appendChild ( legendLink ) ;
523551 } else {
524- name . innerHTML = ' ' + this . _title ;
552+ layerItemName . innerHTML = this . _title ;
525553 }
526- label . appendChild ( input ) ;
527- label . appendChild ( name ) ;
528- opacityControlSummaryLabel . innerText = 'Opacity' ;
529- opacity . id = "o" + L . stamp ( opacity ) ;
530- opacityControlSummaryLabel . setAttribute ( 'for' , opacity . id ) ;
531- opacityControlSummary . appendChild ( opacityControlSummaryLabel ) ;
554+ layerItemName . id = this . _title ;
555+ opacityControlSummary . innerText = 'Opacity' ;
556+ opacityControlSummary . id = 'mapml-layer-item-opacity-' + this . _title ;
532557 opacityControl . appendChild ( opacityControlSummary ) ;
533558 opacityControl . appendChild ( opacity ) ;
534- L . DomUtil . addClass ( details , 'mapml-control-layers' ) ;
535- L . DomUtil . addClass ( opacityControl , 'mapml-control-layers' ) ;
536559 opacity . setAttribute ( 'type' , 'range' ) ;
537560 opacity . setAttribute ( 'min' , '0' ) ;
538561 opacity . setAttribute ( 'max' , '1.0' ) ;
539562 opacity . setAttribute ( 'value' , this . _container . style . opacity || '1.0' ) ;
540563 opacity . setAttribute ( 'step' , '0.1' ) ;
564+ opacity . setAttribute ( 'aria-labelledby' , 'mapml-layer-item-opacity-' + this . _title ) ;
541565 opacity . value = this . _container . style . opacity || '1.0' ;
542566
543567 fieldset . setAttribute ( "aria-grabbed" , "false" ) ;
568+ fieldset . setAttribute ( 'aria-labelledby' , this . _title ) ;
544569
545570 fieldset . onmousedown = ( downEvent ) => {
546571 if ( downEvent . target . tagName . toLowerCase ( ) === "input" || downEvent . target . tagName . toLowerCase ( ) === "select" ) return ;
@@ -609,15 +634,13 @@ export var MapMLLayer = L.Layer.extend({
609634
610635 L . DomEvent . on ( opacity , 'change' , this . _changeOpacity , this ) ;
611636
612- fieldset . appendChild ( details ) ;
613- details . appendChild ( summary ) ;
614- summaryContainer . appendChild ( label ) ;
615- summaryContainer . appendChild ( removeButton ) ;
616- summary . appendChild ( summaryContainer ) ;
617- details . appendChild ( opacityControl ) ;
637+ itemToggleLabel . appendChild ( input ) ;
638+ itemToggleLabel . appendChild ( layerItemName ) ;
639+ itemSettingControlButton . appendChild ( settingsButtonNameIcon ) ;
640+ settingsButtonNameIcon . appendChild ( svgSettingsControlIcon ) ;
618641
619642 if ( this . _styles ) {
620- details . appendChild ( this . _styles ) ;
643+ layerItemSettings . appendChild ( this . _styles ) ;
621644 }
622645 if ( this . _userInputs ) {
623646 var frag = document . createDocumentFragment ( ) ;
@@ -631,21 +654,19 @@ export var MapMLLayer = L.Layer.extend({
631654 // don't add it again if it is referenced > once
632655 if ( mapmlInput . tagName . toLowerCase ( ) === 'map-select' && ! frag . querySelector ( id ) ) {
633656 // generate a <details><summary></summary><select...></details>
634- var selectdetails = document . createElement ( 'details' ) ,
635- selectsummary = document . createElement ( 'summary' ) ,
636- selectSummaryLabel = document . createElement ( 'label' ) ;
657+ var selectdetails = L . DomUtil . create ( 'details' , 'mapml-control-layers' , frag ) ,
658+ selectsummary = L . DomUtil . create ( 'summary' ) ,
659+ selectSummaryLabel = L . DomUtil . create ( 'label' ) ;
637660 selectSummaryLabel . innerText = mapmlInput . getAttribute ( 'name' ) ;
638661 selectSummaryLabel . setAttribute ( 'for' , mapmlInput . getAttribute ( 'id' ) ) ;
639- L . DomUtil . addClass ( selectdetails , 'mapml-control-layers' ) ;
640662 selectsummary . appendChild ( selectSummaryLabel ) ;
641663 selectdetails . appendChild ( selectsummary ) ;
642664 selectdetails . appendChild ( mapmlInput . htmlselect ) ;
643- frag . appendChild ( selectdetails ) ;
644665 }
645666 }
646667 }
647668 }
648- details . appendChild ( frag ) ;
669+ layerItemSettings . appendChild ( frag ) ;
649670 }
650671 return fieldset ;
651672 } ,
0 commit comments