I posted the following on StackOverflow and figured I might get better responses here, so I’ve attached the link to the stackoverflow post and a copy of the referenced question.
The first time I perform a middle click the map flies to a random location in the middle of the ocean. The project is using Resium (the Cesium react wrapper). The odd thing is that none of the examples on the cesium website have this issue.
Below are some of my attempts to try to address the middle click issue, but none of them are able to stop the event from occurring.
I am using cesium 1.73, but recently tried upgrading to cesium 1.76 and was still having this issue.
Any help would be much appreciated! Thanks in advance!
Here’s the code in my CesiumMap component where I am attempting to handle the middle click.
<Viewer
ref={e => this.getRef(e)}
...
>
<ScreenSpaceEventHandler useDefault element={this.canvas && this.viewer.canvas}>
<ScreenSpaceEvent
action={this.onMiddleClick}
type={ScreenSpaceEventType.MIDDLE_CLICK}
/>
</ScreenSpaceEventHandler>
</Viewer>
the Cesium reference
getRef = e => {
const me = this;
const { view, config } = this.props;
if (!this.viewer) {
this.viewer = e && e.cesiumElement;
if (this.viewer) {
// Handle click event
this.clickHandler =
this.clickHandler || new Cesium.ScreenSpaceEventHandler(scene.canvas);
this.clickHandler.setInputAction(movement => {
// maybe do something with the viewer here?
}, Cesium.ScreenSpaceEventType.MIDDLE_CLICK);
}
}
};
I also tried adding the following to my componentDidUpdate():
this.viewer.scene.canvas.addEventListener('auxclick', this._handleMiddleClick);
_handleMiddleClick:
_handleMiddleClick = e => {
e.preventDefault();
if (e.button === 1) {
console.log("middle button clicked");
}
};