Skip to content

Commit

Permalink
Add pickSize parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
glughi committed Nov 8, 2024
1 parent a033c4c commit db99d63
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
115 changes: 115 additions & 0 deletions lib/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ import proxyCatalogItemUrl from "../proxyCatalogItemUrl";
import MinMaxLevelMixin from "./../../../ModelMixins/MinMaxLevelMixin";
import { Extent, Layer, Legends, MapServer } from "./ArcGisInterfaces";
import CommonStrata from "../../Definition/CommonStrata";
import GeographicProjection from "terriajs-cesium/Source/Core/GeographicProjection";
import Cartographic from "terriajs-cesium/Source/Core/Cartographic";
import CesiumMath from "terriajs-cesium/Source/Core/Math";
import ImageryLayerFeatureInfo from "terriajs-cesium/Source/Scene/ImageryLayerFeatureInfo";
import WebMercatorProjection from "terriajs-cesium/Source/Core/WebMercatorProjection";
import Cartesian3 from "terriajs-cesium/Source/Core/Cartesian3";
import Resource from "terriajs-cesium/Source/Core/Resource";
import defined from "terriajs-cesium/Source/Core/defined";

const proj4 = require("proj4").default;

Expand Down Expand Up @@ -588,6 +596,113 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
true,
false
);

const pickSize: number = this.terria.configParameters.pickSize ?? 2;
ArcGisMapServerImageryProvider.prototype.pickFeatures = function (
x,
y,
level,
longitude,
latitude
) {
if (!this.enablePickFeatures) {
return undefined;
}

const rectangle = this.tilingScheme.tileXYToNativeRectangle(
x,
y,
level
);

let horizontal;
let vertical;
let sr;
if (this.tilingScheme.projection instanceof GeographicProjection) {
horizontal = CesiumMath.toDegrees(longitude);
vertical = CesiumMath.toDegrees(latitude);
sr = "4326";
} else {
const projected = this.tilingScheme.projection.project(
new Cartographic(longitude, latitude, 0.0)
);
horizontal = projected.x;
vertical = projected.y;
sr = "3857";
}

let layers = "visible";
if (defined(this.layers)) {
layers += `:${this.layers}`;
}

const query = {
f: "json",
tolerance: pickSize,
geometryType: "esriGeometryPoint",
geometry: `${horizontal},${vertical}`,
mapExtent: `${rectangle.west},${rectangle.south},${rectangle.east},${rectangle.north}`,
imageDisplay: `${this.tileWidth},${this.tileHeight},96`,
sr: sr,
layers: layers
};

const resource = new Resource({ url: this.url });
const newResource = resource.getDerivedResource({
url: "identify",
queryParameters: query
});
return newResource.fetchJson()?.then(function (json: any) {
const result: ImageryLayerFeatureInfo[] = [];

const features = json.results;
if (!defined(features)) {
return result;
}

for (let i = 0; i < features.length; ++i) {
const feature = features[i];

const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.name = feature.value;
featureInfo.properties = feature.attributes;
featureInfo.configureDescriptionFromProperties(feature.attributes);

// If this is a point feature, use the coordinates of the point.
if (
feature.geometryType === "esriGeometryPoint" &&
feature.geometry
) {
const wkid =
feature.geometry.spatialReference &&
feature.geometry.spatialReference.wkid
? feature.geometry.spatialReference.wkid
: 4326;
if (wkid === 4326 || wkid === 4283) {
featureInfo.position = Cartographic.fromDegrees(
feature.geometry.x,
feature.geometry.y,
feature.geometry.z
);
} else if (wkid === 102100 || wkid === 900913 || wkid === 3857) {
const projection = new WebMercatorProjection();
featureInfo.position = projection.unproject(
new Cartesian3(
feature.geometry.x,
feature.geometry.y,
feature.geometry.z
)
);
}
}

result.push(featureInfo);
}

return result;
});
};

const imageryProviderPromise = ArcGisMapServerImageryProvider.fromUrl(
cleanAndProxyUrl(this, getBaseURI(this).toString()),
Expand Down
7 changes: 6 additions & 1 deletion lib/Models/Cesium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,12 @@ export default class Cesium extends GlobeOrMap {
private async pickVectorFeatures(screenPosition: Cartesian2) {
// Pick vector features
const vectorFeatures = [];
const pickedList = this.scene.drillPick(screenPosition);
const pickedList = this.scene.drillPick(
screenPosition,
undefined,
this.terria.configParameters.pickSize,
this.terria.configParameters.pickSize
);
for (let i = 0; i < pickedList.length; ++i) {
const picked = pickedList[i];
let id = picked.id;
Expand Down
8 changes: 7 additions & 1 deletion lib/Models/Terria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ export interface ConfigParameters {
* List of the enabled MapViewers: 3d, 3dsmooth, 2d, cesium2d
*/
mapViewers: string[];

/**
* Side size for the drill pick in Cesium
*/
pickSize?: number;
}

interface StartOptions {
Expand Down Expand Up @@ -648,7 +653,8 @@ export default class Terria {
searchProviders: [],
coordsConverterUrl: undefined,
useElevationMeanSeaLevel: false,
mapViewers: ["3d", "3dsmooth", "2d"]
mapViewers: ["3d", "3dsmooth", "2d"],
pickSize: undefined
};

@observable
Expand Down

0 comments on commit db99d63

Please sign in to comment.