2017-12-30 60 views
1

SVGサークルをマップの背景に描画しようとしていますが、(Chrome Devツールを使用して)要素に表示されている間、SVGサークルはページに表示されません。私はここで何が欠けています、なぜ彼らは隠されていますか?D3とリーフレットのサークルが表示されない

マップと円の塗りつぶし、不透明度を変更しようとしましたが、なぜレンダリングされないのかわかりません。

マイコード:

enter image description here

しかし、それが原因で不透明度や色の見えないではないですが、あなたがいないので:あなたが注意したよう

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Leaflet and D3 map</title> 
       <link rel="stylesheet" href="../leaflet.css" /> 
       <script type="text/javascript" src="../leaflet.js"></script> 
     <script type="text/javascript" src="../d3.js"></script> 
       <style type="text/css"> 

        #map{ 
         width: 700px; 
         height: 600px; 
        } 

       </style> 
    </head> 
    <body> 
      <div id="map"></div> 


     <script type="text/javascript"> 

         // 
         // LOAD THE MAP FROM MAPBOX & LEAFLET 
         // 
         var map = L.map("map").setView([50.0755,14.4378], 12); 

         mapLink = '<a href="http://www.mapbox.com">Mapbox</a>'; 
         L.tileLayer (
          "link to mapbox",{ 
           attribution:"&copy; " + mapLink + " Contributors", 
           maxZoom:20, 
         }).addTo(map); 

         // 
         // Create the SVG layer on top of the map 
         // 
         L.svg().addTo(map); 

         // Create the standard variables selecting the SVG in the map element 
         var svg = d3.select("#map").append("svg"); 
         var g = svg.append("g"); 

      //Load the coordinate for the circle 
      var objects = [ {"circle":{"coordinates":[50.0755,14.4378]}}]; 

      //Loop through to create a LatLng element that can be projected onto Leaflet map 
      for(var i = 0;i<objects.length;i++){ 
       objects[i].LatLng = new L.LatLng(objects[i].circle.coordinates[0], objects[i].circle.coordinates[1]) 
      }; 

      //Create the circle object and store it in features 
      var feature = g.selectAll("circle") 
      .data(objects) 
      .enter() 
      .append("circle") 
      .style("fill", "red") 
      .attr("r", 20); 


      //Make the circle dynamic, by calling the update function whenever view is view is reset 
      map.on("viewreset", update) 

      //Call the update also on first load of the web page 
      update(); 

      //Updates the position of the circle every time the map is updated 
      function update(){ 
       feature.attr("transform", 
       function(d){ 
       return "translate("+ 
        map.latLngToLayerPoint(d.LatLng).x+","+ 
        map.latLngToLayerPoint(d.LatLng).y+")"; 
       }) 

      }; 

     </script> 
    </body> 
</html> 

答えて

1

、あなたの円が追加されますsvgのサイズを設定します。 svgのデフォルトサイズではサークルは境界線を越えて表示されているため、地図の中央に[350,300]が表示され、SVGのデフォルトサイズは300x150 となります()。試してみてください:

var svg = d3.select("#map") 
    .append("svg") 
    .attr("width",700) 
    .attr("height",600) 

あなたの地図は縦横600ピクセルです。

関連する問題