@@ -102,25 +102,23 @@ export var QueryHandler = L.Handler.extend({
102102 }
103103 } )
104104 . then ( ( response ) => {
105- if ( ! layer . _mapmlFeatures ) layer . _mapmlFeatures = [ ] ;
105+ let features = [ ] ;
106106 if ( response . contenttype . startsWith ( 'text/mapml' ) ) {
107107 // the mapmldoc could have <map-meta> elements that are important, perhaps
108108 // also, the mapmldoc can have many features
109109 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+ ) ;
116116 // <map-meta> elements
117117 layer . metas = Array . prototype . slice . call (
118118 mapmldoc . querySelectorAll (
119119 'map-meta[name=cs], map-meta[name=zoom], map-meta[name=projection]'
120120 )
121121 ) ;
122- if ( features . length )
123- layer . _mapmlFeatures = layer . _mapmlFeatures . concat ( features ) ;
124122 } else {
125123 // synthesize a single feature from text or html content
126124 let geom =
@@ -139,9 +137,9 @@ export var QueryHandler = L.Handler.extend({
139137 'text/html'
140138 )
141139 . querySelector ( 'map-feature' ) ;
142- layer . _mapmlFeatures . push ( feature ) ;
140+ features . push ( feature ) ;
143141 }
144- return layer . _mapmlFeatures ;
142+ return { features : features , template : template } ;
145143 } )
146144 . catch ( ( err ) => {
147145 console . log ( 'Looks like there was a problem. Status: ' + err . message ) ;
@@ -248,14 +246,21 @@ export var QueryHandler = L.Handler.extend({
248246 fetches . push ( fetchFeatures ( template , obj ) ) ;
249247 }
250248 }
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 ) ;
256260 }
257- displayFeaturesPopup ( layer . _mapmlFeatures , e . latlng ) ;
258261 }
262+ if ( layer . _mapmlFeatures . length > 0 )
263+ displayFeaturesPopup ( layer . _mapmlFeatures , e . latlng ) ;
259264 } ) ;
260265
261266 function displayFeaturesPopup ( features , loc ) {
0 commit comments