vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
2.03k stars 301 forks source link

Zoom to certain point or resoluatin level #43

Open jingyan-li opened 3 years ago

jingyan-li commented 3 years ago

Is it possible to zoom to a certain point by its coordinate or set the zoom-in or zoom-out level of the camera? When I try to add a globe to a storytelling website, I really hope the camera can move along some trajectories to help me tell the story.

vasturiano commented 3 years ago

@jingyan-li have you looked at the pointOfView method?

tamegeek commented 2 years ago

Hi @vasturiano I think I'm having a similar issue as this person. I have used pointOfView on my initial rendering of the globe, but I need to know the best way to change the pointOfView when clicking on a specific DOM element.

vasturiano commented 2 years ago

@tamegeek this is the method signature of pointOfView:

pointOfView({ lat, lng, altitude }, [ms])

You can invoke this method at any time, and all of the parameters are optional (though you should include at least one otherwise there's no change).

Which specific issue are you experiencing with it?

tamegeek commented 2 years ago

Hi @vasturiano thanks for coming back to me! I got the point of view resolved, however, the issue I now face is that I would like to be able to do a JS action when one of the hotspots is clicked. The action is outside of the of the globeViz div. I have an example Pen here, where you can see that the ID of the blue dot on the UK should be changing the text from demo to hello world at the top of the pen. Any advice on this would be greatly appreciated! CodePen: https://codepen.io/tamegeek/pen/vYJoOQR?editors=0011

vasturiano commented 2 years ago

@tamegeek have you looked at .onLabelClick(labelObj => ...)?

tamegeek commented 2 years ago

I have but i'm going to have multiple IDs (so each hotspot will trigger a different action) and I've not been able to find a working example in your doc (sorry if I have missed it)

vasturiano commented 2 years ago

The first argument in the callback gives you access to the label object itself, so you can use it to choose which action should be carried out.

ishaiavrahami commented 1 year ago

the proper way to get the globe transition to the selected/clicked dot is by having

 .onHexPolygonClick((data, clickData, coord) => {
      globe.pointOfView(coord, 300);
})

The third param coord exports {lat, lng, altitude} of where the polygon is placed on the globe.

Hope this helps!