Hallo,
I am trying to develop a widget in experience builder. The purpose is, when the user presses a button, the app to retrieve all the user's drawings that exist on the map, in order to get their geometry. This is my code so far, but it seems that it doesn't work correctly. The function getGraphics() works, but the drawings on the map can’t be read.
import { React, AllWidgetProps } from 'jimu-core'
import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
import { Button } from 'jimu-ui';
const { useState } = React
const Widget = (props: AllWidgetProps<any>) => {
const [jmv, setJimuMapView] = useState<JimuMapView>()
const activeViewChangeHandler = (jimuMapView: JimuMapView) => {
if (jimuMapView) {
setJimuMapView(jimuMapView)
}
}
function getGraphics(){
const graphicDrawings = jmv.view.graphics.toArray()
if(graphicDrawings.length > 0) {
console.log("graphics on map")
}
else{
console.log('no graphics on map')
}
}
return (
<div className="widget-starter jimu-widget">
{
props.useMapWidgetIds &&
props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent
useMapWidgetId={props.useMapWidgetIds?.[0]}
onActiveViewChange={activeViewChangeHandler}
/>
)
}
<Button type="primary" onClick={getGraphics}>
</Button>
</div>
)
}
export default Widget
Appreciate if you can help me…Thank you!