(template, obj)
| 129 | let fetches = []; |
| 130 | |
| 131 | var fetchFeatures = function (template, obj) { |
| 132 | const parser = new DOMParser(); |
| 133 | return fetch(LeafletUtil.template(template.template, obj), { |
| 134 | redirect: 'follow' |
| 135 | }) |
| 136 | .then((response) => { |
| 137 | if (response.status >= 200 && response.status < 300) { |
| 138 | return response.text().then((text) => { |
| 139 | return { |
| 140 | contenttype: response.headers.get('Content-Type'), |
| 141 | text: text |
| 142 | }; |
| 143 | }); |
| 144 | } else { |
| 145 | throw new Error(response.status); |
| 146 | } |
| 147 | }) |
| 148 | .then((response) => { |
| 149 | let features = []; |
| 150 | let queryMetas = []; |
| 151 | let geom = |
| 152 | "<map-geometry cs='gcrs'><map-point><map-coordinates>" + |
| 153 | e.latlng.lng + |
| 154 | ' ' + |
| 155 | e.latlng.lat + |
| 156 | '</map-coordinates></map-point></map-geometry>'; |
| 157 | if (response.contenttype.startsWith('text/mapml')) { |
| 158 | // the mapmldoc could have <map-meta> elements that are important, perhaps |
| 159 | // also, the mapmldoc can have many features |
| 160 | let mapmldoc = parser.parseFromString( |
| 161 | response.text, |
| 162 | 'application/xml' |
| 163 | ); |
| 164 | let geometrylessFeatures = mapmldoc.querySelectorAll( |
| 165 | 'map-feature:not(:has(map-geometry))' |
| 166 | ); |
| 167 | if (geometrylessFeatures.length) { |
| 168 | let g = parser.parseFromString(geom, 'application/xml'); |
| 169 | for (let i = 0; i < geometrylessFeatures.length; i++) { |
| 170 | let f = geometrylessFeatures[i]; |
| 171 | f.appendChild(g.firstElementChild.cloneNode(true)); |
| 172 | } |
| 173 | } |
| 174 | features = Array.prototype.slice.call( |
| 175 | mapmldoc.querySelectorAll('map-feature') |
| 176 | ); |
| 177 | // <map-meta> elements for this query |
| 178 | queryMetas = Array.prototype.slice.call( |
| 179 | mapmldoc.querySelectorAll( |
| 180 | 'map-meta[name=cs], map-meta[name=zoom], map-meta[name=projection]' |
| 181 | ) |
| 182 | ); |
| 183 | if (queryMetas.length) |
| 184 | features.forEach((f) => (f.meta = queryMetas)); |
| 185 | } else if ( |
| 186 | response.contenttype.startsWith('application/json') || |
| 187 | response.contenttype.startsWith('application/geo+json') || |
| 188 | response.contenttype.startsWith('application/geojson') |
no test coverage detected