Skip to content

Commit

Permalink
Fix ArcGIS Feature request failures on specific server (#7295)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdastous-bentley authored Oct 30, 2024
1 parent 306fffe commit 544bc8e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/map-layers-formats",
"comment": "Fix ArcGIS Feature request failures on specific server",
"type": "none"
}
],
"packageName": "@itwin/map-layers-formats"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Cartographic, ImageMapLayerSettings, ImageSource, ImageSourceFormat, Se
import { base64StringToUint8Array, IModelStatus, Logger } from "@itwin/core-bentley";
import { Matrix4d, Point3d, Range2d, Transform } from "@itwin/core-geometry";
import { ArcGisErrorCode, ArcGISImageryProvider, ArcGISServiceMetadata, ArcGisUtilities, FeatureGraphicsRenderer, HitDetail, ImageryMapTileTree, MapCartoRectangle, MapFeatureInfoOptions, MapLayerFeatureInfo, MapLayerImageryProviderStatus, QuadId, setRequestTimeout } from "@itwin/core-frontend";
import { ArcGisExtent, ArcGisFeatureFormat, ArcGisFeatureQuery, ArcGisFeatureResultType, ArcGisGeometry, FeatureQueryQuantizationParams } from "./ArcGisFeatureQuery";
import { ArcGisExtent, ArcGisFeatureFormat, arcgisFeatureFormats, ArcGisFeatureQuery, ArcGisFeatureResultType, ArcGisGeometry, FeatureQueryQuantizationParams } from "./ArcGisFeatureQuery";
import { ArcGisPbfFeatureReader } from "./ArcGisPbfFeatureReader";
import { ArcGisJsonFeatureReader } from "./ArcGisJsonFeatureReader";
import { ArcGisFeatureResponse, ArcGisResponseData } from "./ArcGisFeatureResponse";
Expand Down Expand Up @@ -215,11 +215,11 @@ export class ArcGisFeatureProvider extends ArcGISImageryProvider {
// Note: needs to be checked on the layer metadata, service metadata advertises a different set of formats
// Also, since PBF format does not support floating points, there is no point using this format if supportsCoordinatesQuantization is not available.
if (this._layerMetadata.supportedQueryFormats) {
const formats: string[] = this._layerMetadata.supportedQueryFormats.split(", ");
if (formats.includes("PBF") && this._supportsCoordinatesQuantization) {
this._format = "PBF";
} else if (formats.includes("JSON")) {
this._format = "JSON";
const formats: string[] = this._layerMetadata.supportedQueryFormats.split(",").map((s: string) => s.trim().toLowerCase());
if (formats.includes(arcgisFeatureFormats.pbf) && this._supportsCoordinatesQuantization) {
this._format = arcgisFeatureFormats.pbf;
} else if (formats.includes(arcgisFeatureFormats.json)) {
this._format = arcgisFeatureFormats.json;
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ export class ArcGisFeatureProvider extends ArcGISImageryProvider {
tmpUrl.searchParams.append("where", "1=1");
tmpUrl.searchParams.append("outSR", "3857");
tmpUrl.searchParams.append("returnExtentOnly", "true");
tmpUrl.searchParams.append("f", "json");
tmpUrl.searchParams.append("f", arcgisFeatureFormats.json);
const cached = ArcGisFeatureProvider._extentCache.get(tmpUrl.toString());
if (cached) {
extentJson = cached;
Expand Down Expand Up @@ -433,12 +433,12 @@ export class ArcGisFeatureProvider extends ArcGISImageryProvider {

if (this._debugFeatureGeom) {
try {
let responseData = await doFeatureInfoQuery("PBF", "", true);
let responseData = await doFeatureInfoQuery(arcgisFeatureFormats.pbf, "", true);
if (responseData) {
const json = JSON.stringify(responseData.data.toObject());
Logger.logInfo(loggerCategory, json);
}
responseData = await doFeatureInfoQuery("JSON", "", true);
responseData = await doFeatureInfoQuery(arcgisFeatureFormats.json, "", true);
if (responseData) {
const json = JSON.stringify(responseData.data);
Logger.logInfo(loggerCategory, json);
Expand All @@ -450,7 +450,7 @@ export class ArcGisFeatureProvider extends ArcGISImageryProvider {

try {
// Feature Info requests are always made in JSON for now.
const responseData = await doFeatureInfoQuery("JSON", "*", true);
const responseData = await doFeatureInfoQuery(arcgisFeatureFormats.json, "*", true);
if (!responseData) {
Logger.logError(loggerCategory, `Could not get feature info data`);
return;
Expand Down Expand Up @@ -556,7 +556,9 @@ export class ArcGisFeatureProvider extends ArcGISImageryProvider {
}

const renderer = new FeatureCanvasRenderer(ctx, this._symbologyRenderer, transfo);
const featureReader: ArcGisFeatureReader = this.format === "PBF" ? new ArcGisPbfFeatureReader(this._settings, this._layerMetadata) : new ArcGisJsonFeatureReader(this._settings, this._layerMetadata);
const featureReader: ArcGisFeatureReader = this.format === arcgisFeatureFormats.pbf
? new ArcGisPbfFeatureReader(this._settings, this._layerMetadata)
: new ArcGisJsonFeatureReader(this._settings, this._layerMetadata);

const getSubEnvelopes = (envelope: ArcGisExtent): ArcGisExtent[] => {
const dx = (envelope.xmax - envelope.xmin) * 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export interface FeatureQueryQuantizationParams {
}

/** @internal */
export type ArcGisFeatureFormat = "JSON" | "PBF";
export type ArcGisFeatureFormat = "json" | "pbf";

/**
* @internal
*/
export const arcgisFeatureFormats = {
json: "json" as ArcGisFeatureFormat,
pbf: "pbf" as ArcGisFeatureFormat,
}

// Based on official documentation:
// https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { ArcGisExtent, ArcGisFeatureFormat } from "./ArcGisFeatureQuery";
import { ArcGisExtent, ArcGisFeatureFormat, arcgisFeatureFormats } from "./ArcGisFeatureQuery";
import { esriPBuffer } from "./esriPBuffer.gen";

/** @internal */
Expand Down Expand Up @@ -48,7 +48,7 @@ export class ArcGisFeatureResponse {
if (tileResponse === undefined || tileResponse.status !== 200 )
return undefined;

if (this.format === "PBF") {
if (this.format === arcgisFeatureFormats.pbf) {
const byteArray: Uint8Array = new Uint8Array(await tileResponse.arrayBuffer());
if (!byteArray || (byteArray.length === 0))
return undefined;
Expand Down
Loading

0 comments on commit 544bc8e

Please sign in to comment.