xy-map 1.0.8 → 1.0.10

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.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "xy-map",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "地图组件",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "dev": "npm run serve",
8
8
  "serve": "vue-cli-service serve",
9
9
  "build": "vue-cli-service build",
10
- "lint": "vue-cli-service lint"
10
+ "lint": "vue-cli-service lint",
11
+ "pub": "npm publish"
11
12
  },
12
13
  "dependencies": {
13
14
  "@turf/turf": "^6.5.0",
@@ -4,6 +4,9 @@ import {
4
4
  hasLayer,
5
5
  setSource
6
6
  } from './index'
7
+ import {
8
+ addLayerText
9
+ } from './Text'
7
10
  import {
8
11
  mapClick
9
12
  } from '../util/mapEvent'
@@ -77,6 +80,11 @@ export const addLayerPoint = (option, layerId) => { // 点
77
80
  if (opt.click) {
78
81
  mapClick(id, opt.click)
79
82
  }
83
+
84
+ // 添加文本图层
85
+ if (opt.text && opt.text.show) {
86
+ addLayerText('point', opt)
87
+ }
80
88
  }
81
89
 
82
90
  /**
@@ -248,4 +256,4 @@ export const clusterLayer = (option, style) => {
248
256
  mapClick(id + 'clusters', (e) => {
249
257
  mapSdk.zoom('in', e.position)
250
258
  })
251
- }
259
+ }
package/src/map.js CHANGED
@@ -80,7 +80,8 @@ class mapSdk {
80
80
  * 地图平移到某个点
81
81
  */
82
82
  easeTo(position, duration = 1000) {
83
- this.map.easeTo({
83
+ let map = this.map
84
+ map.easeTo({
84
85
  center: position,
85
86
  duration
86
87
  })
@@ -320,10 +321,12 @@ class mapSdk {
320
321
  zoom(type, center = '') {
321
322
  const maxZoom = this.options.maxZoom || 18
322
323
  const minZoom = this.options.minZoom || 6
323
- let zoom = this.map.getZoom()
324
+ let map = this.map
325
+ let zoom = map.getZoom()
324
326
  if (!center) {
325
- center = this.map.getCenter()
327
+ center = map.getCenter()
326
328
  }
329
+ console.log(center)
327
330
  if (type === 'in') {
328
331
  // 点击+
329
332
  if (zoom < maxZoom) {
@@ -334,7 +337,7 @@ class mapSdk {
334
337
  zoom -= 1
335
338
  }
336
339
  }
337
- this.map.flyTo({
340
+ this.flyTo({
338
341
  center,
339
342
  zoom
340
343
  })
@@ -2,12 +2,6 @@ import Vue from 'vue'
2
2
  import VueRouter from 'vue-router'
3
3
 
4
4
  import layout from '../views/layout/index.vue'
5
- import home from '../views/home.vue'
6
- import document from '../views/document/index.vue'
7
-
8
- import init from '../views/demo/init.vue'
9
- import flyTo from '../views/demo/flyTo.vue'
10
- import tools from '../views/demo/tools.vue'
11
5
 
12
6
  Vue.use(VueRouter)
13
7
 
@@ -17,7 +11,7 @@ const routes = [{
17
11
  children: [{
18
12
  path: '',
19
13
  name: '首页',
20
- component: home,
14
+ component: () => import('@/views/home.vue'),
21
15
  }]
22
16
  },
23
17
  {
@@ -26,17 +20,22 @@ const routes = [{
26
20
  children: [{
27
21
  path: 'init',
28
22
  name: '初始化',
29
- component: init,
23
+ component: () => import('@/views/demo/init.vue'),
30
24
  },
31
25
  {
32
26
  path: 'flyTo',
33
27
  name: '飞入到指定地点',
34
- component: flyTo,
28
+ component: () => import('@/views/demo/flyTo.vue'),
35
29
  },
36
30
  {
37
31
  path: 'tools',
38
32
  name: '获取摄像机位置',
39
- component: tools,
33
+ component: () => import('@/views/demo/tools.vue'),
34
+ },
35
+ {
36
+ path: 'points',
37
+ name: '点',
38
+ component: () => import('@/views/demo/points.vue'),
40
39
  },
41
40
  ]
42
41
  },
@@ -46,7 +45,7 @@ const routes = [{
46
45
  children: [{
47
46
  path: 'index',
48
47
  name: '文档',
49
- component: document,
48
+ component: () => import('@/views/document/index.vue'),
50
49
  }]
51
50
  }
52
51
  ]
@@ -17,7 +17,9 @@ export default {
17
17
  container: 'map',
18
18
  zoom: 2,
19
19
  minZoom: 2,
20
- center: [102.83643451528434, 24.81972792178513]
20
+ center: [102.83643451528434, 24.81972792178513],
21
+ pitch: 0,
22
+ bearing: 0
21
23
  },
22
24
  view3D: true
23
25
  }
@@ -3,19 +3,13 @@
3
3
  ref="full_el">
4
4
  <div id="map"
5
5
  class="full-height"></div>
6
-
7
- <show-code title="初始化地图"></show-code>
8
6
  </div>
9
7
  </template>
10
8
 
11
9
  <script>
12
10
  import { mapSdk } from '@/index.js'
13
- import showCode from './components/showCode.vue'
14
11
 
15
12
  export default {
16
- components: {
17
- showCode
18
- },
19
13
  data () {
20
14
  return {
21
15
  config: {
@@ -24,6 +18,8 @@ export default {
24
18
  zoom: 2,
25
19
  minZoom: 2,
26
20
  center: [102.83643451528434, 24.81972792178513],
21
+ pitch: 0,
22
+ bearing: 0
27
23
  },
28
24
  view3D: true
29
25
  }
@@ -35,7 +31,6 @@ export default {
35
31
  init () {
36
32
  mapSdk.initMap(this.config).then(map => {
37
33
  this.map = map
38
- console.log(map)
39
34
  })
40
35
  }
41
36
  }
@@ -0,0 +1,68 @@
1
+ <template>
2
+ <div class="full-height relative overflow">
3
+ <div id="map"
4
+ class="full-height"></div>
5
+ </div>
6
+ </template>
7
+
8
+ <script>
9
+ import { mapSdk, mapDraw, mapTools } from '@/index.js'
10
+
11
+ const { addLayerPoint, addLayerImagePoint } = mapDraw
12
+ const { toGeoJson } = mapTools
13
+
14
+
15
+ export default {
16
+ data () {
17
+ return {
18
+ config: {
19
+ accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
20
+ container: 'map',
21
+ center: [131.05098966709647, 45.805820772845436],
22
+ pitch: 62,
23
+ zoom: 12,
24
+ bearing: 15.6,
25
+ },
26
+ view3D: true,
27
+ data: [
28
+ { id: 1, name: '测试点1', lnglat: [131.1515798484043, 45.85405632167139] },
29
+ { id: 2, name: '测试点2', lnglat: [131.04196826087988, 45.85512848048487] }
30
+ ]
31
+ }
32
+ },
33
+ mounted () {
34
+ this.init()
35
+ },
36
+ methods: {
37
+ init () {
38
+ mapSdk.initMap(this.config).then(map => {
39
+ this.map = map
40
+
41
+ this.getPoint2()
42
+ })
43
+ },
44
+ getPoint2 () {
45
+ let data = toGeoJson(this.data, 'Point', 'lnglat')
46
+ addLayerPoint({
47
+ id: 'point2',
48
+ data: data,
49
+ text: {
50
+ show: true,
51
+ layout: {
52
+ 'text-field': '{name}',
53
+ 'text-offset': [0, 1.2]
54
+ }
55
+ },
56
+ click: (e) => {
57
+ console.log(e)
58
+ // 添加弹窗
59
+ mapSdk.addPopup(e.position, '<div>point</div>')
60
+
61
+ // 平移到该坐标
62
+ mapSdk.easeTo(e.position)
63
+ }
64
+ })
65
+ }
66
+ }
67
+ }
68
+ </script>
@@ -6,13 +6,18 @@
6
6
 
7
7
  <!-- 工具 -->
8
8
  <div class="tools flex">
9
- <button @click="getCamera">获取摄像机</button>
10
- <button @click="getLayer">获取所有图层</button>
9
+ <button @click="flyHome(2000)">默认视角</button>
11
10
 
12
11
  <button @click="view2D"
13
12
  v-if="view3D">2D视角</button>
14
13
  <button @click="flyHome(2000)"
15
14
  v-else>3D视角</button>
15
+
16
+ <button @click="zoom('in')">放大</button>
17
+ <button @click="zoom('out')">缩小</button>
18
+
19
+ <button @click="getCamera">获取摄像机</button>
20
+ <button @click="getLayer">获取所有图层</button>
16
21
  </div>
17
22
  </div>
18
23
  </template>
@@ -26,7 +31,7 @@ export default {
26
31
  data () {
27
32
  return {
28
33
  config: {
29
- accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2t4NzAxZzdvMDZ5MTJ2azN0NzBqZGt0bCJ9.cRDXTquac05DVKJ5wc854w',
34
+ accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
30
35
  container: 'map',
31
36
  zoom: 11.2,
32
37
  minZoom: 2,
@@ -41,15 +46,17 @@ export default {
41
46
  this.init()
42
47
  },
43
48
  methods: {
49
+ // 初始化
44
50
  init () {
45
51
  mapSdk.initMap(this.config).then(map => {
46
52
  this.map = map
47
53
  })
48
54
  },
49
- getCamera () {
50
- this.$message.info('请按【F12】打开控制台查看')
51
- mapSdk.getCamera()
55
+ // 放大/缩小
56
+ zoom (type) {
57
+ mapSdk.zoom(type)
52
58
  },
59
+ // 2D视角
53
60
  view2D () {
54
61
  this.view3D = false
55
62
  mapSdk.flyTo({
@@ -63,6 +70,7 @@ export default {
63
70
  mapSdk.pitchWithRotate(false) // 禁用旋转视角
64
71
  })
65
72
  },
73
+ // 默认视角
66
74
  flyHome (duration = 3000) {
67
75
  return new Promise((resolve) => {
68
76
  this.view3D = true
@@ -78,6 +86,12 @@ export default {
78
86
  })
79
87
  })
80
88
  },
89
+ // 获取摄像机
90
+ getCamera () {
91
+ this.$message.info('请按【F12】打开控制台查看')
92
+ mapSdk.getCamera()
93
+ },
94
+ // 获取所有图层
81
95
  getLayer () {
82
96
  this.$message.info('请按【F12】打开控制台查看')
83
97
  console.log(getLayerAll())
@@ -90,7 +104,7 @@ export default {
90
104
  <style lang="scss" scoped>
91
105
  .tools {
92
106
  position: absolute;
93
- right: 10px;
107
+ right: 0;
94
108
  top: 0;
95
109
  margin: 10px;
96
110
 
@@ -62,6 +62,11 @@ export default {
62
62
  id: '2-3',
63
63
  name: '地图工具',
64
64
  link: '/demo/tools',
65
+ },
66
+ {
67
+ id: '2-4',
68
+ name: '点',
69
+ link: '/demo/points',
65
70
  }
66
71
  ]
67
72
  }
@@ -1,51 +0,0 @@
1
- <template>
2
- <div class="code">
3
- <el-button @click="show = !show">查看代码</el-button>
4
-
5
- <el-drawer :title="title"
6
- :with-header="false"
7
- :visible.sync="show"
8
- direction="rtl">
9
- <div class="code-header flex flex-justify-between border-bottom">
10
- <b class="font-15">{{title}}</b>
11
- <i class="el-icon-close pointer"
12
- title="关闭"
13
- @click="show = false"></i>
14
- </div>
15
- <div>{{code}}</div>
16
- </el-drawer>
17
- </div>
18
- </template>
19
-
20
- <script>
21
- export default {
22
- props: {
23
- title: {
24
- type: String,
25
- default: '查看'
26
- },
27
- code: {
28
- type: String,
29
- default: ''
30
- }
31
- },
32
- data () {
33
- return {
34
- show: false,
35
- }
36
- }
37
- }
38
- </script>
39
-
40
- <style lang="scss" scoped>
41
- .code {
42
- position: absolute;
43
- bottom: 0;
44
- right: 0;
45
- margin: 15px;
46
-
47
- .code-header {
48
- padding: 15px;
49
- }
50
- }
51
- </style>