d3.js - How to change point size using geojson file in D3 -
i need little help. think primitive question stuck @ point. have map in orthographic projection in d3 , geojson file contains points representing earthquakes. able display points. have same size. want change size of each point refering "mag" number in geojson file. can me please? here code:
<!doctype html> <meta charset="utf-8"> <meta http-equiv="refresh" content="300" /> <style> .graticule { fill: none; stroke: black; stroke-width:.5; opacity:.1; } .land { fill: rgb(117, 87, 57); stroke: black; stroke-opacity: .2; } </style> <body> <body background="space5.jpg"> <div id="map"></div> <script src="d3.v3.min.js"></script> <script src="topojson.v0.min.js"></script> <script> var diameter = 700, radius = diameter/2, velocity = .005, = date.now(); var projection = d3.geo.orthographic() .scale(radius - 2) .translate([radius, radius]) .clipangle(90); var graticule = d3.geo.graticule(); var svg = d3.select("body").append("svg") .attr("width", diameter) .attr("height", diameter); var path = d3.geo.path() .projection(projection) var ocean_fill = svg.append("defs").append("radialgradient") .attr("id", "ocean_fill") .attr("cx", "75%") .attr("cy", "25%"); ocean_fill.append("stop").attr("offset", "55%").attr("stop-color", "#ddf"); ocean_fill.append("stop").attr("offset", "100%").attr("stop-color", "#9ab"); //load sphere var globe = {type: "sphere"}; svg.append("path") .datum(globe) .attr("d", path) .style("fill", "url(#ocean_fill)"); //graticule svg.append("path") .datum(graticule) .attr("class", "graticule") .attr("d", path); //load countries d3.json("world-110m.json", function(error, topology) { var land = topojson.object(topology, topology.objects.countries), globe = {type: "sphere"}; svg.insert("path") .datum(topojson.object(topology, topology.objects.countries)) .attr("class", "land") .attr("d", path); }); //load earthquakes d3.json("2.5_day.geojson", function(json) { svg.selectall("path.day") .data(json.features) .enter() .append("path") .attr("d",path) .style("fill", "red") }); //rotate d3.timer(function() { var angle = velocity * (date.now() - then); projection.rotate([angle,0,0]); svg.selectall("path") .attr("d", path); }); </script> </body> </html> and here part of geojson file (just 1 point):
{ type: "featurecollection", metadata: { generated: 1396609484000, url: http://..., title: usgs magnitude, api: string, count: integer, status: integer }, features: [ { type: "feature", properties: { mag: 5.2, place: 70km sw of iquique, chile, time: 1396605206040, updated: 1396606883841, tz: integer, url: string, detail: string, felt:integer, cdi: decimal, mmi: decimal, alert: string, status: string, tsunami: integer, sig:integer, net: string, code: string, ids: string, sources: string, types: string, nst: integer, dmin: decimal, rms: decimal, gap: decimal, magtype: string, type: string }, geometry: { type: "point", coordinates: [ longitude, latitude, depth ] }, id: string }, ... ] } thank time reading , comments.
you can use .pointradius() function of path this:
var path = d3.geo.path() .projection(projection) .pointradius(function(d) { return d.properties.mag; }); you may want have scale map data circle sizes, e.g.
var scale = d3.scale.sqrt().domain([minmag, maxmag]).range([2, 10]); // ... .pointradius(function(d) { return scale(d.properties.mag); });
Comments
Post a Comment