forge Viewer - Markup camera change issue - autodesk-forge

In my viewer, I have a markup plotted using cloud mode and during camera change event, am not able to map the associated label with the markup as it moves on.
To make this work I store coordinates and while camera change event I use worldToClient to find the new coordinates, but this is not working
So problem is with finding original world coordinates. I tried multiple ways as below, but nothing seems to work for me. Much appreciate help on this. Just for an idea on this, am attaching screen-shots of model before and after camera change.
/*** option 1***/
worldCoord = markup.markups[0].generateBoundingBox().max;
/*** option 2***/
var coords = viewer.impl.clientToViewport(pos.x, pos.y);
worldCoord = coords.unproject(viewer.impl.camera)
/*** option 3***/
worldCoord = markup.markups[0].getClientPosition()
/*** option 4***/
worldCoord = viewer.clientToWorld(pos.x,pos.y,true);
/***option 5***/
worldCoord = markup.markups[0].getBoundingRect()

Finally I got it.
We can store layername info with your label and fetch it in your camera change event using below code.
position = markup.svgLayersMap[layerName].markups[0].getClientPosition()
hope this helps someone

Related

Geo Location on click _ Forge viewer

i'm looking for some guidance on how best to display real world coordinates when i click on the screen or select a model element in the forge viewer.
i have had a look around and done some research but with little success, however i have found this post that helps however the coordinate read out seems to be completely diffent to the cordantes that i would expect to see.
https://github.com/apprentice3d/ForgeViewerExtensions/blob/master/assets/js/extensions/transformationExplorer.js
As you can tell i dont know much about the viewer geo extension, any guidance on this would be great.
Thanks Tom.
If it's enough to get the world coordinates of a point you clicked on in the viewer, you can simply use the viewer's clientToWorld method, for example like so:
viewer.container.addEventListener('click', function (ev) {
const result = viewer.clientToWorld(ev.clientX, ev.clientY);
if (result) {
console.log(result.point);
}
});
i managed to get it to work by using NOP_VIEWER.model.getData().globalOffset
Example
this.infoX.innerText = nodeData.position.x + NOP_VIEWER.model.getData().globalOffset.x;

how to change a CesiumJS viewer's baselayer url

i am using a CesiumJS instance to display a base map of the earth using a imageryProvider from source A.
var viewer = new Cesium.Viewer('cesiumContainer', imageryProvider:providerA);
Now while using the Viewer I would like to be able to change this map to get images from providerB at a certain event.
I tried:
viewer.scene.imageryLayers.get(0).imageryProvider.url = providerB.url
However that does not seem to work and also feels quite like hack anyway.
I could not find anything in Cesium's documentation .
Is this at all possible without restarting / recreating the viewer instance?
I know that there is a Cesium.BaseLayerPicker (https://cesium.com/docs/cesiumjs-ref-doc/BaseLayerPicker.html)
However I do not see what method this picker calls on "select" )
Thanks a lot.
The BaseLayerPicker widget calls this code when the user selects a new layer.
There's a lot of boilerplate widget management in that block of code, but for your sake, only a couple of the lines are critical. First, the old existing active imagery layer is searched for, and removed:
imageryLayers.remove(layer);
Then, a new imagery provider is constructed and added at index 0, the first position, which is the base imagery layer:
imageryLayers.addImageryProvider(newProviders, 0);
You can directly change the URL of the provider but you should also change appropriate parameters("layers" in case of WMS, "layer", "style", "format", "tileMatrixSetID " ... in case of WMTS) depending on the type of provider(WMS or WMTS).

How to detect HOVER/CLICKS in Starling button with LeapMotionAS3

I want to click on Starling buttons using the LeapMotion SCREEN_TAP gesture.
This is possible? To click the Starling button and see the regular push/shrink effect on it using this gesture?
If not...what is the best approach to achieve this?
Any help is welcome!
Regards.
I assume you could do this (I have never done it but I think it should work):
Check whether the tap's coordinates are over the button
If they are, swap the button's texture: var up:Texture = btn.upState; //save reference
btn.upState = btn.downState;
After X milliseconds swap them back: btn.upState = up;

How to apply mouse Click event for 3D model

Added 3D collada (.dae) file in to a scene. The 'DAE' file contains geometry with the name "monster" and the id is "monster-mesh-skin". I tried to apply mouse click event to the geometry "monster". like,
var monster = dae.getChildByName("monster"); // get geometry
monster.addEventListener("click", meshClickHandler);
The click event is not working. And I tried THREE.Vector3() and THREE.Ray like,
var mouse3D = new THREE.Vector3();
mouse3D.x = event.clientX;
mouse3D.y = event.clientY;
mouse3D.z = 0.5;
var ray = new THREE.Ray(mouse3D);
var intersects = ray.intersectObjects(monster);
console.dir(intersects);
on document click handler. In intersects variable not contain any value.
Is there any solution to apply mouse event for 3D model and control it?
It appears you need to rethink the approach a bit. Any 3D object in your scene exists exclusively as a 2D "drawing" of an object and itself can not have standard DOM event handlers attached to it.
What you want is a general event listener on the document itself to capture mouse clicks, like so:
document.addEventListener( 'click', detectIntersect, false );
Now, there are a ton of example right in Three.js example directory that can show you exactly how to "click your object", but in 3D terms it's refered to as object picking or raycasting an object. These terms might help when searching for examples/help. Have a look at these examples:
http://threejs.org/examples/webgl_interactive_cubes.html
http://threejs.org/examples/canvas_interactive_cubes_tween.html
One last note, it appears your using r57 or earlier of the Three.js library. I would suggest upgrading to the latest build as getting support from the community is easier when were all on the same page :)
Hope that helps, take care.

Detect which poi is clicked in mapquest flash

So i am trying to get a workaround solution on the problem of mobile mapquest not supporting infowindows with flex components. i managed to create a custom handler for the pois. however i cant figure out how to detect which poi was clicked. all the pois are stored in a shapecollection and i would like to be able to detect which was clicked in order to push its data to another view. any ideas?
after a few days researching and trying different methods i found the solution within the flex itshelf. So here is my solution and I hope that more people can use this to their mobile apps.
var p: Poi = new Poi(myLatLng);
p.key = "myKey";
p.addEventListener(MouseEvent.CLICK,this.onPoiClick);
private function onPoiClick(e:MouseEvent):void {
var poi: Poi = e.currentTarget as Poi;
trace("The Poi's key is: " + poi.key);
}
Special thanks to the mapquest forums for helping out