v-ol-map 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,194 +0,0 @@
1
- <template>
2
- <div :id="target" :style="{'width':mapWidth,'height':mapHeight}">
3
- <a :id="downLoadId" :download="downloadName"></a>
4
- <slot v-if="load"></slot>
5
- </div>
6
- </template>
7
-
8
- <script>
9
- import { nanoid } from 'nanoid'
10
- import { OlMap } from '@/utils/index.js'
11
-
12
- export default {
13
- name: 'v-map',
14
- provide () {
15
- return {
16
- VMap: this
17
- }
18
- },
19
- props: {
20
- // 地图容器宽度
21
- width: {
22
- type: [String, Number],
23
- default () {
24
- return '100%'
25
- }
26
- },
27
- // 地图容器高度
28
- height: {
29
- type: [String, Number],
30
- default () {
31
- return '100%'
32
- }
33
- },
34
- // 地图容器Id
35
- target: {
36
- type: String,
37
- default: `map-${nanoid()}`
38
- },
39
- // 视窗属性
40
- view: {
41
- type: Object
42
- },
43
- // 未引入tile组件时默认加载图层
44
- defaultTile: {
45
- type: String,
46
- default: 'TD'
47
- },
48
- // 控制属性
49
- controls: {
50
- type: Object
51
- },
52
- // 控制类扩展
53
- controlsExtend: {
54
- type: Object
55
- },
56
- // 交互属性
57
- interactions: {
58
- type: Object
59
- },
60
- // 交互类扩展
61
- interactionsExtend: {
62
- type: Object
63
- }
64
- },
65
- computed: {
66
- mapOption () {
67
- return {
68
- target: this.target,
69
- view: this.view,
70
- controls: this.controls,
71
- interactions: this.interactions
72
- }
73
- },
74
- map () {
75
- return OlMap.map.map
76
- },
77
- mapWidth () {
78
- return typeof this.width === 'string' ? this.width : this.width.toString() + 'px'
79
- },
80
- mapHeight () {
81
- return typeof this.height === 'string' ? this.height : this.height.toString() + 'px'
82
- }
83
- },
84
- watch: {
85
- 'view.center': {
86
- handler (value) {
87
- if (value) {
88
- OlMap.panTo(value)
89
- }
90
- },
91
- immediate: false,
92
- deep: true
93
- }
94
- },
95
- data () {
96
- return {
97
- vMap: null,
98
- load: false,
99
- downLoadId: `download-${nanoid()}`,
100
- downloadName: 'map.png',
101
- noBase: true,
102
- properties: {
103
- isDefault: true
104
- },
105
- modify: null,
106
- select: null,
107
- translates: null,
108
- dragRotateAndZoom: null,
109
- fullScreen: null
110
- }
111
- },
112
- methods: {
113
- init () {
114
- return new Promise((resolve, reject) => {
115
- OlMap.map = new OlMap(this.mapOption)
116
- if (OlMap.map.map) {
117
- resolve('success')
118
- } else {
119
- reject(new Error('fail'))
120
- }
121
- })
122
- },
123
- dispose () {
124
- if (!this.map) return
125
- const layers = [...this.map.getLayers().getArray()]
126
- layers.forEach(layer => {
127
- if (layer) {
128
- const layerTitle = layer.get('users')
129
- if (layerTitle) {
130
- console.log('destroying layer', layerTitle)
131
- layer.getSource().clear()
132
- layer.getRenderer().dispose()
133
- layer.setSource(undefined)
134
- this.map.removeLayer(layer)
135
- }
136
- }
137
- })
138
- this.map.disposeInternal()
139
- },
140
- zoomEnd (evt) {
141
- this.$emit('changeZoom', evt, this.map)
142
- evt.map.once('moveend', (evt) => {
143
- this.zoomEnd(evt)
144
- })
145
- }
146
- },
147
- mounted () {
148
- this.init().then(res => {
149
- if (res === 'success') {
150
- // 点击事件
151
- this.map.on('singleclick', (r) => {
152
- this.$emit('click', r, this.map)
153
- this.map.forEachSmFeatureAtPixel(r.pixel, (i, e) => {
154
- this.$emit('onClickFeature', i, e, r)
155
- }, {}, r)
156
- })
157
- // 层级变化
158
- this.map.getView().once('change:resolution', () => {
159
- this.map.once('moveend', (evt) => {
160
- this.zoomEnd(evt)
161
- })
162
- })
163
- // 鼠标悬浮
164
- this.map.on('pointermove', evt => {
165
- const pixel = this.map.getEventPixel(evt.originalEvent)
166
- const hit = this.map.hasFeatureAtPixel(pixel)
167
- this.map.getTargetElement().style.cursor = hit ? 'pointer' : ''
168
- this.map.getLayers().getArray().forEach(layer => {
169
- if (layer.get('type') === 'graphic') {
170
- const data = layer.getData(evt.pixel)
171
- const hitImage = data && data[3] > 0 // transparent pixels have zero for data[3]
172
- this.map.getTargetElement().style.cursor = hitImage || hit ? 'pointer' : ''
173
- }
174
- })
175
- this.$emit('pointermove', evt, this.map)
176
- })
177
- // 鼠标右键
178
- this.map.on('contextmenu', evt => {
179
- this.$emit('contextmenu', evt, this.map)
180
- })
181
- this.$emit('load')
182
- this.load = true
183
- }
184
- })
185
- },
186
- beforeUnmount () {
187
- this.dispose()
188
- }
189
- }
190
- </script>
191
-
192
- <style scoped>
193
-
194
- </style>
package/src/main.js DELETED
@@ -1,10 +0,0 @@
1
- import Vue from 'vue'
2
- import App from './App.vue'
3
- import olMap from '@/components/index'
4
-
5
- Vue.config.productionTip = false
6
- Vue.use(olMap)
7
-
8
- new Vue({
9
- render: h => h(App)
10
- }).$mount('#app')