2015-04-07 41 views
0

我有一點麻煩設置風格L.geoJSON基礎層上,我的代碼看起來是這樣的:不能設置風格傳單L.geoJSON層

var addProperties = function addProperties(prop,map) 
{ 
    //the API does not seem to support adding properties to an existing feature, 
    //the idea here is simple: 
    //(1) currentFeature.toGeoJson() needs to be called to obtain a json representation 
    //(2) set the properties on the geojson 
    //(3) create a new feature based on the geojson 
    //(4) remove res and add the new feature as res 

    var style = function style(feature){ 
     var markerStyle = { 
      draggable: 'true', 
      icon: L.AwesomeMarkers.icon({ 
      icon: 'link', 
      prefix: 'glyphicon', 
      markerColor: 'red', 
      spin: true 
      }) 
     }; 
     if(feature.geometry.type==='Point') 
      return markerStyle; 
    }; 

    var onEachFeature = function onEachFeature(feature,layer){ 
     console.log("Inside on each feature,checking to see if feature was passed to it ",feature); 
     layer.on('click',function(e){ 
      //open display sidebar 
      console.log("Checking to see if setupTabs exists ",setupTabs); 
      setupTabs('#display-feature-tabs'); 
      console.log("Checking to see if featureInfo exists ",featureInfo); 
      var featureInfoAPI =featureInfo('feature-properties'); 
      featureInfoAPI.swap(feature.properties); 
      setTimeout(function() { 
        sidebar.show(); 
       }, 100); 
     }); 
    }; 

    console.log("Inside add properties"); 
    var geoJSON,feature; 
    if(res != null) 
    { 
     geoJSON = res.toGeoJSON(); 
     geoJSON.properties = prop; 
     console.log(geoJSON); 
     feature = L.geoJson(geoJSON,{style:style,onEachFeature:onEachFeature}); 
     console.log("The new feature that has been created ",feature); 
     removeFeature(map); 
     addFeature(feature); 
     feature.addTo(map); 

    } 
}; 

我也曾嘗試style方法以及,我正在尋找爲點添加樣式到活動層(樣式也將按類型添加到線條和多段線中)。

+0

你的geojson是怎麼樣的? – Hinrich

回答

0

要樣式化點要素,您應該使用pointToLayer選項。