2016-11-29 74 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);