Skip to content

Commit 2582658

Browse files
committed
fix: get feature info with projection
1 parent 074acf1 commit 2582658

File tree

5 files changed

+112
-8
lines changed

5 files changed

+112
-8
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Improved performance when removing primitives. [#3018](https://github.com/CesiumGS/cesium/pull/3018)
2323
- Improved performance of terrain Quadtree handling of custom data [#12907](https://github.com/CesiumGS/cesium/pull/12907)
2424
- Fixed picking of `GroundPrimitive` with multiple `PolygonGeometry` instances selecting the wrong instance. [#12978](https://github.com/CesiumGS/cesium/pull/12978)
25+
- Fixed WMS GetFeatureInfo requests to correctly projects the results based on schema projection. [#12993](https://github.com/CesiumGS/cesium/pull/12993)
2526

2627
## 1.134.1 - 2025-10-10
2728

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [{
4+
"type": "Feature",
5+
"id": "bores.641",
6+
"geometry": {
7+
"type": "Point",
8+
"coordinates": [1406877.9886, 5326443.0126]
9+
},
10+
"geometry_name": "the_geom",
11+
"properties": {
12+
"OBJECTID": 2956,
13+
"FEATTYPE": "Bore",
14+
"NAME": "TOP TANK",
15+
"FEATREL": "1980-12-31T13:00:00Z",
16+
"ATTRREL": "1980-12-31T13:00:00Z",
17+
"PLANACC": 100,
18+
"SOURCE": "GEOSCIENCE AUSTRALIA",
19+
"CREATED": "2006-05-08T14:00:00Z",
20+
"RETIRED": null,
21+
"PID": 527738,
22+
"SYMBOL": 11,
23+
"FEATWIDTH": 0,
24+
"ORIENTATN": 0,
25+
"TEXTNOTE": ""
26+
}
27+
}],
28+
"crs": {
29+
"type": "EPSG",
30+
"properties": {
31+
"code": "3857"
32+
}
33+
}
34+
}

packages/engine/Source/Scene/GetFeatureInfoFormat.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import Cartesian3 from "../Core/Cartesian3.js";
12
import Cartographic from "../Core/Cartographic.js";
23
import defined from "../Core/defined.js";
34
import DeveloperError from "../Core/DeveloperError.js";
5+
import GeographicProjection from "../Core/GeographicProjection.js";
46
import RuntimeError from "../Core/RuntimeError.js";
57
import ImageryLayerFeatureInfo from "./ImageryLayerFeatureInfo.js";
68

@@ -70,8 +72,7 @@ function GetFeatureInfoFormat(type, format, callback) {
7072

7173
this.callback = callback;
7274
}
73-
74-
function geoJsonToFeatureInfo(json) {
75+
function geoJsonToFeatureInfo(json, projection) {
7576
const result = [];
7677

7778
const features = json.features;
@@ -86,9 +87,16 @@ function geoJsonToFeatureInfo(json) {
8687

8788
// If this is a point feature, use the coordinates of the point.
8889
if (defined(feature.geometry) && feature.geometry.type === "Point") {
89-
const longitude = feature.geometry.coordinates[0];
90-
const latitude = feature.geometry.coordinates[1];
91-
featureInfo.position = Cartographic.fromDegrees(longitude, latitude);
90+
const x = feature.geometry.coordinates[0];
91+
const y = feature.geometry.coordinates[1];
92+
93+
if (!defined(projection) || projection instanceof GeographicProjection) {
94+
featureInfo.position = Cartographic.fromDegrees(x, y);
95+
} else {
96+
const positionInMeters = new Cartesian3(x, y, 0);
97+
const cartographic = projection.unproject(positionInMeters);
98+
featureInfo.position = cartographic;
99+
}
92100
}
93101

94102
result.push(featureInfo);

packages/engine/Source/Scene/UrlTemplateImageryProvider.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,26 @@ UrlTemplateImageryProvider.prototype.pickFeatures = function (
588588
++formatIndex;
589589

590590
if (format.type === "json") {
591-
return resource.fetchJson().then(format.callback).catch(doRequest);
591+
return resource
592+
.fetchJson()
593+
.then((response) =>
594+
format.callback(response, that.tilingScheme.projection),
595+
)
596+
.catch(doRequest);
592597
} else if (format.type === "xml") {
593-
return resource.fetchXML().then(format.callback).catch(doRequest);
598+
return resource
599+
.fetchXML()
600+
.then((response) =>
601+
format.callback(response, that.tilingScheme.projection),
602+
)
603+
.catch(doRequest);
594604
} else if (format.type === "text" || format.type === "html") {
595-
return resource.fetchText().then(format.callback).catch(doRequest);
605+
return resource
606+
.fetchText()
607+
.then((response) =>
608+
format.callback(response, that.tilingScheme.projection),
609+
)
610+
.catch(doRequest);
596611
}
597612
return resource
598613
.fetch({

packages/engine/Specs/Scene/WebMapServiceImageryProviderSpec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
} from "../../index.js";
2626

2727
import pollToPromise from "../../../../Specs/pollToPromise.js";
28+
import WebMercatorProjection from "../../Source/Core/WebMercatorProjection.js";
29+
import Cartesian3 from "../../Source/Core/Cartesian3.js";
2830

2931
describe("Scene/WebMapServiceImageryProvider", function () {
3032
beforeEach(function () {
@@ -965,6 +967,50 @@ describe("Scene/WebMapServiceImageryProvider", function () {
965967
});
966968
});
967969

970+
it("works with GeoJSON responses in mercator projection", function () {
971+
const provider = new WebMapServiceImageryProvider({
972+
url: "made/up/wms/server",
973+
layers: "someLayer",
974+
tilingScheme: new WebMercatorTilingScheme(),
975+
});
976+
977+
Resource._Implementations.loadWithXhr = function (
978+
url,
979+
responseType,
980+
method,
981+
data,
982+
headers,
983+
deferred,
984+
overrideMimeType,
985+
) {
986+
expect(url).toContain("GetFeatureInfo");
987+
Resource._DefaultImplementations.loadWithXhr(
988+
"Data/WMS/GetFeatureInfo-GeoJSON-mercator.json",
989+
responseType,
990+
method,
991+
data,
992+
headers,
993+
deferred,
994+
overrideMimeType,
995+
);
996+
};
997+
const projection = new WebMercatorProjection();
998+
999+
return provider
1000+
.pickFeatures(0, 0, 0, 0.5, 0.5)
1001+
.then(function (pickResult) {
1002+
expect(pickResult.length).toBe(1);
1003+
1004+
const firstResult = pickResult[0];
1005+
expect(firstResult).toBeInstanceOf(ImageryLayerFeatureInfo);
1006+
expect(firstResult.name).toBe("TOP TANK");
1007+
expect(firstResult.description).toContain("GEOSCIENCE AUSTRALIA");
1008+
expect(firstResult.position).toEqual(
1009+
projection.unproject(new Cartesian3(1406877.9886, 5326443.0126, 0)),
1010+
);
1011+
});
1012+
});
1013+
9681014
it("works with MapInfo MXP responses", function () {
9691015
const provider = new WebMapServiceImageryProvider({
9701016
url: "made/up/wms/server",

0 commit comments

Comments
 (0)