添加一堆原生点
1、
function init_ActualSituation() {
var dians=static_DataBrowsing;
console.info(dians)
var vectorSource = new ol.source.Vector({});
//画点(画等值面点)
for(var i=0;i<dians.length;i++){
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([dians[i].Lon, dians[i].Lat]),
name: "dians",
value:dians[i].Value>0?dians[i].Value+'':'',
value2:dians[i].Value2>0?dians[i].Value2+'':'',
myid:dians[i].Station_Id_C,
myname:dians[i].Station_Name,
lonw:dians[i].Lon+'',
latw:dians[i].Lat+'',
});
iconFeature.setStyle(createLabelStyle(iconFeature));
if(turf.booleanPointInPolygon(turf.point([dians[i].Lon, dians[i].Lat]), hainan_Polygon)){
//将图标特性添加进矢量中
vectorSource.addFeature(iconFeature);
}
}
var layer = new ol.layer.Vector(
{
id: "dianss",
source: vectorSource,
})
map.addLayer(layer)
}
2、
function createLabelStyle(feature){
var _name="";
if(is_show_name){
_name=feature.get('myname')
}
return new ol.style.Style({
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color:'#489CEA'
}),
}),
fill: new ol.style.Fill({ //文本填充样式(即文字颜色)
color: '#000'
}),
//文本样式
text: new ol.style.Text({
//垂直文本偏移量(以像素为单位)。正值将使文本向下移动。
offsetY: 1,
//对齐方式
textAlign: 'center',
//文本基线
textBaseline: 'middle',
//字体样式
font: 'normal 11px 微软雅黑',
//文本内容
text: feature.get('value')+'\n'+_name,
// +feature.get('myname')
//填充样式
//文本填充样式(即文字颜色)
fill: new ol.style.Fill({color: '#000'}),
}),
});
}
浙公网安备 33010602011771号