I cant zoom/pan to a IGeometry Object from a FeatureDataRecord. I'm using following function for this.
zoomTo = (geom: IGeometry) => {
if (this.jimuMapView) {
this.jimuMapView.view.goTo(geom).catch(function (error) {
if (error.name != "AbortError") {
console.error(error);
}
});
}
}
Solved! Go to Solution.
Try adding this to your manifest.json:
"dependency": [
"jimu-arcgis"
]
Try casting as Geometry
import Geometry from 'esri/geometry/Geometry';
this.jimuMapView?.view.goTo(geom as Geometry);
I can't use
import Geometry from 'esri/geometry/Geometry';
Module '"esri/geometry/Geometry"' can only be default-imported using the 'allowSyntheticDefaultImports' flagts(1259)
arcgis-js-api.d.ts(95049, 3): This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
I use
import { Polygon,Polyline, Geometry } from 'esri/geometry';
instead. Could this be a problem?
I can cast to geom as Geometry but the Object shows still the same content:
geom
{spatialReference: {…}, paths: Array(1)}
paths : [Array(153)]
spatialReference : {latestWkid: 2056, wkid: 2056}
[[Prototype]]: Object
It doesn't look like a Geometry Object.
Therefore still no zoom/pan to the Geometry...
It seems to be a Import problem. if I use
import Polyline from 'esri/geometry/Polyline';
the widget can't load when I use new Polygon({..}).
if I use use
constructor(props) {
super(props);
loadArcGISJSAPIModules([
"esri/geometry/geometryEngine",
"esri/geometry/Polyline"
]).then((modules) => {
[this.geometryEngine, this.polyline] = modules;
console.log("ESRI API Moduls loaded");
});
}
I can use the Polygon type like this
zoomTo = (geom: IGeometry) => {
if (this.jimuMapView) {
const pl = new this.polyline({
paths: (geom as IPolyline).paths,
spatialReference: geom.spatialReference
});
this.jimuMapView.view.goTo(pl).catch(function (error) {
if (error.name != "AbortError") {
console.error(error);
}
});
}
}
But I don't understand why I can't use import?
Try adding this to your manifest.json:
"dependency": [
"jimu-arcgis"
]
That's solved my problems. Thanks a lot!
I have updated ExB from Version 1.5 to 1.11 and again I get stuck with this problem. This code isn't working any more for me:
zoomTo = (geom: IGeometry) => {
let g;
if ((geom as IPolyline).paths) {
g = new Polyline(geom);
} else {
g = new Polygon(geom);
}
this.jimuMapView?.view.goTo(g).catch(function (error) {
// if (error.name != "AbortError") {
// console.error(error);
// }
});
}
new Polyline or new Polygone won't be found
I still have this in my manifest.json:
"dependency": [ "jimu-arcgis" ]
I just solved this. I hade to change the Import part from
import { Polyline, Polygon } from "esri/geometry";
to
import Polyline from "esri/geometry/Polyline";
import Polygon from "esri/geometry/Polygon";