gpt4 book ai didi

svg - D3 和​​传单在 Chrome/Safari 和 Firefox 中返回不同的 SVG

转载 作者:行者123 更新时间:2023-12-01 15:34:05 25 4
gpt4 key购买 nike

我正在按照 this 示例使用最新版本的 d3 和 leaflet 使用 leaflet 和 d3 制作 map 。我的代码中的某些东西导致 d3 为 Chrome 和 FF 28 中的 SVG 元素返回不同的值。这导致点在 FF 中倾斜,它在 PATH 元素中具有不同的 d 值以及在 SVG 中具有不同的转换属性元素。

这是 Chrome 的 SVG:

<svg width="1049711" height="1802" transform="translate(127,1079)" style="margin-left: -127px; margin-top: -1079px;">
<g class="leaflet-zoom-hide" transform="translate(127,1079)">
<path class="nora f" id="1383_ST_BERNARD_AVE" lat="29.970905251" long="90.064206456" d="M287,210m0,2a2,2 0 1,1 0,-4a2,2 0 1,1 0,4z"></path>
<path class="fixed f" id="7400_ADVENTURE_AVE" lat="30.0599104550001" long="89.9260116889999" d="M1092,-389m0,2a2,2 0 1,1 0,-4a2,2 0 1,1 0,4z"></path>

这是 Firefox 的 SVG

<svg width="1049711" height="1802" style="margin-left: -97px; margin-top: -1079px;" transform="translate(97,1079)">
<g class="leaflet-zoom-hide" transform="translate(97,1079)">
<path class="nora f" id="1383_ST_BERNARD_AVE" lat="29.970905251" long="90.064206456" d="M317,210m0,2a2,2 0 1,1 0,-4a2,2 0 1,1 0,4z"/>
<path class="fixed f" id="7400_ADVENTURE_AVE" lat="30.0599104550001" long="89.9260116889999" d="M1122,-389m0,2a2,2 0 1,1 0,-4a2,2 0 1,1 0,4z"/><path class="nora f" id="4170_OLD_GENTILLY_RD" lat="30.0024662600001" long="90.0401487569999" d="M457,-3m0,2a2,2 0 1,1 0,-4a2,2 0 1,1 0,4z"/>

这是加载 map 和投影点的代码。最后有一个函数 project 为 Chrome 和 FF 28 中的点返回不同的 x 值。我认为这一行造成了代码的整体问题。 x 值在不同时间偏离不同值,因此很难编写更正。

    var map = new L.Map("map", {center: [29.95, -90.05], zoom: 13, minZoom:10, maxZoom:18})
.addLayer(new L.tileLayer('http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png'));

var svg = d3.select(map.getPanes().overlayPane).append("svg"),
g = svg.append("g").attr("class", "leaflet-zoom-hide");

//these brackets are jinja2 template syntax. They eventually return 'static/out.json'
d3.json('out.json') }}', function(collection) {
var bounds = d3.geo.bounds(collection),
path = d3.geo.path().projection(project).pointRadius(function (d) {return 2});
console.warn(path)

var feature = g.selectAll("path")
.data(collection.features)
.enter().append("path").attr("class", function(d){
return d.properties.category + " " + d.properties.investigates;;
}).attr("id", function(d){
return d.geometry.address;
}).attr("lat", function(d){
return Math.abs(d.geometry.coordinates[1]);
}).attr("long", function(d){
return Math.abs(d.geometry.coordinates[0]);
});
$(".t").on("click", function(e) {

var adr = "/" + this.id;
showDialog(adr);
});

map.on("viewreset", reset);
reset();


// Reposition the SVG to cover the features.
function reset() {
console.warn(bounds)
var bottomLeft = project(bounds[0]),
topRight = project(bounds[1]);


svg .attr("width", topRight[0] - bottomLeft[0])
.attr("height", bottomLeft[1] - topRight[1])
.style("margin-left", bottomLeft[0] + "px")
.style("margin-top", topRight[1] + "px").attr("transform", "translate(" + -bottomLeft[0] + "," + -topRight[1] + ")");

g .attr("transform", "translate(" + -bottomLeft[0] + "," + -topRight[1] + ")");

feature.attr("d", path)
}

// Use Leaflet to implement a D3 geographic projection.
function project(x) {
var point = map.latLngToLayerPoint(new L.LatLng(x[1], x[0]));
return [point.x, point.y];
}
});

proposed this as a bug 传单。如果您在 FF 28 和 Chrome 中尝试 fiddle ,您会看到第 51 行在 Chrome(正确的 x 值)和 firefox(错误的 x 值)中针对相同的纬度/经度返回不同的 x 值

我已经在 FF 27 和 FF 28 中试过这个 fiddle ——每个版本的 firefox 都会为第 51 行的点返回一个不同的(并且不正确的)x 值。

我是不是遇到了 leaflet 或 d3 中的错误,或者我的代码有问题?有解决方法吗?这是怎么回事?

最佳答案

我最终按照这个例子让它工作:https://gist.github.com/ZJONSSON/2957559

这是工作代码:

var path = d3.geo.path().projection(function project(x) {
var point = map.latLngToLayerPoint(new L.LatLng(x[1], x[0]));
return [point.x, point.y];
}).pointRadius(function(d) {
return 2;
});

/* Load and project/redraw on zoom */
d3.json("static/out.json", function(collection) {
var feature = g.selectAll("path")
.data(collection.features)
.enter().append("path")
.attr("class", function(d) {
return d.properties.category + " " + d.properties.investigates + " " + d.properties.thumbnail;
}).attr("id", function(d) {
return d.properties.address;
}).attr("lat", function(d) {
return Math.abs(d.geometry.coordinates[1]);
}).attr("long", function(d) {
return Math.abs(d.geometry.coordinates[0]);
})
.attr("d", path);

map.on("viewreset", function reset() {
feature.attr("d", path);
});
loadThumbs();
});

关于svg - D3 和​​传单在 Chrome/Safari 和 Firefox 中返回不同的 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com