Ton*_*BCN 5 javascript openlayers-3
在OpenLayers 3中可以更改选区中的边框颜色:
style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 2
})
});
Run Code Online (Sandbox Code Playgroud)
但是有可能只改变边界底部吗?
就像是:
style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 2,
border-bottom: 2px dotted #ff9900
})
});
Run Code Online (Sandbox Code Playgroud)
当然,由于有大量可用的 OL 3 资源,您可以使用第二种样式来(模拟)边框底部。用一个ol.style#GeometryFunction。受到这个例子的启发。
http://jsfiddle.net/jonataswalker/k11bxma2/
有点不同 - http://jsfiddle.net/jonataswalker/n73gm0u9/
var style = [
new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'red',
width: 2
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'green',
width: 2
}),
geometry: function(feature) {
var geom = feature.getGeometry();
var extent = geom.getExtent();
var bottomLeft = ol.extent.getBottomLeft(extent);
var bottomRight = ol.extent.getBottomRight(extent);
// return a linestring with the second style
return new ol.geom.LineString([bottomLeft, bottomRight]);
}
})
];
Run Code Online (Sandbox Code Playgroud)