Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addMouseEventListener(mapView: MapView) {
const canvas = mapView.canvas;
mapView.zoomLevel = 15.5;
// tslint:disable:no-unused-expression
new LongPressHandler(canvas, event => {
// snippet:harp_gl_threejs_add_simple_object_1.ts
// Get the position of the mouse in geo space.
const geoPosition = mapView.getGeoCoordinatesAt(event.pageX, event.pageY);
if (geoPosition === null) {
return;
}
// end:harp_gl_threejs_add_simple_object_1.ts
// snippet:harp_gl_threejs_add_simple_object_2.ts
const cube = createPinkCube();
cube.geoPosition = geoPosition;
mapView.mapAnchors.add(cube);
// end:harp_gl_threejs_add_simple_object_2.ts
// end:harp_gl_threejs_add_simple_object_3.ts
// Request an update once the cube [[MapObject]] is added to [[MapView]].
map.lookAt(NY, 2000, 50);
// Add an UI.
const ui = new MapControlsUI(mapControls);
canvas.parentElement!.appendChild(ui.domElement);
// Resize the mapView to maximum.
map.resize(window.innerWidth, window.innerHeight);
// React on resize events.
window.addEventListener("resize", () => {
map.resize(window.innerWidth, window.innerHeight);
});
// tslint:disable:no-unused-expression
new LongPressHandler(canvas, event => {
// snippet:harp_gl_threejs_raycast_0.ts
const pickResults = map.intersectMapObjects(event.pageX, event.pageY);
if (pickResults.length === 0) {
return;
}
// end:harp_gl_threejs_raycast_0.ts
// snippet:harp_gl_threejs_raycast_1.ts
const worldPoint = new THREE.Vector3();
// Pick results is sorted by distance, so we choose the first point in 3D.
for (const pick of pickResults) {
if (pick.point instanceof THREE.Vector3) {
worldPoint.copy(pick.point);
// Points returned from the intersectMapObjects are in local space, hence we
// transform to actual world space.
worldPoint.add(map.worldCenter);