fuchengshen
2022-07-04 343ba87e09501be7a63abde000a43e13a5b4f03e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//定义的geoserver发布的pdf的Sld样式
 
(function (window) {
    class MarsPbfStyle {
        constructor(options) {
            this.options = options;
            this.ol = window.ol;
        }
 
        //对外主要方法
        getStyle() {
            let that = this;
 
            return function (feature, resolution) { 
                that.type = feature.getGeometry().getType();
                that.properties = feature.getProperties();
                that.resolution = resolution;
                that.scale = 1 / (0.0254 / (96 * resolution));
 
                //通过外部接口获取style配置信息
                var styleCfg = that.options.getStyle(that.properties, that);
 
                var style = {};
                if (styleCfg.stroke) {//线
                    style.stroke = new ol.style.Stroke({ color: styleCfg.color, width: styleCfg.width });;
                }
                if (styleCfg.fill) {//面
                    style.fill = new ol.style.Fill({ color: styleCfg.fillColor });
                }
 
                // 组装层级样式
                style.zIndex = that.options.zIndex || 1;
 
                return [new ol.style.Style(style)];
            }
        }  
    }
 
    //对外接口 
    window.mars3d.MarsPbfStyle = MarsPbfStyle;
 
 
})(window);