@@ -2,6 +2,7 @@ import { Vector as VectorLayer } from "ol/layer";
22import { Vector as VectorSource } from "ol/source" ;
33import { type Rule , evaluateStyle , parseMapCSS } from "./mapcss" ;
44import { Geometry } from "ol/geom" ;
5+ import GeoJSON from "ol/format/GeoJSON" ;
56import OSMXML from "./OSMXML" ;
67import { splitQuerySubpart } from "./overpass" ;
78
@@ -12,16 +13,24 @@ export default class OverpassVectorLayer extends VectorLayer<
1213 const map = this . getMapInternal ( ) ;
1314 const features = await Promise . all (
1415 splitQuerySubpart ( query ) . map ( ( { query, subpart } ) =>
15- this . executeQuery0 ( query , subpart ) ,
16+ / \/ \/ \/ \s * @ t y p e g e o j s o n / dg. test ( query )
17+ ? this . readGeoJSON ( query . replace ( / \/ \/ \/ .* / dg, "" ) , subpart )
18+ : this . executeQuery0 ( query , subpart ) ,
1619 ) ,
1720 ) ;
1821 const vectorSource = new VectorSource ( {
19- features : features . reduce ( ( a , b ) => [ ... a , ... b ] ) ,
22+ features : features . flat ( ) ,
2023 } ) ;
2124 this . setSource ( vectorSource ) ;
2225 map ?. getView ( ) . fit ( vectorSource . getExtent ( ) , { padding : [ 24 , 24 , 24 , 24 ] } ) ;
2326 }
2427
28+ private readGeoJSON ( query : string , subpart = "" ) {
29+ const features = new GeoJSON ( ) . readFeatures ( query ) ;
30+ features . forEach ( ( feature ) => feature . set ( "@subpart" , subpart ) ) ;
31+ return features ;
32+ }
33+
2534 private async executeQuery0 ( query : string , subpart = "" ) {
2635 const map = this . getMapInternal ( ) ;
2736 if ( map ) {
0 commit comments