Html Openlayers:如何在线条要素周围添加彩色边框

Html Openlayers:如何在线条要素周围添加彩色边框,html,css,openlayers,stroke,Html,Css,Openlayers,Stroke,我要将边框指定给线要素。在下面的代码中,我可以根据道路类型指定笔划颜色,但我想在其上指定另一个边界。 例如,我想为最后一条else语句指定一个边框。属于该类别的任何特征都应该与笔划颜色一起边框。 我怎样才能做到这一点 img: 矢量图块 .地图{ 宽度:100%; 高度:100vh; } 身体{ 保证金:0; } var popup=新ol.Overlay({ 元素:document.getElementById('popup') }); var osmLayer=新ol.layer.Til

我要将边框指定给线要素。在下面的代码中,我可以根据道路类型指定笔划颜色,但我想在其上指定另一个边界。 例如,我想为最后一条else语句指定一个边框。属于该类别的任何特征都应该与笔划颜色一起边框。 我怎样才能做到这一点

img:


矢量图块
.地图{
宽度:100%;
高度:100vh;
}
身体{
保证金:0;
}
var popup=新ol.Overlay({
元素:document.getElementById('popup')
});
var osmLayer=新ol.layer.Tile({
来源:new ol.source.OSM()
});
var styleFunction=函数(特性){
console.log(特性);
//根据道路类型指定道路的符号
颜色变异;
if(feature.get(“type”)=='primary'&&&'secondary'&&&trunk'){
颜色='rgba(252214112,1)';
}else if(feature.get(“type”)=“高速公路”){
颜色='rgba(245171,53,1)';
}else if(feature.get(“type”)=='cycleway'){
颜色='rgba(31166120,1)';
}否则{
颜色='rgba(2362362361)'
}
var retStyle=新的ol.style.style({
笔划:新的ol.style.stroke({
颜色:颜色,
宽度:5
})
});
回归复述风格;
};
var vectorLayer1=新ol.layer.VectorTile({
来源:新ol.source.VectorTile({
格式:新建ol.format.MVT(),
网址:'http://localhost:8080/tiles/roads/{z} /{x}/{y}.mvt'
}),
style:styleFunction
})
var selectInteraction=新建ol.interaction.Select({
层:功能(层){
返回layer.get('name');
}
});
var map=新ol.map({
目标:“地图”,
图层:[osmLayer,vectorLayer1],
视图:新ol.view({
中心:Lonlat的其他项目([103.8198,1.3521]),
缩放:13
})
});
map.addOverlay(弹出窗口);
函数picktrandomProperty(){
变量前缀=[‘底部’、‘中心’、‘顶部’];
var randPrefix=前缀[Math.floor(Math.random()*prefix.length)];
变量后缀=[‘左’、‘中’、‘右’];
var randSuffix=后缀[Math.floor(Math.random()*suffix.length)];
返回randPrefix+'-'+randSuffix;
}
var container=document.getElementById('popup');
var displayFeatureInfo=函数(像素、坐标){
var特征=[];
map.forEachFeatureAtPixel(像素,功能(特征,层){
功能。推送(功能);
});
如果(features.length>0){
var信息=[];
对于(变量i=0,ii=features.length;i
只要内部颜色没有任何透明度,就可以使用重叠笔划样式数组

  var retStyle = [
    new ol.style.Style({
      stroke: new ol.style.Stroke({ 
        color: outerColor,
        width: 7,
        zIndex: 0
      })
    }),
    new ol.style.Style({
      stroke: new ol.style.Stroke({ 
        color: color,
        width: 5,
        zIndex: 1
      })
    })
  ];
  var retStyle = [
    new ol.style.Style({
      stroke: new ol.style.Stroke({ 
        color: outerColor,
        width: 7,
        zIndex: 0
      })
    }),
    new ol.style.Style({
      stroke: new ol.style.Stroke({ 
        color: color,
        width: 5,
        zIndex: 1
      })
    })
  ];