D3 DataMaps (or jvectormap): How to put a custom object on map by coords
Asked Answered
T

1

10

For example I want to add a custom html object to wold map by gps coords (lat, lng) - like pulsating dot done with css or any other(js?) marker animation

<style>

#circle {
    background: red;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;

}

.gps_ring {
    border: 3px solid red;
    -webkit-border-radius: 30px;
    height: 18px;
    width: 18px;

    left:20px;
    top:214px;
    -webkit-animation: pulsate 1s ease-out;
    -webkit-animation-iteration-count: infinite; 
    opacity: 0.0
}
@-webkit-keyframes pulsate {
    0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
    50% {opacity: 1.0;}
    100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}
</style>

<div id="state" class="grid_4 alpha">
    <div class="gps_ring"></div>

</div>
Tropology answered 12/8, 2016 at 15:17 Comment(0)
B
2

You can get x, y coordinates from projection:

var projection = d3.geo.mercator()
            .center([0, 5 ])
            .scale(150);

projection([long, lat]);

For animation you could either use either d3 transitions example or CSS.

I have created a block for you: http://bl.ocks.org/ckothari/32149f15261b9c5c7a56c40f7f6b353d

EDIT Sorry, just realized your question was about using http://datamaps.github.io/. Let me know if you can use topojson, else i will delete my answer.

EDIT-2 To color country:

d3.tsv('data.csv', function(data){
            g.selectAll('path')
                    .filter(function(d){
                        return data.find(function(d1){
                            return d1.iso == d.properties.iso_a2;
                        })
                    })
                    .attr('class', 'selected');
   //...
 })

EDIT-3 Chaining transitions Updated example: https://bl.ocks.org/ckothari/raw/32149f15261b9c5c7a56c40f7f6b353d/

Also see http://bl.ocks.org/mbostock/1125997.

Bolognese answered 16/8, 2016 at 11:41 Comment(6)
great, but is there a way to somehow highlight a country with a color?Tropology
yes, you can select paths, filter it on iso or the country you want to color and apply fill attribute.Bolognese
one more question - is there a way to make different pulse time animation for every circle? ThanksTropology
here are different ease functions available: github.com/d3/d3-3.x-api-reference/blob/master/…Bolognese
I mean when function calls "var circle = g.selectAll("circle");" then it selects all circle and set them one pulse time animation. I want every circle to pulsate by it own timing. When one starts to increase the other one should decreaseTropology
glad to have helped :)Bolognese

© 2022 - 2024 — McMap. All rights reserved.