D3 및 전단지 Chrome / Safari 및 Firefox에서 다른 SVG를 반환합니다.
문제
나는 최신 버전을 사용하여 전단지와 D3가있는지도를 만들려면이 예제를 따릅니다. D3 및 전단지의 내 코드의 무언가가 D3이 크롬 및 FF 28의 SVG 요소에 대해 다른 값을 반환하게하는 것입니다. 이는 SVG의 다른 변환 특성뿐만 아니라 경로 요소에 다른 D 값을 갖는 FF에서 포인트를 비뚤어졌습니다. 요소.
여기에 크롬 용 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"/>
.
여기에지도를로드하고 점을 프로젝트하는 코드입니다. 맨 끝에서 Chrome 및 FF 28의 포인트에 대해 다른 X 값을 반환하는 기능 project
가 있습니다.이 줄은 코드에 전체 문제를 만드는 것 같습니다. x-value는 다른 시간에 다른 값으로 꺼져 있으므로 수정을 작성하기가 어렵습니다.
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];
}
});
.
i leaflet에서 버그로 제안되었습니다. FF 28 및 Chrome에서 Firedle을 사용하면 51 줄이 Chrome (오른쪽 X 값) 및 Firefox (잘못된 X 값)
동일한 LAT / LONG에 대해 다른 X 값을 반환하는지 확인합니다.FF 27 및 FF 28 에서이 바이올린을 시도했습니다. 이러한 버전의 Firefox는 51 행의 지점에 대해 다른 (및 부정확 한) x 값을 반환합니다.
전단지 또는 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();
});
. 다른 팁
문제점은 d3.json
를 호출하는 방법입니다.
d3.json('{{url_for('static', filename='out.json') }}', //...
.
가 유효하지 않습니다. d3.json
함수는 첫 번째 매개 변수가 객체가 아닌 URL 문자열로 기대합니다.FF 및 WebKit 모두에서는 무작위 쓰레기를 가져오고 코드가 경계를 계산하는 데 사용하는 것입니다.
URL을 구성하기 위해 템플릿 (즉 콧수염)을 사용하려고 시도하고 있습니까?그렇다면 템플릿을 렌더링하는 것입니다.