I tried to modify the widget for displaying map coordinates alongside it. However, when I launched it, I noticed that the ActiveViewChange function does not execute. Below is my widget's code.
export default class Widget extends React.Component<AllWidgetProps<IMConfig>, any>{
constructor(props) {
super(props);
}
ActiveViewChange = (jmv: JimuMapView): void => {
console.log(jmv)
}
render() {
return (
<div className="widget-demo jimu-widget m-2">
{this.props.hasOwnProperty("useMapWidgetIds") &&
this.props.useMapWidgetIds &&
this.props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent
useMapWidgetId={this.props.useMapWidgetIds?.[0]}
onActiveViewChange={this.ActiveViewChange}
/>
)}
<p><FormattedMessage id="pr" defaultMessage={defaultMessages.pr} /></p>
</div>
)
}
}
Is there anyone who might have an idea about the issue?
Solved! Go to Solution.
The code above will get the first JimuMapView in an Experience, but because it is not dependent onActiveViewChange, it will not fail even if this widget loads before JimuMapView is created. You may need to add if checks for mapView to prevent other errors, especially on the first render of this widget.
The onActiveViewChange function may not operate the way you think it does. It only activates if the entire mapView is changed, as in the the entire map object is replaced with a completely separate map object. It is rarely if ever activated in most Experience Builder applications.
Does this explain your issue?
I agree with you. However, upon display, it must still execute the function so that I can retrieve my jimuMapView, which should be displayed in the console.log().
I typically get the mapView with these two lines. They do not need to be within the onActiveViewChange function.
const viewManager = MapViewManager.getInstance()
const mapView = viewManager.getJimuMapViewById(viewManager.getAllJimuMapViewIds()[0])
This code will allow you to retrieve the MapView from the widget inside the 'Carte' widget in question. My goal is to obtain the MapView of a 'Carte' widget from another widget, and to achieve that, I am required to go through JimuMapViewcomponent.
The code above will get the first JimuMapView in an Experience, but because it is not dependent onActiveViewChange, it will not fail even if this widget loads before JimuMapView is created. You may need to add if checks for mapView to prevent other errors, especially on the first render of this widget.