@@ -7,10 +7,11 @@ export var FeatureIndex = L.Layer.extend({
7
7
8
8
this . _output = L . DomUtil . create ( "output" , "mapml-feature-index" , map . _container ) ;
9
9
this . _body = L . DomUtil . create ( "span" , "mapml-feature-index-content" , this . _output ) ;
10
+ this . _body . index = 0 ;
10
11
11
12
map . on ( "layerchange layeradd layerremove overlayremove" , this . _toggleEvents , this ) ;
12
13
map . on ( 'moveend focus' , this . _checkOverlap , this ) ;
13
- map . on ( "keydown" , this . _toggleContent , this ) ;
14
+ map . on ( "keydown" , this . _onKeyDown , this ) ;
14
15
this . _addOrRemoveFeatureIndex ( ) ;
15
16
} ,
16
17
@@ -33,19 +34,21 @@ export var FeatureIndex = L.Layer.extend({
33
34
let body = this . _body ;
34
35
35
36
body . innerHTML = "" ;
37
+ body . index = 0 ;
36
38
37
39
body . allFeatures = [ ] ;
38
40
keys . forEach ( i => {
39
41
if ( layers [ i ] . featureAttributes && featureIndexBounds . overlaps ( layers [ i ] . _bounds ) ) {
40
- let label = layers [ i ] . group . getAttribute ( "aria-label" ) ;
42
+ let group = layers [ i ] . group ;
43
+ let label = group . getAttribute ( "aria-label" ) ;
41
44
42
45
if ( index < 8 ) {
43
46
body . appendChild ( this . _updateOutput ( label , index , index ) ) ;
44
47
}
45
48
if ( index % 7 === 0 || index === 1 ) {
46
49
body . allFeatures . push ( [ ] ) ;
47
50
}
48
- body . allFeatures [ Math . floor ( ( index - 1 ) / 7 ) ] . push ( { label, index} ) ;
51
+ body . allFeatures [ Math . floor ( ( index - 1 ) / 7 ) ] . push ( { label, index, group } ) ;
49
52
if ( body . allFeatures [ 1 ] && body . allFeatures [ 1 ] . length === 1 ) {
50
53
body . appendChild ( this . _updateOutput ( "More results" , 0 , 9 ) ) ;
51
54
}
@@ -78,12 +81,16 @@ export var FeatureIndex = L.Layer.extend({
78
81
}
79
82
} ,
80
83
81
- _toggleContent : function ( e ) {
84
+ _onKeyDown : function ( e ) {
82
85
let body = this . _body ;
83
- if ( e . originalEvent . keyCode === 57 ) {
84
- this . _newContent ( body , 1 ) ;
86
+ let key = e . originalEvent . keyCode ;
87
+ if ( key >= 49 && key <= 55 ) {
88
+ let group = body . allFeatures [ body . index ] [ key - 49 ] . group ;
89
+ if ( group ) group . focus ( ) ;
85
90
} else if ( e . originalEvent . keyCode === 56 ) {
86
91
this . _newContent ( body , - 1 ) ;
92
+ } else if ( e . originalEvent . keyCode === 57 ) {
93
+ this . _newContent ( body , 1 ) ;
87
94
}
88
95
} ,
89
96
@@ -92,6 +99,7 @@ export var FeatureIndex = L.Layer.extend({
92
99
let newContent = body . allFeatures [ Math . floor ( ( ( index - 1 ) / 7 ) + direction ) ] ;
93
100
if ( newContent && newContent . length > 0 ) {
94
101
body . innerHTML = "" ;
102
+ body . index += direction ;
95
103
for ( let i = 0 ; i < newContent . length ; i ++ ) {
96
104
let feature = newContent [ i ] ;
97
105
let index = feature . index ? feature . index : 0 ;
0 commit comments