openlayers4中用font设置图标样式

概述

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
联系方式

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

LZUGIS

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牛老师讲GIS

感谢老板支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值