@@ -102,25 +102,23 @@ export var QueryHandler = L.Handler.extend({
102
102
}
103
103
} )
104
104
. then ( ( response ) => {
105
- if ( ! layer . _mapmlFeatures ) layer . _mapmlFeatures = [ ] ;
105
+ let features = [ ] ;
106
106
if ( response . contenttype . startsWith ( 'text/mapml' ) ) {
107
107
// the mapmldoc could have <map-meta> elements that are important, perhaps
108
108
// also, the mapmldoc can have many features
109
109
let mapmldoc = parser . parseFromString (
110
- response . text ,
111
- 'application/xml'
112
- ) ,
113
- features = Array . prototype . slice . call (
114
- mapmldoc . querySelectorAll ( 'map-feature' )
115
- ) ;
110
+ response . text ,
111
+ 'application/xml'
112
+ ) ;
113
+ features = Array . prototype . slice . call (
114
+ mapmldoc . querySelectorAll ( 'map-feature' )
115
+ ) ;
116
116
// <map-meta> elements
117
117
layer . metas = Array . prototype . slice . call (
118
118
mapmldoc . querySelectorAll (
119
119
'map-meta[name=cs], map-meta[name=zoom], map-meta[name=projection]'
120
120
)
121
121
) ;
122
- if ( features . length )
123
- layer . _mapmlFeatures = layer . _mapmlFeatures . concat ( features ) ;
124
122
} else {
125
123
// synthesize a single feature from text or html content
126
124
let geom =
@@ -139,9 +137,9 @@ export var QueryHandler = L.Handler.extend({
139
137
'text/html'
140
138
)
141
139
. querySelector ( 'map-feature' ) ;
142
- layer . _mapmlFeatures . push ( feature ) ;
140
+ features . push ( feature ) ;
143
141
}
144
- return layer . _mapmlFeatures ;
142
+ return { features : features , template : template } ;
145
143
} )
146
144
. catch ( ( err ) => {
147
145
console . log ( 'Looks like there was a problem. Status: ' + err . message ) ;
@@ -248,14 +246,21 @@ export var QueryHandler = L.Handler.extend({
248
246
fetches . push ( fetchFeatures ( template , obj ) ) ;
249
247
}
250
248
}
251
- Promise . allSettled ( fetches ) . then ( ( ) => {
252
- // create connection between queried <map-feature> and its parent <map-extent>
253
- if ( layer . _mapmlFeatures ) {
254
- for ( let feature of layer . _mapmlFeatures ) {
255
- feature . _extentEl = template . _extentEl ;
249
+ Promise . allSettled ( fetches ) . then ( ( results ) => {
250
+ layer . _mapmlFeatures = [ ] ;
251
+ // f is an array of {features[], template}
252
+
253
+ for ( let f of results ) {
254
+ if ( f . status === 'fulfilled' ) {
255
+ // create connection between queried <map-feature> and its parent <map-extent>
256
+ for ( let feature of f . value . features ) {
257
+ feature . _extentEl = f . value . template . _extentEl ;
258
+ }
259
+ layer . _mapmlFeatures = layer . _mapmlFeatures . concat ( f . value . features ) ;
256
260
}
257
- displayFeaturesPopup ( layer . _mapmlFeatures , e . latlng ) ;
258
261
}
262
+ if ( layer . _mapmlFeatures . length > 0 )
263
+ displayFeaturesPopup ( layer . _mapmlFeatures , e . latlng ) ;
259
264
} ) ;
260
265
261
266
function displayFeaturesPopup ( features , loc ) {
0 commit comments