2017-05-15 3 views
0

私はdjangoでリーフレットマップを持っています。私はデータベースからgeojsonを渡しています。何らかの理由で、私はエラーを出すことはありませんが、3,000程度ではなく1つのポリゴンをレンダリングするだけです。他のすべてが正しく動作しているようです。ポリゴンのリストに1つのポリゴンをレンダリングするリーフレット

この形状の中に形はなく、同じ場所にレンダリングされた形の束があるので、技術的には多角形ではありません。私が何をしたか

function initmap(){ 


      var map = new L.map('map',{ 

          center: [1.0,1.0], 
          layers: [osmLayer,markers,parcelLayer], 
      minZoom: 1, 
          zoom: 3 } 
        ).setView([lat,long],13); 


    }  



      var osmLayer = new L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { 
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>', 
        subdomains: ['a','b','c'] 
    }); 



    var markers = new L.FeatureGroup(); 


    var parcelFeature = ['{"geometry": {"type": "Polygon", "coordinates": [[[a,b],[c,d],[e,f],[g,h]]]}, "type": "Feature"}', 
'{"geometry": {"type": "Polygon", "coordinates": [[[i,j],[k,l],[m,n],[o,p]]], "type": "Feature"}']; 
    parcelFeature = JSON.parse(parcelFeature[0]);  

     var parcelLayer = L.geoJson([parcelFeature],{ 
        style : { 

        "color": "#000000", 
        "weight": 3, 
        "opacity": 10.65 

          } 
     }); 

      parcelLayer.on("loaded", function(e) {map.fitBounds(e.target.getBounds());});  


    //marker icon 
    var ceIcon = L.icon({ 
     iconUrl: "/static/maps/leaflet/images/somepng.png", 
     iconSize: [45,45], 
     iconAnchor: [0, 0], 
     popupAnchor: [-3, -76] 
    }); 



    //add markers 

     marker = new L.marker([lat,long], {icon:ceIcon}); 
     markers.addLayer(marker); 

     marker = new L.marker([lat,long], {icon:ceIcon}); 
     markers.addLayer(marker); 

     marker = new L.marker([lat,long], {icon:ceIcon}); 
     markers.addLayer(marker); 

     marker = new L.marker([lat,long], {icon:ceIcon}); 
     markers.addLayer(marker); 



    initmap(); 
+0

は、それは我々が同じ問題... jsfiddleまたはstackoverflowのエディタを再現することができ、実行中のサンプルを作成することは可能ですか? –

答えて

0

JavaScriptで各JSON項目を分割し、新しいリストに追加するその後、JSONとしてジャンゴを介してこれを通過したと。

var parcelFeature = []; 
     var parcel_json = {{ parcel_json|safe }}; 


     for(i = 0; i < parcel_json.length; i++){ 
     var pjson = parcel_json[i]; 
     pjson = JSON.parse(pjson); 
     parcelFeature.push(pjson); 

     } 

これ以降、デフォルトのL.geoJsonレイヤーを使用して正しくレンダリングしました。わからない

VAR parcelLayer = L.geoJson(parcelFeature、 {スタイル:{

   "color": "#000000", 
       "weight": 1, 
       "opacity": 100}, 
     "fillColor":"#FFFFFF", 
    onEachFeature: function(feature, layer) { 
       // does this feature have a property named popupContent? 
       if (feature.properties && feature.properties.popupContent) { 
       layer.bindPopup(feature.properties.popupContent); 
       console.dir(feature.properties.popupContent); 
      } } 

    }); 
関連する問題