Select to view content in your preferred language

Zoom to IGeometry Object

1167
7
Jump to solution
10-24-2022 12:28 PM
Zoggo
by
Occasional Contributor

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);
        }
      });
    }
  }
 
There's no error but the view doesn't move to the Geometry...
0 Kudos
1 Solution

Accepted Solutions
DougLogsdon2
Regular Contributor

Try adding this to your manifest.json:

 "dependency": [
    "jimu-arcgis"
  ]

View solution in original post

0 Kudos
7 Replies
DougLogsdon2
Regular Contributor

Try casting as Geometry

import Geometry from 'esri/geometry/Geometry';

this.jimuMapView?.view.goTo(geom as Geometry);

 

0 Kudos
Zoggo
by
Occasional Contributor

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...

0 Kudos
Zoggo
by
Occasional Contributor

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?

0 Kudos
DougLogsdon2
Regular Contributor

Try adding this to your manifest.json:

 "dependency": [
    "jimu-arcgis"
  ]
0 Kudos
Zoggo
by
Occasional Contributor

That's solved my problems. Thanks a lot!

0 Kudos
Zoggo
by
Occasional Contributor

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"
  ]

 

0 Kudos
Zoggo
by
Occasional Contributor

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";
0 Kudos