質問

フォローこの例LeafletとD3でマップを作成するには、最新のバージョンを使用してD3とリーフレットの。私のコードの中の何かは、D3がChromeとFF 28のSVG要素に対して異なる値を返すようにしています。これは、PATS要素内のD値とSVG内の異なる変換プロパティの異なるD値を持つFFでポイントをスキューする原因となります。要素

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"/>
.

これは地図をロードしてポイントを投影するコードです。最後に、ChromeとFF 28のポイントの異なるx値を返す関数projectがあります。この行はコードの全体的な問題を作成していると思います。 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];
      }          
      });
.

i リーフレットへのバグとして提案した。 FF 28とChromeでフィドルを試してみると、行51は同じLAT / LOND(右X値)とFirefox(間違ったX値)の異なるX値を返すことがわかります。

私はFF 27およびFF 28でこのフィドルを試してみました - これらのバージョンのFirefoxのそれぞれは、41行目のポイントに対して異なる(不正解)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の両方で、おそらくランダムなゴミを取得し、それがあなたのコードが範囲を計算するために使用するものです。

あなたはテンプレート(i.E.口ひげ)を使ってURLを構築しようとしていますか?もしそうなら、あなたはテンプレートをレンダリングするのを忘れています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top