zhangjiaqing
3 天以前 f5f65e6a9a49709c451dc2efd253970b5ae41f69
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
业主详情页面
 **/
(function(vc) {
    vc.extends({
        data: {
            parkingMapInfo: {
                datas: [],
                parkStatusList: [],
                conditions: {
                    communityId: vc.getCurrentCommunity().communityId
                }
            }
        },
        _initMethod: function() {
 
            $that._loadDatas();
 
 
        },
        _initEvent: function() {
 
        },
        methods: {
            _loadDatas: function() {
                let param = {
                        params: $that.parkingMapInfo.conditions
                    }
                    //发送get请求
                vc.http.apiGet('/parkingSpace.queryParkingMap',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.parkingMapInfo.datas = _json;
                        $that._initParkingMap();
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _initParkingMap: function() {
                const parkStatusList = [{
                        id: 86,
                        status: 1
                    }]
                    //加载geo数据
                const source = new ol.source.Vector({
                    features: (new ol.format.GeoJSON()).readFeatures({
                        type: 'FeatureCollection',
                        features: $that.parkingMapInfo.datas.map(v => {
                            const geoJson = JSON.parse(v.geo);
                            //添加属性
                            geoJson.properties.type = v.type;
                            geoJson.properties.num = v.num;
                            geoJson.properties.ID = v.ID;
                            return geoJson;
                        })
                    })
                });
                //定义块样式
                const partStyle = new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#ffcc33',
                        width: 3
                    })
                });
                const parkStyle = new ol.style.Style({
                    text: new ol.style.Text({
                        textAlign: 'center',
                        overflow: false, //永久显示
                        font: 'bold 20px 微软雅黑',
                        fill: new ol.style.Fill({
                            color: 'black'
                        })
                    })
                });
                const redStyle = new ol.style.Style({
                    fill: new ol.style.Fill({
                        color: 'rgba(255,0,0,0.5)',
                    })
                });
                const greenStyle = new ol.style.Style({
                    fill: new ol.style.Fill({
                        color: 'rgba(0,255,0,0.5)',
                    })
                });
                //初始化图层
                const vectorLayer = new ol.layer.Vector({
                    background: 'lightgray',
                    source: source,
                    style: function(feature) {
                        const { type, num, ID } = feature.getProperties();
                        const styles = [partStyle];
                        if (type == '车位') {
                            parkStyle.getText().setText(num);
                            styles.push(parkStyle);
                            if (parkStatusList.find(v => v.id == ID)?.status) {
                                styles.push(redStyle);
                            } else {
                                styles.push(greenStyle);
                            }
                        }
                        return styles;
                    }
                });
                const view = new ol.View({
                    center: [0, 0],
                    zoom: 1,
                });
                //初始化画布
                const map = new ol.Map({
                    layers: [
                        vectorLayer,
                    ],
                    target: 'map',
                    view: view,
                });
                //定位
                view.fit(source.getExtent(), {
                    nearest: true,
                    padding: [0, 250, 0, 0]
                })
            },
            refreshParkStatus: function() {
                parkStatusList[0].status = !parkStatusList[0].status;
                vectorLayer.changed();
            }
 
 
        }
    });
})(window.vc);