How can you get height and width in screen pixels of a rectangle drawn with the sketch widget?
Solved! Go to Solution.
Get the geometry (extent) use the xmin, ymin, xmax, ymax to create a points then the views toScreen method to get the point screen coordinates and do the math.
Get the geometry (extent) use the xmin, ymin, xmax, ymax to create a points then the views toScreen method to get the point screen coordinates and do the math.
Hi there,
You can listen to create event on the sketch. When the create operation is completed, check the tool that created a shape, then divide the rectangle polygon extent's width and height by the view resolution. This will give you the rectangle polygon's extent width and heights in pixels.
sketch.on("create", function(event){
// when draw rectangle create event is completed
if (event.state === "complete" && event.tool === "rectangle"){
console.log(event.graphic.geometry.extent.width / view.resolution, "pixels");
console.log(event.graphic.geometry.extent.height / view.resolution, "pixels");
}
});
Here is a doc for the MapView.resolution.
-Undral