javascript - Datamaps are showing small size map of India -
hi trying create map datamap , d3 js. showing map in reverse , small in size. how can resolve this. sharing js fiddle same.
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"></script> <script src="https://raw.githubusercontent.com/markmarkoh/datamaps/master/dist/datamaps.ind.js"></script> <div id="container" style="position: relative; width: 500px; height: 300px;"></div> var map = new datamap({ element: document.getelementbyid('container'), scope: 'ind' });
you need tell center , projection. add code:
setprojection: function(element) { var projection = d3.geo.equirectangular() .center([80, 25]) .scale(600) .translate([element.offsetwidth / 2, element.offsetheight / 2]); var path = d3.geo.path() .projection(projection); return {path: path, projection: projection}; }
center of india: 20.5937° n, 78.9629° e
complete code:
var map = new datamap({ element: document.getelementbyid('container'), scope: 'ind', setprojection: function(element) { var projection = d3.geo.equirectangular() .center([80, 25]) .scale(600) .translate([element.offsetwidth / 2, element.offsetheight / 2]); var path = d3.geo.path() .projection(projection); return {path: path, projection: projection}; } });
tip: can change projection type to: mercator
projection: 'mercator',
that give flat map intead of rounded globe type.
hope help
Comments
Post a Comment