-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cesium captures mouse click events #4126
Comments
This is a tricky issue because the prevention of default behavior is quite intentional. If we don't prevent default behavior, actions like panning the globe would have side effects of drag-selecting DOM elements in the vicinity of the canvas at the same time. If memory serves, the Geocoder widget has a better solution, I think it may be listening to the canvas (or the screenspaceeventhandler) and giving up its own focus voluntarily. It's worth double-checking what the Geocoder actually does, but I bet mimicking its behavior will yield better UX than enabling default event processing on the canvas. |
Here's my recommended workaround for this. Use this JS code in the same Sandcastle demo as @hpinkos HTML template above, to see the effects:
What happens here is that we set the Cesium canvas itself to have a The The reason this workaround is needed is because we intentionally prevent the default behavior for left-drags, otherwise the credit text and/or widgets would get the blue selection highlight every time you pan the globe. |
Here's a link to the completed workaround, with some restyling: I recommend we close this, unless people think the workaround belongs in Cesium. |
Thanks @emackey |
sorry, link is no longer active, can you please post it again? |
@emackey ema |
Apologies for the broken link. Try this: Sandcastle Demo CSS is here:
HTML:
JS:
|
Thanks @emackey In function setInputAction I have code something like this // Pick a new feature
var pickedFeature = viewer.scene.pick(movement.position);
if (!Cesium.defined(pickedFeature)) {
clickHandler(movement);
return;
}
} code above can run ok but when I get getProperty from pickedFeature selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';
viewer.selectedEntity = selectedEntity;
selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>' +
'<tr><th>BIN</th><td>' + pickedFeature.getProperty('BIN') + '</td></tr>' +
'<tr><th>DOITT ID</th><td>' + pickedFeature.getProperty('DOITT_ID') + '</td></tr>' +
'<tr><th>SOURCE ID</th><td>' + pickedFeature.getProperty('SOURCE_ID') + '</td></tr>' +
'<tr><th>Longitude</th><td>' + pickedFeature.getProperty('longitude') + '</td></tr>' +
'<tr><th>Latitude</th><td>' + pickedFeature.getProperty('latitude') + '</td></tr>' +
'<tr><th>Height</th><td>' + pickedFeature.getProperty('height') + '</td></tr>' +
'<tr><th>Terrain Height (Ellipsoid)</th><td>' + pickedFeature.getProperty('TerrainHeight') + '</td></tr>' +
'</tbody></table>'; I always get errors "Uncaught TypeError: pickedFeature.getProperty is not a function"! |
Clicking on the Cesium viewer prevents focus being removed from other page elements. In this example, I added an input textbox that turns red when it has focus and white when it loses it. If you click in the textbox to focus, then click in Cesium, you'll see the textbox stays red. However if you click elsewhere in the sandcastle app the textbox correctly loses focus. I think this is happening because Cesium is capturing the click event and preventing any default behavior, but I'm not 100% sure. I know this isn't the default behavior for a canvas though, I checked that with a tiny JSFiddle demo
This gets frustrating when an Cesium has form elements have behavior that relies on focus and clicking away from the element and onto the canvas doesn't produce the expected behavior.
The text was updated successfully, but these errors were encountered: