Esri / arcgis-experience-builder-sdk-resources

ArcGIS Experience Builder samples
https://developers.arcgis.com/experience-builder/
Apache License 2.0
119 stars 111 forks source link

Fix get map coordinates #176

Open esride-nik opened 5 months ago

esride-nik commented 5 months ago

The "get map coordinates" widget ran into null pointer issues for SRs other than 4326 or 3857. latitude and longitude or map center resp. mouse coordinate are undefined when using a projected coordinate system like 25832 (UTM 32N). First step was to prevent the null pointer errors by adding conditional access (latitude?.toFixed(3)), second step was to project the points if necessary.

qlqllu commented 5 months ago

@esride-nik Thanks for the PR! For the geometry projection, can you try whether this works?

import { geometryUtils } from 'jimu-core'
geometryUtils.projectToSpatialReference()
grothkha commented 5 months ago

using geometryUtils leads to an error

Uncaught (in promise) TypeError: t.equals is not a function
    at Module.<anonymous> (index.js:2:592375)
    at Generator.next (<anonymous>)
    at index.js:2:591904
    at new Promise (<anonymous>)
    at nC (index.js:2:591649)
    at Module.oC (index.js:2:592270)
    at Widget.<anonymous> (widget.tsx:60:27)
    at Generator.next (<anonymous>)
    at set-public-path.ts:7:52
    at new Promise (<anonymous>)

widget.tsx:60:27 is our function call

geometryUtils.projectToSpatialReference([point], { wkid: 4326 } as __esri.SpatialReference)

while parameter "point" is our esri/geometry/Point in wkid 25832

esride-nik commented 5 months ago

Thanks @grothkha! (He's the one with the right service at hand.) Btw @qlqllu, your documentation doesn't say anything about geometryUtils ;)

qlqllu commented 5 months ago

Could you create a SpatialReference instance? For the documentation, there are still many classes/methods that are not documented yet, we are trying to add more.