Select to view content in your preferred language

Get X,Y coordinates of data records

620
1
Jump to solution
10-18-2021 08:34 PM
Dan_
by
Emerging Contributor

Hello,

I'm trying to read the x & y coordinates of selected data records in a custom widget. My data source is a layer of points. Retrieving the data attributes of the selected records works perfectly fine, but I can't figure out, how to get the points' coordinates. getGeometry() returns null. I'm using the current version (v1.5) of the developer edition. Am I missing something?

const ds = DataSourceManager.getInstance().getDataSource(
  props.useDataSources[0].dataSourceId
);
ds.getSelectedRecords().map((r) => {
  console.log(r.getGeometry()); // null
});

 

Thanks

0 Kudos
1 Solution

Accepted Solutions
Dan_
by
Emerging Contributor

I've figured out, what caused the issue for me.

I was using the DataSourceComponent with an empty query. Setting returnGeometry in the query solved the problem.

<DataSourceComponent
        useDataSource={props.useDataSources[0]}
        query={{where: '1=1',outFields: ['*'],returnGeometry: true,}}
        widgetId={props.id}
>
        {dataRender}
</DataSourceComponent>

 

View solution in original post

1 Reply
Dan_
by
Emerging Contributor

I've figured out, what caused the issue for me.

I was using the DataSourceComponent with an empty query. Setting returnGeometry in the query solved the problem.

<DataSourceComponent
        useDataSource={props.useDataSources[0]}
        query={{where: '1=1',outFields: ['*'],returnGeometry: true,}}
        widgetId={props.id}
>
        {dataRender}
</DataSourceComponent>