liuyg
2021-07-16 5db28e39983bb71c6e250b00a5c19fe6b0f82e2d
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!--
 * @Descripttion:
 * @version:
 * @Author: song
 * @Date: 2021-04-08 15:14:57
 * @LastEditors: song
 * @LastEditTime: 2021-04-24 11:59:43
-->
<template>
    <div id="map"
         style="height: 100%"></div>
</template>
<script>
import OLCesium from 'olcs/OLCesium.js'
import 'ol/ol.css'
import OlView from 'ol/View.js'
import XYZ from 'ol/source/XYZ'
import OlLayerTile from 'ol/layer/Tile.js'
import OlMap from 'ol/Map.js'
 
import {
    // eslint-disable-next-line no-unused-vars
    defaults as OlControlDefaults,
    defaults,
    // 全屏控件
    FullScreen,
    // 比例尺控件
    ScaleLine,
    // 缩放滚动条控件
    // eslint-disable-next-line no-unused-vars
    ZoomSlider,
    // 鼠标位置控件
    // eslint-disable-next-line no-unused-vars
    MousePosition,
    // -地图属性控件
    Attribution,
    // 鹰眼控件
    // eslint-disable-next-line no-unused-vars
    OverviewMap,
    // 缩放到范围控件
    // eslint-disable-next-line no-unused-vars
    ZoomToExtent,
    Rotate
 
} from 'ol/control.js'
 
import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
 
import Feature from 'ol/Feature.js'
import Point from 'ol/geom/Point.js'
import LineString from 'ol/geom/LineString.js'
import { Icon, Style, Fill, Stroke } from 'ol/style.js'
 
export default {
    name: 'Map',
    data () {
        return {
            gunAddlayer: new VectorLayer({ // 图标图层
                zIndex: 22,
                source: new VectorSource()
            }),
            peopleAddlayer: new VectorLayer({ // 图标图层
                zIndex: 22,
                source: new VectorSource()
            }),
            carAddlayer: new VectorLayer({ // 图标图层
                zIndex: 22,
                source: new VectorSource()
            }),
            peopleLineAddlayer: new VectorLayer({ // 图标图层
                zIndex: 22,
                source: new VectorSource()
            }),
        }
    },
    mounted () {
        const ol2d = new OlMap({
            layers: [
                new OlLayerTile({
                    zIndex: 4,
                    title: '影像',
                    source: new XYZ({
                        url: 'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=e9533f5acb2ac470b07f406a4d24b4f0' // 行政区划
                    })
                }),
                new OlLayerTile({
                    zIndex: 5,
                    title: '道路+中文注记',
                    source: new XYZ({
                        url: 'http://t3.tianditu.com/DataServer?T=cta_w&x={x}&y={y}&l={z}&tk=e9533f5acb2ac470b07f406a4d24b4f0' // 注记
                    })
                })
            ],
 
            // 注意地图控件的写法
            controls: defaults().extend([
                new FullScreen(),
                new ScaleLine(),
                new MousePosition(),
                new Rotate(),
                new Attribution()
            ]),
            target: 'map',
            view: new OlView({
                center: [0, 0],
                zoom: 2,
                projection: 'EPSG:4326'
            })
        })
        window.ol2d = ol2d
 
        var view = ol2d.getView()
 
        view.setCenter([115.85883507433789, 28.708432053474827])
 
        view.setZoom(13)
 
        const ol3d = new OLCesium({ map: window.ol2d })
        window.ol3d = ol3d
 
        ol2d.addLayer(this.gunAddlayer)
        ol2d.addLayer(this.peopleAddlayer)
        ol2d.addLayer(this.carAddlayer)
        ol2d.addLayer(this.peopleLineAddlayer)
        this.addLines()
    },
    methods: {
        init3D (val) {
            window.ol3d.setEnabled(val)
        },
        addEntitys (item, icon, scale, name, type) {
            const iconFeature = new Feature({
                geometry: new Point([Number(item.LGTD), Number(item.LTTD)]),
                name: name,
                attributes: item
            })
 
            const iconStyle = new Style({
                // text: new Text({ // 字体, 未成功, 浪费许多时间
                //   font: 'Normal ' + 12 + 'px ' + 'iconfont',
                //   text: "\e645",
                //   fill: new Fill({ color: "green" }),
                // }),
 
                image: new Icon({
                    scale: scale,
                    opacity: 1,
                    src: icon
                    // src: require('../../assets/Mark.png')
                })
 
                // new CircleStyle({ // 普通样式
                //   radius: 6,
                //   fill: new Fill({
                //     color: 'rgba(200, 155, 155, 0.8)'
                //   }),
                //   stroke: new Stroke({
                //     color: 'black',
                //     width: 0.3,
                //   })
                // }),
            })
 
            iconFeature.setStyle(iconStyle)
 
            this[type].getSource().addFeature(iconFeature)
        },
 
        addLines () {
 
            // 点坐标
            var lineCoords = [
              [115.87471898408013, 28.720924466928977],
              [115.87471898408013, 28.724163802651635],
              [115.87401037939081, 28.72456871961697],
              [115.87147964835748, 28.7246699488583],
              [115.86925260504815, 28.7246699488583],
              [115.86621572780817, 28.7246699488583],
              [115.8635837675335, 28.72578347051296]
              ];// 线里点的集合
 
            // 要素
            // var lineCoords = [[featureInfo.lineString[0][0],featureInfo.lineString[0][0]],[featureInfo.lineString(0),featureInfo.lineString(0)]];
            var feature_LineString = new Feature({
                geometry: new LineString(lineCoords)
            });
 
 
            feature_LineString.setStyle(new Style({
                //填充色
                fill: new Fill({
                    color: 'rgba(255, 255, 255, 0.2)'
                }),
                //边线颜色
                stroke: new Stroke({
                    color: 'rgb(252, 94, 32)',
                    width: 5
                })
            }))
 
 
            this.peopleLineAddlayer.getSource().addFeature(feature_LineString)
 
        }
    }
}
</script>