@@ -33,7 +33,10 @@ export default class Geometry extends EventEmitter {
3333 paths : Path [ ] ;
3434 schema : JSONSchema6 ;
3535
36- constructor ( url : URL , metadata : any ) {
36+ constructor (
37+ url : URL ,
38+ metadata : any
39+ ) {
3740 super ( ) ;
3841
3942 this . baseUrl = url ;
@@ -48,9 +51,13 @@ export default class Geometry extends EventEmitter {
4851
4952 async fetch ( config : EsriDumpConfig ) {
5053 try {
51- if ( config . approach === EsriDumpConfigApproach . BBOX ) await this . fetch_bbox ( config ) ;
52- else if ( config . approach === EsriDumpConfigApproach . ITER ) await this . fetch_iter ( config ) ;
53- else throw new Err ( 400 , null , 'Unknown Approach' ) ;
54+ if ( config . approach === EsriDumpConfigApproach . BBOX || EsriDumpConfigApproach . TOP_FEATURES_BBOX ) {
55+ await this . fetch_bbox ( config ) ;
56+ } else if ( config . approach === EsriDumpConfigApproach . ITER || EsriDumpConfigApproach . TOP_FEATURES_ITER ) {
57+ await this . fetch_iter ( config ) ;
58+ } else {
59+ throw new Err ( 400 , null , 'Unknown Approach' ) ;
60+ }
5461 } catch ( err ) {
5562 this . emit ( 'error' , err ) ;
5663 }
@@ -59,7 +66,9 @@ export default class Geometry extends EventEmitter {
5966 async fetch_iter ( config : EsriDumpConfig ) {
6067 if ( ! this . oidField ) this . emit ( 'error' , new Err ( 400 , null , 'Cannot use iter function as oidField could not be determined' ) ) ;
6168
62- const url = new URL ( String ( this . baseUrl ) + '/query' ) ;
69+ const queryFragment = config . approach === EsriDumpConfigApproach . TOP_FEATURES_ITER ? '/queryTopFeatures' : '/query' ;
70+
71+ const url = new URL ( String ( this . baseUrl ) + queryFragment ) ;
6372 url . searchParams . append ( 'returnCountOnly' , 'true' ) ;
6473 if ( ! config . params . where ) url . searchParams . append ( 'where' , '1=1' ) ;
6574
@@ -79,7 +88,7 @@ export default class Geometry extends EventEmitter {
7988 while ( curr < count ) {
8089 let attempts = 0 ;
8190
82- const url = new URL ( String ( this . baseUrl ) + '/query' ) ;
91+ const url = new URL ( String ( this . baseUrl ) + queryFragment ) ;
8392 if ( ! config . params . where ) url . searchParams . append ( 'where' , '1=1' ) ;
8493 url . searchParams . append ( 'geometryPrecision' , '7' ) ;
8594 url . searchParams . append ( 'returnGeometry' , 'true' ) ;
@@ -112,7 +121,7 @@ export default class Geometry extends EventEmitter {
112121 this . emit ( 'feature' , feat )
113122 } catch ( err ) {
114123 // This usually errors if it's an attribute only feature
115- if ( process . env . DEBUG ) console . error ( 'Invalid Feature' , feature ) ;
124+ if ( process . env . DEBUG ) console . error ( 'Invalid Feature' , feature , err instanceof Error ? err . message : err ) ;
116125 }
117126 }
118127 }
@@ -132,10 +141,12 @@ export default class Geometry extends EventEmitter {
132141 }
133142
134143 async fetch_bbox ( config : EsriDumpConfig ) {
144+ const queryFragment = config . approach === EsriDumpConfigApproach . TOP_FEATURES_BBOX ? '/queryTopFeatures' : '/query' ;
145+
135146 while ( this . paths . length ) {
136147 const bounds = this . paths . pop ( ) ;
137148
138- const url = new URL ( String ( this . baseUrl ) + '/query' ) ;
149+ const url = new URL ( String ( this . baseUrl ) + queryFragment ) ;
139150 url . searchParams . append ( 'geometry' , [ bounds . xmin , bounds . ymin , bounds . xmax , bounds . ymax ] . join ( ',' ) ) ;
140151 url . searchParams . append ( 'geometryType' , 'esriGeometryEnvelope' ) ;
141152 url . searchParams . append ( 'spatialRel' , 'esriSpatialRelIntersects' ) ;
@@ -180,7 +191,7 @@ export default class Geometry extends EventEmitter {
180191 this . emit ( 'feature' , feat )
181192 } catch ( err ) {
182193 // This usually errors if it's an attribute only feature
183- if ( process . env . DEBUG ) console . error ( 'Invalid Feature' , feature ) ;
194+ if ( process . env . DEBUG ) console . error ( 'Invalid Feature' , feature , err instanceof Error ? err . message : err ) ;
184195 }
185196 }
186197 }
0 commit comments