How to use the @here/harp-mapview.MapViewUtils.rayCastWorldCoordinates function in @here/harp-mapview

To help you get started, we’ve selected a few @here/harp-mapview examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
Math.min(
                        maxDistance + geoUtils.EarthConstants.EQUATORIAL_RADIUS,
                        this.camera.position.length() + zOnVertical
                    )
                )
            );
        }

        // In sphere, we may have to also orbit the camera around the position located at the
        // center of the screen, in order to limit the tilt to `maxTiltAngle`, as we change
        // this tilt by changing the camera's height above.
        if (
            this.mapView.projection.type === geoUtils.ProjectionType.Spherical &&
            this.m_maxTiltAngle !== undefined
        ) {
            const centerScreenTarget = MapViewUtils.rayCastWorldCoordinates(this.mapView, 0, 0);
            if (centerScreenTarget !== null) {
                const tilt = MapViewUtils.extractSphericalCoordinatesFromLocation(
                    this.mapView,
                    this.camera,
                    this.mapView.projection.unprojectPoint(centerScreenTarget)
                ).tilt;
                const deltaTilt = tilt - this.m_maxTiltAngle;
                if (deltaTilt > 0) {
                    MapViewUtils.orbitFocusPoint(this.mapView, 0, deltaTilt, this.m_maxTiltAngle);
                }
            }
        }

        this.updateMapView();
        this.mapView.addEventListener(
            MapViewEventNames.AfterRender,
github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
let elevationProviderResult: THREE.Vector3 | undefined;

        if (this.mapView.elevationProvider !== undefined) {
            elevationProviderResult = this.mapView.elevationProvider.rayCast(fromX, fromY);
        }

        if (elevationProviderResult === undefined) {
            fromWorld = MapViewUtils.rayCastWorldCoordinates(this.mapView, from.x, from.y);
            toWorld = MapViewUtils.rayCastWorldCoordinates(this.mapView, to.x, to.y);
        } else {
            fromWorld = elevationProviderResult;
            const fromGeoAltitude = this.mapView.projection.unprojectAltitude(fromWorld);

            // We can ensure that points under the mouse stay there by projecting the to point onto
            // a plane with the altitude based on the initial point.
            toWorld = MapViewUtils.rayCastWorldCoordinates(
                this.mapView,
                to.x,
                to.y,
                fromGeoAltitude
            );
        }
        if (fromWorld === null || toWorld === null) {
            return;
        }
        return { fromWorld, toWorld };
    }
github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
this.m_state = State.TOUCH;
            return {
                currentTouchPoint: newTouchPoint,
                lastTouchPoint: newTouchPoint,
                currentWorldPosition: toWorld,
                initialWorldPosition: toWorld
            };
        } else {
            const { width, height } = utils.getWidthAndHeightFromCanvas(this.domElement);
            const to = utils.calculateNormalizedDeviceCoordinates(
                newTouchPoint.x,
                newTouchPoint.y,
                width,
                height
            );
            const result = MapViewUtils.rayCastWorldCoordinates(this.mapView, to.x, to.y);
            const toWorld = result === null ? new THREE.Vector3() : result;
            // Unless the user is tilting, considering a finger losing the surface as a touchEnd
            // event. Inertia will get triggered.
            if (
                toWorld.length() === 0 &&
                !(this.m_touchState.touches.length === 3 && this.tiltEnabled)
            ) {
                this.setTouchState([] as any);
                this.m_state = State.NONE;
                this.dispatchEvent(MAPCONTROL_EVENT_END_INTERACTION);
                return;
            }
            if (this.m_state !== State.TOUCH) {
                this.dispatchEvent(MAPCONTROL_EVENT_BEGIN_INTERACTION);
            }
            this.m_state = State.TOUCH;
github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
const from = utils.calculateNormalizedDeviceCoordinates(fromX, fromY, width, height);
        const to = utils.calculateNormalizedDeviceCoordinates(toX, toY, width, height);

        let toWorld: THREE.Vector3 | null;
        let fromWorld: THREE.Vector3 | null;

        let elevationProviderResult: THREE.Vector3 | undefined;

        if (this.mapView.elevationProvider !== undefined) {
            elevationProviderResult = this.mapView.elevationProvider.rayCast(fromX, fromY);
        }

        if (elevationProviderResult === undefined) {
            fromWorld = MapViewUtils.rayCastWorldCoordinates(this.mapView, from.x, from.y);
            toWorld = MapViewUtils.rayCastWorldCoordinates(this.mapView, to.x, to.y);
        } else {
            fromWorld = elevationProviderResult;
            const fromGeoAltitude = this.mapView.projection.unprojectAltitude(fromWorld);

            // We can ensure that points under the mouse stay there by projecting the to point onto
            // a plane with the altitude based on the initial point.
            toWorld = MapViewUtils.rayCastWorldCoordinates(
                this.mapView,
                to.x,
                to.y,
                fromGeoAltitude
            );
        }
        if (fromWorld === null || toWorld === null) {
            return;
        }
github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
pointToNorth() {
        const target = MapViewUtils.rayCastWorldCoordinates(this.mapView, 0, 0);
        if (target === null) {
            throw new Error("MapView does not support a view pointing in the void.");
        }
        this.m_startAzimuth =
            Math.PI +
            MapViewUtils.extractSphericalCoordinatesFromLocation(
                this.mapView,
                this.camera,
                this.mapView.projection.unprojectPoint(target)
            ).azimuth;
        // Wrap between -PI and PI.
        this.m_startAzimuth = Math.atan2(
            Math.sin(this.m_startAzimuth),
            Math.cos(this.m_startAzimuth)
        );
        if (this.m_startAzimuth === 0) {
github heremaps / harp.gl / @here / harp-map-controls / lib / MapControls.ts View on Github external
private get currentTilt(): number {
        const target = MapViewUtils.rayCastWorldCoordinates(this.mapView, 0, 0);
        if (target === null) {
            throw new Error("MapView does not support a view pointing in the void.");
        }
        return MapViewUtils.extractSphericalCoordinatesFromLocation(
            this.mapView,
            this.camera,
            this.mapView.projection.unprojectPoint(target)
        ).tilt;
    }
github heremaps / harp-map-editor / src / map-editor / map-handler / index.ts View on Github external
this.onMapRender = () => {
            if (this.m_mapView === null || this.m_controls === null) {
                return;
            }
            const targetWorld = MapViewUtils.rayCastWorldCoordinates(this.m_mapView, 0, 0);
            const target = this.m_mapView.projection.unprojectPoint(targetWorld!);
            const state = new MapViewState(
                this.m_mapView.lookAtDistance,
                target,
                -this.m_controls.attitude.yaw,
                this.m_controls.attitude.pitch
            );
            this.m_mapViewState = state;
            this.emitStateUpdate();
        };