2017-04-03 109 views
0

我有一個代碼,需要一個谷歌地圖,並上傳一個D3層,它在V3和它的工作正常。現在我需要將其轉移到V4,它給了我一個錯誤: 「遺漏的類型錯誤:r是不是一個函數」 下面的代碼被轉移後,到V4d3從v3翻譯到v4

<body> 
     <div id="map"></div> 
     <script> 
     var map = new google.maps.Map(d3.select("#map").node(), { 
      zoom: 7, 
      center: new google.maps.LatLng(31.5852,36.2384), 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 

     styles: [ 

       {elementType: 'geometry', stylers: [{color: "#212121"}]}, 
       {elementType: 'labels.text.stroke', stylers: [{color: '#242f3e'}]}, 
       {elementType: 'labels.text.fill', stylers: [{color: '#746855'}]}, 

       ] 
     }); 

     d3.json("Export_Output_6_modified.json", function(error, jordanLevel2) { 
      if (error) throw error 

      //console.log(data[0].comuni[0].geometry.coordinates); 
      var overlay = new google.maps.OverlayView(); 

      overlay.onAdd = function() { 

      var layer = d3.select(this.getPanes().overlayLayer).append("div");//.attr("height",1000) 

      overlay.draw = function() { 

       layer.select('svg').remove(); 

       var w = 900; 
       var h = 900; 

       var color = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999']; 
       var heat_color = d3.scaleLinear().domain([0, 1]).range(['#b2df8a', '#ff7f00']).interpolate(d3.interpolateHcl); 

       var overlayProjection = this.getProjection(); 

       // Turn the overlay projection into a d3 projection 
       var googleMapProjection = function(coordinates) { 
       var googleCoordinates = new google.maps.LatLng(coordinates[1], coordinates[0]); 
       var pixelCoordinates = overlayProjection.fromLatLngToDivPixel(googleCoordinates); 
       return [pixelCoordinates.x, pixelCoordinates.y]; 
       } 

       var path = d3.geoPath().projection(googleMapProjection); 

       var svg = layer.append("svg") 
       .attr('width', w) 
       .attr('height', h) 

       var g = svg.append('g') 
       .attr("id", "mapGroup"); 
    //I believe the problem is here.... 
       g.selectAll(".path") 
       .data(jordanLevel2.features) 
       .enter() 
       .append("path") 
       .attr("d", path) 
       .attr('class', 'state selected') 
       .style("fill", function(d, i) { 
        return color[i % color.length]; 
       }) 
       .style('opacity', .7); 

      } 
      } 
      overlay.setMap(map); 

     }); 
     </script> 
    </body> 

回答

-1

不幸的是,沒有任何簡單的方法來從V3到V4遷移。 v4版本是模塊化的,並且是許多小型圖書館的集合,而不是一個大型圖書館。所以,這些變化是根本性的,可能會更好。我發現Irene Ros的presentation是遷移到v4的良好開端。另外,請參閱GitHub repo,其中有許多Scott書籍遷移到v4的示例。

+0

是的我知道,但在另一方面,我需要翻譯具體的方面。 我閱讀演示文稿它必須從投影轉換爲geoProjection,但也出現錯誤 – DANAA