openlayers--点位、边界样式设置

时间:2023-01-30
本文章向大家介绍openlayers--点位、边界样式设置,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
//创建中心点文字样式
createPointStyle(feature) {
return new ol.style.Style({
text: new ol.style.Text({
//位置
textAlign: 'center',
//基准线
textBaseline: 'middle',
//文字样式
font: 'normal 18px 微软雅黑',
// center: [115.5, 36.5],
//文本内容
text: feature.get('name'),
//文本填充样式(即文字颜色)
fill: new ol.style.Fill({ color: '#f00' }),
stroke: new ol.style.Stroke({ color: '#ffcc33', width: 0.5 })
})
});
},

//图片样式设置 image放在上面方法中与text同级一起使用
image: new ol.style.Icon(
({
anchor: [0.5, 1],
anchorOrigin: 'top-right',
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
offsetOrigin: 'top-right',
opacity: 0.75,
//图标的url
src: require('../../assets/public/map/images/position_3.png')
})
),

//边界(地块样式的设置)
/* 地块样式 */
featureStyle() {
return {
"sourceData": new ol.style.Style({
//图层范围样式
fill: new ol.style.Fill({
color: '#dfff0055' //填充颜色
}),
    //图层边框样式设置
stroke: new ol.style.Stroke({
// color: '#18399499', //边框颜色220, 174, 20
color: '#ff636377', //边框颜色
width: 2 // 边框宽度
})
}),
}
},

原文地址:https://www.cnblogs.com/kaoo-kiee/p/17077108.html