【问题标题】:D3: Is there a simple way to enlarge a map statically?D3:有没有简单的静态放大地图的方法?
【发布时间】:2013-12-17 20:38:56
【问题描述】:

我正在尝试创建我所在城市的地图,但默认地图太小。我不想做任何像缩放这样的事情(还),但我想将显示的尺寸加倍。

这里是脚本的摘录

var projection;
var w=1200;
var h=800;
var x=-14100;
var y=7300;
var scale=66700;

projection=d3.geo.albers()
.translate([x,y])
.scale([scale]);
var path=d3.geo.path()
.projection(projection);
var svg=d3.select("#data-div")
.append("svg")
.attr("width",w)
.attr("height",h);
var category;

// GROUPS

var paths = svg.append("g"),
 circles = svg.append("g");

// TORONTO MAP JSON

d3.json("d3_files/json/new-toronto.json",function(error, data){
paths.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d",path)
.attr("name",function(data){
    return"<strong>name</strong>"
}) // end name attr
.style("fill",function(data){
    return"lightgrey";
}) // end fill style
.style("stroke","#000")
}); // end toronto json

【问题讨论】:

  • This question 应该会有所帮助。
  • Lars,非常感谢,当我在下面看到 Adam 的 cmets 时,我忽略了这个提示。我现在刚刚试了一下,效果很好!

标签: d3.js geomap


【解决方案1】:

代替:

var scale=66700;

做:

var scale= 33350;

这将“缩小”投影。来自API

比例因子线性对应于之间的距离 投影点

【讨论】:

  • 在发布这个问题之前我已经尝试过了。如果我将其更改为该值,则地图将完全消失。如果我进行较小的更改,所有发生的事情就是地图移动了。
  • 你可能想发布一个 jsfiddle 或 bl.ocks
  • 我以前从未使用过 jsfiddle ...我已经创建了一个帐户并发布了我的代码,但我不确定这是您要求的。 jsfiddle.net/PatriciaW/xxAJn
  • 会不会是json文件格式不对?文件头以 { "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG:: 4269", "features": [ { "type": "Feature", "properties": { "GEO_ID": 14630026, "CREATE_ID": 63519, "NAME": "Scarborough-Rouge River (41)", "SCODE_NAME ":"41","LCODE_NAME":"EA41","TYPE_DESC":"Ward","TYPE_CODE":"CITW","OBJECTID":1,"SHAPE_AREA":0.0,"SHAPE_LEN":0.0 },"几何”:{“类型”:“多边形”,“坐标”:....
猜你喜欢
  • 2011-12-13
  • 2020-04-24
  • 1970-01-01
  • 2012-01-11
  • 2011-10-31
  • 2013-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多