Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

export enum EsriDumpConfigApproach {
BBOX = 'bbox',
ITER = 'iter'
ITER = 'iter',
TOP_FEATURES_BBOX = 'top_features_bbox',
TOP_FEATURES_ITER = 'top_features_iter',
}

export enum EsriResourceType {
Expand Down Expand Up @@ -75,7 +77,7 @@
const discover = new Discovery(this.url);
discover.fetch(this.config);

discover.on('layer', (layer: any) => {

Check warning on line 80 in index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
this.emit('layer', layer);
}).on('schema', (schema: JSONSchema6) => {
this.emit('schema', schema);
Expand Down Expand Up @@ -122,7 +124,7 @@
if (!res.ok) this.emit('error', await res.text());

// TODO: Type Defs
const metadata: any = await res.json();

Check warning on line 127 in index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

if (metadata.error) {
return this.emit('error', new Err(400, null, 'Server metadata error: ' + metadata.error.message));
Expand All @@ -137,7 +139,7 @@

if (metadata.services.length > 0 && Array.isArray(metadata.services)) {
errorMessage += '\nChoose a Layer from one of these Services: \n '
+ metadata.services.map((d: any) => { return d.name; }).join('\n ') + '\n';

Check warning on line 142 in index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
}

return this.emit('error', new Err(400, null, errorMessage));
Expand All @@ -145,7 +147,7 @@
let errorMessage = 'Endpoint provided is not a Server resource.\n';
if (metadata.layers.length > 0 && Array.isArray(metadata.layers)) {
errorMessage += '\nChoose one of these Layers: \n '
+ metadata.layers.map((d: any) => { return d.name; }).join('\n ') + '\n';

Check warning on line 150 in index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
}
return this.emit('error', new Err(400, null, errorMessage));
} else if (!this.resourceType) {
Expand Down
29 changes: 20 additions & 9 deletions lib/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default class Geometry extends EventEmitter {
paths: Path[];
schema: JSONSchema6;

constructor(url: URL, metadata: any) {
constructor(
url: URL,
metadata: any
) {
super();

this.baseUrl = url;
Expand All @@ -48,9 +51,13 @@ export default class Geometry extends EventEmitter {

async fetch(config: EsriDumpConfig) {
try {
if (config.approach === EsriDumpConfigApproach.BBOX) await this.fetch_bbox(config);
else if (config.approach === EsriDumpConfigApproach.ITER) await this.fetch_iter(config);
else throw new Err(400, null, 'Unknown Approach');
if (config.approach === EsriDumpConfigApproach.BBOX || EsriDumpConfigApproach.TOP_FEATURES_BBOX) {
await this.fetch_bbox(config);
} else if (config.approach === EsriDumpConfigApproach.ITER || EsriDumpConfigApproach.TOP_FEATURES_ITER) {
await this.fetch_iter(config);
} else {
throw new Err(400, null, 'Unknown Approach');
}
} catch (err) {
this.emit('error', err);
}
Expand All @@ -59,7 +66,9 @@ export default class Geometry extends EventEmitter {
async fetch_iter(config: EsriDumpConfig) {
if (!this.oidField) this.emit('error', new Err(400, null, 'Cannot use iter function as oidField could not be determined'));

const url = new URL(String(this.baseUrl) + '/query');
const queryFragment = config.approach === EsriDumpConfigApproach.TOP_FEATURES_ITER ? '/queryTopFeatures' : '/query';

const url = new URL(String(this.baseUrl) + queryFragment);
url.searchParams.append('returnCountOnly', 'true');
if (!config.params.where) url.searchParams.append('where', '1=1');

Expand All @@ -79,7 +88,7 @@ export default class Geometry extends EventEmitter {
while (curr < count) {
let attempts = 0;

const url = new URL(String(this.baseUrl) + '/query');
const url = new URL(String(this.baseUrl) + queryFragment);
if (!config.params.where) url.searchParams.append('where', '1=1');
url.searchParams.append('geometryPrecision', '7');
url.searchParams.append('returnGeometry', 'true');
Expand Down Expand Up @@ -112,7 +121,7 @@ export default class Geometry extends EventEmitter {
this.emit('feature', feat)
} catch (err) {
// This usually errors if it's an attribute only feature
if (process.env.DEBUG) console.error('Invalid Feature', feature);
if (process.env.DEBUG) console.error('Invalid Feature', feature, err instanceof Error ? err.message : err);
}
}
}
Expand All @@ -132,10 +141,12 @@ export default class Geometry extends EventEmitter {
}

async fetch_bbox(config: EsriDumpConfig) {
const queryFragment = config.approach === EsriDumpConfigApproach.TOP_FEATURES_BBOX ? '/queryTopFeatures' : '/query';

while (this.paths.length) {
const bounds = this.paths.pop();

const url = new URL(String(this.baseUrl) + '/query');
const url = new URL(String(this.baseUrl) + queryFragment);
url.searchParams.append('geometry', [bounds.xmin, bounds.ymin, bounds.xmax, bounds.ymax].join(','));
url.searchParams.append('geometryType', 'esriGeometryEnvelope');
url.searchParams.append('spatialRel', 'esriSpatialRelIntersects');
Expand Down Expand Up @@ -180,7 +191,7 @@ export default class Geometry extends EventEmitter {
this.emit('feature', feat)
} catch (err) {
// This usually errors if it's an attribute only feature
if (process.env.DEBUG) console.error('Invalid Feature', feature);
if (process.env.DEBUG) console.error('Invalid Feature', feature, err instanceof Error ? err.message : err);
}
}
}
Expand Down
Loading
Loading