Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas)
// Now wait for start
mouseHandler.setInputAction(movement => {
if (movement.position != null) {
const cartesian = scene.camera.pickEllipsoid(
movement.position,
ellipsoid
)
if (cartesian) {
markers.addBillboard(cartesian)
_self.stopDrawing()
options.callback(cartesian)
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
mouseHandler.setInputAction(movement => {
const position = movement.endPosition
if (position != null) {
const cartesian = scene.camera.pickEllipsoid(position, ellipsoid)
if (cartesian) {
tooltip.showAt(
position,
'<p>Click to add your marker. Position is: </p>' +
getDisplayLatLngString(
ellipsoid.cartesianToCartographic(cartesian)
)
)
} else {
tooltip.showAt(
position,
start() {
this.disableInput()
const that = this
// Now wait for start
this.mouseHandler.setInputAction(movement => {
that.handleRegionStart(movement)
}, Cesium.ScreenSpaceEventType.LEFT_DOWN)
},
handleRegionStart(movement) {
const cartesian = this.options.map.scene.camera.pickEllipsoid(
movement.position,
this.options.map.scene.globe.ellipsoid
),
that = this
if (cartesian) {
// var that = this;
this.click1 = this.options.map.scene.globe.ellipsoid.cartesianToCartographic(
cartesian
)
this.mouseHandler.setInputAction(() => {
that.buttonPressed = false
that.handleRegionStop()
}, Cesium.ScreenSpaceEventType.LEFT_UP)
this.mouseHandler.setInputAction(movement => {
that.buttonPressed = true
that.handleRegionInter(movement)
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
}
},
start() {
imageryProvider: false, // prevent default imagery provider
mapMode2D: 0,
},
})
// disable right click drag to zoom (context menu instead);
viewer.scene.screenSpaceCameraController.zoomEventTypes = [
Cesium.CameraEventType.WHEEL,
Cesium.CameraEventType.PINCH,
]
viewer.screenSpaceEventHandler.setInputAction(() => {
if (!store.get('content').get('drawing')) {
$('body').mousedown()
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN)
viewer.screenSpaceEventHandler.setInputAction(() => {
if (!store.get('content').get('drawing')) {
$('body').mousedown()
}
}, Cesium.ScreenSpaceEventType.RIGHT_DOWN)
setupTerrainProvider(viewer, properties.terrainProvider)
return viewer
}
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(
scene.canvas
)
this._globeClickhandler.setInputAction(movement => {
const pickedObject = scene.pick(movement.position)
// disable edit if pickedobject is different or not an object
if (
!(
pickedObject &&
!pickedObject.isDestroyed() &&
pickedObject.primitive
)
) {
extent.setEditMode(false)
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
// set on top of the polygon
markers.setOnTop()
}
this._editMode = true
} else {
if (this._markers != null) {
this._markers.remove()
this._markers = null
this._globeClickhandler.destroy()
}
this._editMode = false
}
}
const value = getExtent(firstPoint, firstPoint)
updateExtent(value)
} else {
_self.stopDrawing()
if (typeof options.callback == 'function') {
options.callback(
getExtent(
firstPoint,
ellipsoid.cartesianToCartographic(cartesian)
)
)
}
}
}
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN)
mouseHandler.setInputAction(movement => {
const position = movement.endPosition
if (position != null) {
if (extent == null) {
tooltip.showAt(position, '<p>Click to start drawing rectangle</p>')
} else {
const cartesian = scene.camera.pickEllipsoid(position, ellipsoid)
if (cartesian) {
const value = getExtent(
firstPoint,
ellipsoid.cartesianToCartographic(cartesian)
)
updateExtent(value)
tooltip.showAt(
position,
callbacks.dragHandlers.onDragEnd(getIndex(), position)
}
var handler = new Cesium.ScreenSpaceEventHandler(_self._scene.canvas)
handler.setInputAction(movement => {
const cartesian = _self._scene.camera.pickEllipsoid(
movement.endPosition,
ellipsoid
)
if (cartesian) {
onDrag(cartesian)
} else {
onDragEnd(cartesian)
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
handler.setInputAction(movement => {
onDragEnd(
_self._scene.camera.pickEllipsoid(movement.position, ellipsoid)
)
}, Cesium.ScreenSpaceEventType.LEFT_UP)
enableRotation(false)
callbacks.dragHandlers.onDragStart &&
callbacks.dragHandlers.onDragStart(
getIndex(),
_self._scene.camera.pickEllipsoid(position, ellipsoid)
)
})
}
handleRegionStart(movement) {
const cartesian = this.options.map.scene.camera.pickEllipsoid(
movement.position,
this.options.map.scene.globe.ellipsoid
),
that = this
if (cartesian) {
this.click1 = this.options.map.scene.globe.ellipsoid.cartesianToCartographic(
cartesian
)
this.mouseHandler.setInputAction(() => {
that.handleRegionStop()
}, Cesium.ScreenSpaceEventType.LEFT_UP)
this.mouseHandler.setInputAction(movement => {
that.handleRegionInter(movement)
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
}
},
start() {
EventManager.prototype.commit = function () {
var _this = this;
var sshe = this.sshe;
var destroyed = this.sshe.isDestroyed();
var elements = new Set(this.hovered.keys());
var elements2 = new Set();
if (!destroyed) {
if (this.events.onMouseEnter.size === 0 &&
this.events.onMouseLeave.size === 0 &&
this.events.onMouseMove.size === 0) {
this.sshe.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
else if (!this.sshe.getInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)) {
this.sshe.setInputAction(this.onMouseMove, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
}
Object.entries(this.events).forEach(function (_a) {
var et = _a[0], m = _a[1];
var eventType = et;
m.forEach(function (v, k) {
if (!_this.hovered.has(k)) {
_this.hovered.set(k, false);
}
elements2.add(k);
});
if (et === "onMouseEnter" || et === "onMouseLeave" || et === "onMouseMove") {
return;
}
var cesiumEventType = EventManager.eventTypeMap[eventType];