kpst._this这里指向初始化的map

     // 设置标注样式函数
function createStyle(name) {
// 河流style
var riverStyle = new Style({
stroke: new Stroke({
color: '#4e89d4',
width: 2
}),
fill: new Fill({
color: '#eee'
})
})
// 省份style·
var provinceStyle = new Style({
stroke: new Stroke({
color: '#4e89d4',
width: 1
}),
fill: new Fill({
color: '#eee'
})
}) //城市style·
if (name != '') {
var cityStyle = new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: '#05ab57',
}),
stroke: new ol.style.Stroke({
color: '#05ab57',
width: 1
}),
}),
text: new ol.style.Text({
textAlign: "center", // 位置
textBaseline: "top", // 基准线
font: "normal 12px 微软雅黑", // 文字样式
text: name,
fill: new ol.style.Fill({
color: "#333",// 文本填充样式(即文字颜色)
}),
stroke: new ol.style.Stroke({
color: "#Fff",
}),
zIndex: 9
})
})
}
return {
riverStyle,
provinceStyle,
cityStyle
}
}
//创建图层
function creatlayer(name) {
var layer
if (name != 'city') {
layer = new VectorLayer({
name: name,
source: new VectorSource({
// 地图的坐标系是CGCS2000,json数据也要是CGCS2000
features: (new GeoJSON()).readFeatures(require("../../assets/data/" + name + '.json'))
}),
style: createStyle()[name + 'Style']
}); } else {
var features = (new GeoJSON()).readFeatures(require("../../assets/data/city.json"))
for (let i = 0; i < features.length; i++) {
const feature = features[i];
feature.setStyle(createStyle(feature.get("NAME")).cityStyle)
}
layer = new VectorLayer({
name: name,
source: new VectorSource({
features: features
})
})
}
kpst._this.addLayer(layer);
return layer
};
// 将图层加载到地图,并将所加图层赋给地图的某个对象
function layerFx(name) {
kpst._this[name] = creatlayer(name)
}
// 将图层加载函数挂载到地图
kpst._this.layerFx = layerFx

最新文章

  1. [经验交流] Mesos-dns 和 Marathon-lb 简要使用方法
  2. 第5.5次Scrum会议
  3. tomcat异常: Cannot get a connection, pool exhausted
  4. 【转载】如何系统地自学 Python?
  5. jQuery控制TR的显示隐藏
  6. Android NDK调试C++源码(转)
  7. MySQL字符串类型转换时间类型
  8. Ubuntu 16.04 LTS 正式发布:系统将持续更新5年
  9. 【递推+矩阵快速幂】【HDU2604】【Queuing】
  10. 文件搜索查找功能VC++
  11. GPS校时器,GPS时钟装置,NTP网络时间服务器
  12. [国嵌攻略][052][NandFlash驱动设计_读]
  13. VMS项目总结
  14. kubernetes系列08—service资源详解
  15. 阿里云服务器+ftp文件操作+基于Centos7的vsftpd配置
  16. vue-cli项目 build后请求本地static文件中的 json数据,路径不对,报错404处理方法
  17. python之路--MySQL多表查询
  18. 通过dd命令显示硬盘的读写性能
  19. 【Windows】添加定时任务不执行
  20. HTML5实现video标签的自定义播放进度条

热门文章

  1. HttpClient两种调用方式
  2. linux 之 pthread_create 实现类的成员函数做参数
  3. Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + file.Name) 中文显示乱码
  4. Mac 下 Android Studio 连 夜神模拟器 调试
  5. electron关于无边框窗口无法拖拽移动以及点击事件失效的问题
  6. gateway 整合 websocket demo
  7. c#根据配置文件反射
  8. net.sf.json.JSONObject处理 &quot;null&quot; 字符串的一些坑
  9. SQL Server 等待统计信息基线收集
  10. Python爬虫学习==&gt;第十章:使用Requests+正则表达式爬取猫眼电影