首页 > 其他分享 >openlayers图层创建

openlayers图层创建

时间:2023-01-30 19:33:19浏览次数:29  
标签:style ol features 创建 openlayers text new 图层 size

创建图层

addVectorLayers(features,type) {
  //参数 features==接口获取的点位
let that=this;
//实例化一个矢量图层Vector作为绘制层
  //vectorSource 普通数据源
this.vectorSource = new ol.source.Vector({
features: features
});
//聚合 clusterSource 聚合数据源
this.clusterSource = new ol.source.Cluster({
distance:30,
source:this.vectorSource,
})
//创建一个图层 vectorLayer 先声明图层实例
this.vectorLayer = new ol.layer.Vector({
source: this.clusterSource,
style: function (feature) {
let size = feature.get('features').length;//获取该要素所在聚合群的要素数量
// var style = styleCache[size];
let style = null;
if (size > 1) {
      //点位聚合时 聚合的样式
style = [
new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
stroke: new ol.style.Stroke({
color: '#fff'
}),
fill: new ol.style.Fill({
color: '#ff000088'
})
}),
text: new ol.style.Text({
text: size.toString(),
fill: new ol.style.Fill({
color: '#fff'
})
})
})
];
     //点位没聚合时 点位的样式
} else {
      //在调用创建图层函数时传一个点位类型参数 不同类型点位使用不同的图片
if(type == 'shexiangtou'){
style = [
        //图片样式与文字样式
new ol.style.Style({
image: new ol.style.Icon({
src: require('../../assets/public/map/images/shexiangji.png'),
crossOrigin: '',
// size: [100, 100],
scale: 1
}),
text: new ol.style.Text({
// text: feature.values_.features[0].values_.name,
fill: new ol.style.Fill({
color: '#f00'
})
})
})
];
} else {
style = [
new ol.style.Style({
image: new ol.style.Icon({
src: require('../../assets/public/map/images/position_3.png'),
crossOrigin: '',
// size: [100, 100],
scale: 1
}),
text: new ol.style.Text({
// text: feature.values_.features[0].values_.name,
fill: new ol.style.Fill({
color: '#f00'
})
})
})
];
}
}
return style;
}
});

this.vectorLayer.set("customPro", "test")
this.vectorLayer.setZIndex(1999)
//将绘制层添加到地图容器中
this.mapUtilobj.map.addLayer(this.vectorLayer);
},

标签:style,ol,features,创建,openlayers,text,new,图层,size
From: https://www.cnblogs.com/kaoo-kiee/p/17077080.html

相关文章

  • Microsoft Azure 解决方案:如何创建Linux VM以及安全管理建议?
    51CTO博客地址:https://blog.51cto.com/14669127Azure培训视频地址:https://space.bilibili.com/2000820534企业如果采用云平台管理数据或者部署开发环境,但我们都知道Clo......
  • 使用python的tempfile模块创建临时文件
    什么样的情况下需要我创建临时文件呢?我很早就知道tempfile这个模块,但一直没有使用过它,也没有兴趣去研究它,一度认为自己用不到这个模块。存在即合理,合理的才能存在,想来是我不......
  • PVE API创建虚拟机
    度娘,谷歌都搜了一圈没有找到通过PVEAPI创建虚拟机的方式,于是查官网自己试了试,部分代码抄的SamLiu大佬的作业,感谢大佬。python代码如下:importrequests#self-signCA......
  • 使用pyfakefs在内存中创建文件,而非硬盘
    pyfakefs是一个假文件系统,它模拟的是python的文件系统,简单来说,它提供了和python的os模块,Path模块一样的功能,所有的文件操作,例如创建,修改,删除,重命名等操作都是在内存中进行......
  • 十二课:类中创建方法
    在类中创建一个方法方式一:在类内写方法functionProduct(pno,pname,price){//属性this.pno=pno;this.pn......
  • 15.1 SQL Server创建LOGIN(登录)
    SQLServer创建LOGIN(登录)目录SQLServer创建LOGIN(登录)简介示例SQLServerCREATELOGIN语句更多选项CHECK_POLICY选项CHECK_EXPIRATION选项MUST_CHANGE选项从Windows域帐......
  • ABAP 创建数据类型的三种方式,各自的使用场合和优缺点辨析试读版
    本教程之前的步骤,介绍了ABAP数据字典即SE11这个事务码里能够创建三种不同的数据类型:DataElementStructureTableType以及这三种数据类型各自的使用场合:84.AB......
  • WebGL从创建好的program中得到uniform和Attributes
    最近在看Cesium的源码,发现可以从创建好的program中提取uniform和Attributes,主要代码在ShaderProgram.js中,特意记录一下提取uniform,主要用到两个函数constnumberO......
  • c++针对特定数据结构创建堆
    make_heaphttps://en.cppreference.com/w/cpp/algorithm/make_heapstructds{ doublevalue; intidx; ds(doublev,intindex):value(v),idx(index){}......
  • Python字典对象的创建(9种方式)
    第一种方式:使用{}firstDict={"name":"wangyuanwai","age":25} 说明:{}为创建一个空的字典对象第二种方式:使用fromkeys()方法second_dict=dict.f......