首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenLayers 3动态样式

OpenLayers 3动态样式
EN

Stack Overflow用户
提问于 2016-09-16 21:38:28
回答 1查看 1.3K关注 0票数 1

我需要能够样式的地图上的要素后,他们已经渲染了每个用户的选择。

目前我正在添加这样的样式...

代码语言:javascript
复制
style: function (feature, resolution) {
                            var text = resolution * 100000 < 10 ? response.text : '';

                            if (text != "") {
                                styleCache[text] = [new ol.style.Style({
                                    stroke: new ol.style.Stroke({
                                        color: '#319FD3',
                                        width: 1
                                    }),
                                    text: new ol.style.Text({
                                        font: '12px Calibri,sans-serif',
                                        text: text,
                                        fill: new ol.style.Fill({
                                            color: '#000'
                                        }),
                                        stroke: new ol.style.Stroke({
                                            color: '#fff',
                                            width: 3
                                        })
                                    }),
                                    fill: new ol.style.Fill({
                                        color: colorFromDatabase
                                    })
                                })];
                            }
                            else if (text == "") {
                                styleCache[text] = [new ol.style.Style({
                                    fill: new ol.style.Fill({
                                        color: colorFromDatabase
                                    })
                                })
                                ]
                            } return styleCache[text];
                        }

...I需要能够进入并更改填充、笔触等。渲染后,我已经有了有限的“成功”...if,这就是你想要称之为it...making所有功能的黑色。

非常感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2016-09-21 00:12:36

谢谢@Jonatas Walker在你的帮助下我最终得到了这个...

代码语言:javascript
复制
var source = webLayer.getSource();
var features = source.getFeatures();

var templateStyle = new ol.style.Style({
     fill: new ol.style.Fill({ color: convertHex(Layer.LayerStyle.FillColor, '0.5') }),
     stroke: new ol.style.Stroke({ color: convertHex(Layer.LayerStyle.LineColor, '0.5') }),
     text: new ol.style.Text({
        font: '24px Verdana',
        text: webLayer.U.label,
        offsetY: 20,
        fill: new ol.style.Fill({
            color: [255, 255, 255, 0.8]
        })
    })
});


var select = new ol.interaction.Select({
    style: templateStyle
});

map.addInteraction(select);
webLayer.setVisible(Visibility);
features[0].setStyle(templateStyle);

这就是应用样式!!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39532949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档