如何在Raphael js中调整地图大小和位置?

时间:2014-02-25 08:59:59

标签: svg raphael

我正在尝试使用Raphael js在动态广告中包含一张世界地图。一旦定义了路径,我就会更新rapahel paper对象的viewbox以缩放路径。虽然这部分工作正常,但我无法将路径与div的中心对齐。以下是我到目前为止根据answer所做的事情:

var paper = Raphael("map"),
            path = paper.path(w_path).attr({fill: "#000", "stroke-width": 0, "stroke-linejoin": "round", opacity: 1}),
    box = path.getBBox(),
            margin = Math.max(box.width, box.height) * 0.025;  // set the viewbox to match the bounding box of the path with 2.5% margins
    paper.setViewBox(box.x - margin, box.y - margin, box.width + margin * 2, box.height + margin * 2);

我的问题是如何在div(map div)的中心对齐垂直和水平的路径?

更新: 我为此添加了jsFiddle

0 个答案:

没有答案