2016-11-29 81 views

回答

0

你可以只添加样式对象到ol.format.KML代码() ;

var source = new ol.source.Vector({ 
    url: 'city.kml', 
    format: new ol.format.KML({ 
     projection: 'EPSG:3857', 
     extractStyles: false 
    }) 
}); 

function styleFunction(feature) { 
    var style = new ol.style.Style({ 
     stroke: new ol.style.Stroke({ 
     color: 'red', 
     width: 4 
     }) 
    }) 
    return [style]; 
} 

var layer = new ol.layer.Vector({ 
    source: source, 
    style: styleFunction 
}); 
map.addLayer(layer);