Can someone guide me on how to release the onClick event? we have this setup in webapp builder but have not found the way to do it in Experience builder, see code
import { React, type AllWidgetProps, type Color } from 'jimu-core'
import { JimuMapViewComponent, type JimuMapView } from 'jimu-arcgis'
import type Point from 'esri/geometry/Point'
import Graphic from 'esri/Graphic'
const { useState } = React
const linkButton = {
display: 'block',
color: '#f2f2f2',
backgroundColor: '#3C73BD',
fontWeight: 'bold',
padding: '12px 15px',
fontFamily: 'Sans-Serif',
borderRadius: '50px',
textAlign: 'center',
textDecoration: 'none'
}
// interface State {
// jimuMapView: JimuMapView
// }
const Widget = (props: AllWidgetProps<any>) => {
const [latitude, setLatitude] = useState<string>('')
const [longitude, setLongitude] = useState<string>('')
const mainURL = url + latitude + ' ' + longitude
const [visible, setVisible] = React.useState(false)
// const [graphic, setGraphic] = useState(null);
const activeViewChangeHandler = (jmv: JimuMapView) => {
// if (this.state.jimuMapView) {
// if (this.state.currentWidget) {
// this.state.currentWidget.destroy()
// }
// }
if (jmv) {
// When the pointer moves, take the pointer location and create a Point
// Geometry out of it (`view.toMap(...)`), then update the state.
const simpleMarkerSymbol = {
type: 'simple-marker',
color: [226, 119, 40], // Orange
outline: {
color: [255, 255, 255], // White
width: 1
}
}
jmv.view.on('click', evt => {
const point: Point = jmv.view.toMap({
x: evt.x,
y: evt.y
})
setLatitude(point.latitude.toFixed(8))
setLongitude(point.longitude.toFixed(8))
setVisible(true)
const graphic = new Graphic({
geometry: point,
symbol: simpleMarkerSymbol
})
// setGraphic(graphic);
jmv.view.graphics.removeAll()
jmv.view.graphics.add(graphic)
})
}
}
return (
<div className="widget-starter jimu-widget">
{
props.useMapWidgetIds &&
props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent
useMapWidgetId={props.useMapWidgetIds?.[0]}
onActiveViewChange={activeViewChangeHandler}
/>
)
}
<p><h9>Click on Map to get the coordinates </h9></p>
<div style={ { display: visible ? 'block' : 'none' } }>
<div>
<p style={{ textAlign: 'center' }}><strong>Lat/Lon: {latitude} {longitude}</strong> </p>
{/* <p style={myStyle}><button onClick={ () => openLinkInNewTab(mainURL)}>View in Google Maps!</button></p> */}
<a style={linkButton} href={mainURL} target='_blank'>View in Google Maps</a>
</div>
</div>
</div>
)
}
export default Widget