美文网首页开源GIS加油站Gis专辑
openlayers4中用font设置图标样式

openlayers4中用font设置图标样式

作者: 牛老师讲webgis | 来源:发表于2018-05-29 15:04 被阅读34次

    概述

    font其实是个好东西,不论是写css还是。。。,这不,牛老师想把它用在openlayers4中,用以很方便的设置图标的大小、颜色,还不失真,东拼西凑,终于算是完成了。

    效果

    font样式

    换个大小?

    改变大小

    换个颜色?

    改变颜色

    先炫耀到这吧,确实很6啊。。。

    实现

    1、样式引入

    <link rel="stylesheet" type="text/css" href="css/iconfont.css"/>
    

    2、iconfont.css

    @charset "utf-8";
    
    @font-face {font-family: "iconfont";
      src: url('./iconfont.woff?t=1502264184772') format('woff'); 
    }
    

    3、样式设置

            function styleFunc (feature, resolution) {
                var iconFont = 'iconfont';
                var iconFontText = "\S"; // equates to fa-trash icon
                var iconSize = 6 * map.getView().getZoom();
                var col = '#00f';
    
                var styleIcon = new ol.style.Style({
                    text: new ol.style.Text({
                        font: 'Normal ' + iconSize + 'px ' + iconFont,
                        text: iconFontText,
                        fill: new ol.style.Fill({ color: col }),
                        textBaseline: 'bottom'
                    })
                });
                return styleIcon;
            }
    

    技术博客
    CSDN:http://blog.csdn.NET/gisshixisheng
    在线教程
    https://edu.csdn.net/course/detail/799
    https://edu.csdn.net/course/detail/7471
    联系方式

    类型 内容
    qq 1004740957
    公众号 lzugis15
    e-mail niujp08@qq.com
    webgis群 452117357
    Android群 337469080
    GIS数据可视化群 458292378
    LZUGIS

    相关文章

      网友评论

      • yyyzhen:老师您好,我在vue中使用ol5尝试设置font图标,代码和上面的例子基本一样,只有上面设置的iconFontText中的内容不太一样,unicode和content中的内容我尝试放入但都无效,不知您的 "\S" 是从哪里得到的

      本文标题:openlayers4中用font设置图标样式

      本文链接:https://www.haomeiwen.com/subject/psfajftx.html