记一次openlayers 添加交互修改样式的Bug
2018-01-19 20:11
369 查看
openlayers版本:4.6.4
实现功能:鼠标移入要素修改要素的样式
效果:
鼠标移入前:
鼠标移入后:
移入前样式代码:这里使用的styleFunction
//面样式方法 polygonStyleFunction:function(feature,resource){ var style = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(255, 255, 255, 0)' }), stroke: new ol.style.Stroke({ color: '#5076b3', width: 0.5 }), text: new ol.style.Text({ font: '12px 微软雅黑,sans-serif', fill: new ol.style.Fill({ color: '#ffffff' }), placement:'point', //标签的边框 backgroundStroke:new ol.style.Stroke({ color:'#4D98DD', width:1 }), //标签的背景填充 backgroundFill:new ol.style.Fill({ color:'#4D98DD' }) }) }); if(feature.get('name')){ style.getText().setText(feature.get('name')); } return [style]; }
鼠标移入后样式:
var polygonHighlightStyle = new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ff1824', width: 2 }), fill: new ol.style.Fill({ color: 'rgba(255,0,0,0.0)' }), text: new ol.style.Text({ font: '12px 微软雅黑,sans-serif', fill: new ol.style.Fill({ color: '#4c76cc' }), placement:'point', backgroundStroke:new ol.style.Stroke({ color:'#feff2a', width:1 }), backgroundFill:new ol.style.Fill({ color:'#feff2a' }), text:"测试" }) }); // TODO 滑过高亮---------移入高亮 polygonPointerMove = new ol.interaction.Select({ condition: ol.events.condition.pointerMove, /** 移动触发*/ style:function (feature) { if(feature.get('name')){ polygonHighlightStyle.getText().setText(feature.get('name')); } return [polygonHighlightStyle]; }, layers:[beijingLayer,jiedaoLayer,shequLayer] });
到这里,一切正常,效果也符合预期,鼠标移入时,字体替换为 黄底蓝字的样式,移到其他也没什么问题。。
滑着滑着就出现了一个问题:
当移到中间这个要素的时候,其他样式的Text属性的 背景全消失了,而只有移入这个要素的时候才会有这个问题。。。。。。。。。。。。。。。
我以为时哪里出现了问题,然后换其他图层,
然后试了很多种方法,都无法解决这个问题,当我想是不是要素加载的顺序的原因的时候发现也不是这个问题
如果有大神知道请告诉我
相关文章推荐
- uploadify 插件使用 包含 增删,修改样式,类似邮箱里的 添加附件 功能,也修复了uploadify存在的bug
- 为extjs的TabPanel 添加右键关闭效果(修改一个bug)
- vue开发中,父组件添加scoped之后。解决在父组件中无法修改子组件样式问题。
- css添加修改样式
- android线程 Handler Message Queue AsyncTask线程模型 线程交互 + 修改Button样式 示例 最终easy整合版
- 一次添加硬盘分区并修改/etc/fstab引起的故障
- jquery之修改元素样式(添加和删除类名称,使用addClass(),removeClass(),toggleClass()方法)
- 添加多个tab,并循环修改tab样式
- Mysql复习--添加字段,删除字段,一次多行插入,修改字段名和类型,分组查询,建类似表,
- 织梦后台添加自定义字段样式修改
- 修改ASP.NET MVC Ajax分页组件ASP.NET MvcPager一个小Bug并修该样式为自己所用(三)
- 修改一行代码,解决在C++ Builder平台上JSONCPP向数组添加元素的Bug
- 在项目开发中,jsp页面不会少了,如何公用页面(添加页面和修改页面)和公用样式代码(css,js)?
- 使用jquery对片段的样式进行添加修改
- android线程 Handler Message Queue AsyncTask线程模型 线程交互 + 修改Button样式 示例 最终easy整合版
- 添加,查询,修改,删除测试方法及常见bug说明
- 如何不修改OpenLayers源代码修正其Bug