Select to view content in your preferred language

How to change basemap coordinates from Sketch feature to XY Coordinates

1233
3
Jump to solution
01-15-2022 05:50 PM
RahmanNurhidayat
New Contributor

Hi everyone, I have a problem changing the coordinate type from the sketch feature to the XY coordinate type.

whenever i see result from draw coordinate type it stays basemap type.

 

code:

RahmanNurhidayat_0-1642297633661.png

 

log:

RahmanNurhidayat_1-1642297769870.png

please help me solve it.

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

Yes sketch creates geometries with a spatial reference that matches the spatial reference of the view. If your basemap's spatial reference is Web Mercator (102100) then you can use webMercatorUtils.webMercatorToGeographic() method to project the geometry to geographic spatial reference. 

You can do something like the following. 

sketch.on("create", (event) => {
  if (event.state === "complete") {
    console.log("sketch geometry", event.graphic.geometry);
    const geographicGeom = webMercatorUtils.webMercatorToGeographic(event.graphic.geometry);
            
     console.log("geographic geometry", geographicGeom)
  }
});

 

If your basemap's spatialReference is not WebMercator then you can use projection.project() method.

 

Hope this helps,

 

View solution in original post

3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Yes sketch creates geometries with a spatial reference that matches the spatial reference of the view. If your basemap's spatial reference is Web Mercator (102100) then you can use webMercatorUtils.webMercatorToGeographic() method to project the geometry to geographic spatial reference. 

You can do something like the following. 

sketch.on("create", (event) => {
  if (event.state === "complete") {
    console.log("sketch geometry", event.graphic.geometry);
    const geographicGeom = webMercatorUtils.webMercatorToGeographic(event.graphic.geometry);
            
     console.log("geographic geometry", geographicGeom)
  }
});

 

If your basemap's spatialReference is not WebMercator then you can use projection.project() method.

 

Hope this helps,

 

RahmanNurhidayat
New Contributor

Thanks. Its Worked

0 Kudos
Lazy
by
New Contributor

nice

0 Kudos