Closed joshuaiz closed 6 years ago
Still stuck on this...anyone?
Once the globe is initialized (In your case after redraw()), you can provide your desired destination.
function rotate2Destination(dest) {
nextRotate = [dest.longitude * -1, dest.latitude * -1];
d3.select("g")
.transition()
.attrTween("d", function (d) {
var r = d3.interpolate(globalRotation, nextRotate);
return function (t) {
globalRotation = r(t);
return redraw();
};
})
.duration(3000);
}
And once this rotation is completed you can Add legends/arcs/bubbles/highlightRegions etc.
Hi @zaryab91 - thanks for this. I'm still stuck on how to target the respective region. In my case, I have say a
But thanks so much - I think this gets me a lot closer.
Hi @joshuaiz, the above-provided function is a custom made function. Since globalRotation is an array of [long, lat] and for rotation, you need a combination of [long,lat] that too with inverted signs. Whereas the ISO class will give you lat-long. If you are able to fetch the underlying information from ISO you can modify this function accordingly.
@zaryab91 got it.
This is what worked for me: I dragged/rotated the globe to each of the countries I wanted links for and got the long
and lat
for each one. In my case, it is only a few countries.
I then added the coordinates as data attributes to my link like so:
<a class="partner-name" data-longitude="68.40" data-latitude="39.84">Argentina</a>
Then here is my jQuery click handler:
$('a[data-id]').on('click', function() {
var long = $(this).data('longitude');
var lat = $(this).data('latitude');
rotate2Destination(long, lat);
})
And then a slightly adjusted function from above, sending the long,lat as parameters:
function rotate2Destination(long, lat) {
nextRotate = [long, lat];
d3.select("g")
.transition()
.attrTween("d", function (d) {
var r = d3.interpolate(globalRotation, nextRotate);
return function (t) {
globalRotation = r(t);
return redraw();
};
})
.duration(3000);
}
The -1
in the original function weren't working but just sending the coordinates directly works.
An improvement on this would be to get the coordinates programmatically. Anyway, I'm pretty happy with this so thanks again.
Going to close this but thanks @zaryab91 again for the help!
I'm have a legend with names of the specific countries I have highlighted on a world map using the orthographic projection.
I have the basic orthographic globe working here: https://studiobiodev.com/jb.dev/wp/partners/
What I would like to achieve is to click on a country name (on the left) and then have the map rotate and center on that country.
The closest thing I have found is this oft cited example: https://bl.ocks.org/mbostock/4183330 but I don't really know how to integrate what's there with Datamaps.
Any help or pointers in the right direction would be great. Thanks!
Here is my current code including qTip2 popups (instead of the built-in Datamaps popups):