2017-07-27 8 views
0

誰かが私のコードで間違っていることを教えてもらえますか?私はポリゴンを選択し、リーフレットとハイチャートを使ってポップアップでグラフを表示したいと思っています。私はポップアップでグラフを作成することができましたが、行が欠落していました。また、私が望んでいないWebページの下部に同じグラフ(と行)を表示する別のdivも取得します。誰も私の行をポップアップでグラフに表示し、別のグラフを削除する方法を教えてもらえますか?ここに私のコードです。ここにコードを入れてくださいリーフレットのポップアップと別のDivのグラフ

<!DOCTYPE html> 
<html> 
<head> 

    <title>Quick Start - Leaflet</title> 

    <meta charset="utf-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <!--include leaflet CSS file--> 

    <link rel="stylesheet" href="css/leaflet.css" /> 
    <link rel="markers" type="images/marker-icon" href="images/marker-icon.png" /> 

<!--include Leaflet Javascript file--> 
<!-- Make sure you put this AFTER Leaflet's CSS --> 

    <script src="js/leaflet.js"></script> 
    <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script> 
    <script src='http://unpkg.com/[email protected]/dist/leaflet.js'></script> 
    <script src="js/esri-leaflet.js"></script> 
    <script src="https://d3js.org/d3.v4.min.js"></script> 
    <script src="https://code.highcharts.com/highcharts.src.js"></script> 

</head> 
<body> 

<!--Put a div element with a certain id where you want your map to be: --> 

    <div id="map" style="width: 1000px; height: 800px;"></div> 
    <div id="chartcontainer" class="highchart" style="width: 500px; height: 200px;"></div> 

    <!-- First we’ll initialize the map and set its view to our chosen geographical coordinates and a zoom level:--> 
    <script> 

    var mymap = L.map('map', { 
      zoomControl:true, maxZoom:28, minZoom:1 
     }).fitBounds([[51.0269253989,-1.34762355597],[51.1990603009,-0.951310026203]]); 

    L.esri.basemapLayer('Imagery').addTo(mymap);   

//loads geoserver layer as WMS 
var field_boundaries = L.tileLayer.wms("http://localhost:1997/geoserver/RSAC/wms", { 
    layers: 'RSAC:results_clipped_with_growth_small_new', 
    format: 'image/png', 
    transparent: true, 
    version: '1.1.0', 
    attribution: "myattribution" 
    }); 


//loads the geojson layer 
    var owsrootUrl = 'http://localhost:1997/geoserver/RSAC/wms'; 
    var defaultParameters = { 
     service : 'WFS', 
     version : '2.0', 
     request : 'GetFeature', 
     typeName : 'RSAC:results_clipped_with_growth_small_new', 
     outputFormat : 'json', 
     format_options : 'callback:getJson', 
     SrsName : 'EPSG:4326' 
    }; 
var parameters = L.Util.extend(defaultParameters); 
var URL = owsrootUrl + L.Util.getParamString(parameters); 
var ajax = $.ajax({ 
    url : URL, 
    dataType : 'json', 
    jsonpCallback : 'getJson', 
    success : function (response) { 
    L.geoJson(response, { 
     onEachFeature: function (feature, url) { 
     url.on('click', function(e){ 

        var chartplotoptions ={ 
         chart: { 
          type: 'line' 
         }, 
         title: { 
          text: 'Growth' 
         }, 

         xAxis: { 
          allowDecimals: true, 
          categories: ['20151114', '20151126', '20151208', '20151220', '20160113', '20160125', '20160206', '20160218', '20160301', '20160313', '20160325', '20160406', '20160418', '20160430', '20160512', '20160524', '20160605', '20160629', '20160723', '20160804', '20160816'], 
          labels: { 
           formatter: function() { 
            return this.value; 
           } 
          } 
         }, 
         yAxis: { 
           startOnTick: false, 
           minPadding: 0.05, 
          title: { 
           text: 'Crop Growth', 

          }, 
          labels: { 
           formatter: function() { 
            return this.value; 
           } 
          } 
         }, 
         tooltip: { 
          pointFormat: '{series.name}{point.y}' 
         }, 
         plotOptions: { 

           area: { 
           pointStart: -20, 
           threshold: 10, 
           marker: { 
            enabled: false, 
            symbol: 'circle', 
            radius: 2, 
            states: { 
             hover: { 
              enabled: false 
             } 
            } 
           } 
          } 
         }, 
         series: [{ 
          name: 'Growth', 
          data: [parseFloat(feature.properties.Date_20151114),parseFloat(feature.properties.Date_20151126),parseFloat(feature.properties.Date_20151208), parseFloat(feature.properties.Date_20151220), parseFloat(feature.properties.Date_20160113), parseFloat(feature.properties.Date_20150125), parseFloat(feature.properties.Date_20160206), parseFloat(feature.properties.Date_20160218), parseFloat(feature.properties.Date_20160301), parseFloat(feature.properties.Date_20160313), parseFloat(feature.properties.Date_20160325), parseFloat(feature.properties.Date_20160406), parseFloat(feature.properties.Date_20160418), parseFloat(feature.properties.Date_20160430), parseFloat(feature.properties.Date_20160512), parseFloat(feature.properties.Date_20160524), parseFloat(feature.properties.Date_20160605), parseFloat(feature.properties.Date_20160629), parseFloat(feature.properties.Date_20160723), parseFloat(feature.properties.Date_20160804), parseFloat(feature.properties.Date_20160816)] 
         }, 

         ] 
        }; 


        $('#chartcontainer').highcharts(chartplotoptions); 
        url.bindPopup($('#chartcontainer').html()); 
        url.openPopup(); 
        }); 
       } 

      }).addTo(mymap); 
     } 
    });  

    </script> 



</body> 
</html> 
+0

次の時間はあなたが[MCVE]を提供していることを確認してください(https://stackoverflow.com/help/mcve) – ghybs

答えて

1

HTMLマークアップにdiv要素は必要ありません。 onEachFeature関数でオンザフライで作成し、ポップアップに追加することができます。また、ポップアップが開いた後ではなく、ハイチャートを初期化する必要があります。コメント付きのコードで:

new L.GeoJSON(feature, { 
    onEachFeature: function (feature, layer) { 

     // Create div with class name highchart 
     var div = L.DomUtil.create('div', 'highchart'); 

     // Bind popup to layer with div as content 
     layer.bindPopup(div); 

     // Handle event when popup opens 
     layer.on('popupopen', function (e) { 

      console.log(e.target); // layer object 
      console.log(e.target.feature); // layer's feature object 
      console.log(e.popup); // popup object 
      console.log(e.popup.getContent()); // the div 

      // Now do the highcharts stuff 
      Highcharts.chart(e.popup.getContent(), { /**/ }); 
     }); 
    } 
}); 

とCSSでdiv要素の大きさを設定することを忘れないでください:

.highchart { 
    width: 500px; 
    height: 200px; 
} 
+0

ありがとうiH8。私はついにこれを手に入れました。 – user8136435

関連する問題