ry-vue-map 0.6.2 → 0.6.3

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/README.MD CHANGED
@@ -1,5 +1,5 @@
1
1
  # ryvuemap
2
- ![ryui-version](https://img.shields.io/badge/ryvuemap-0.6.2-green)
2
+ ![ryui-version](https://img.shields.io/badge/ryvuemap-0.6.3-green)
3
3
  > ry公共组件库
4
4
 
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ry-vue-map",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "private": false,
5
5
  "main": "lib/ryui.umd.min.js",
6
6
  "description": "ry公共组件库",
@@ -45,7 +45,7 @@
45
45
  "kml-to-geojson": "^1.0.13",
46
46
  "nprogress": "~0.2.0",
47
47
  "ol": "^6.14.1",
48
- "ry-map": "^0.5.2",
48
+ "ry-map": "^0.5.3",
49
49
  "vue": "~2.6.14",
50
50
  "vue-demi": "^0.13.11",
51
51
  "vue-router": "~3.5.2",
@@ -13,7 +13,7 @@ export default class RyKMLDto extends Base {
13
13
  type: Boolean,
14
14
  default: true,
15
15
  };
16
-
16
+
17
17
  // 清除多边形以及标记
18
18
  clear = {
19
19
  type: Boolean,
@@ -24,6 +24,13 @@ export default class RyKMLDto extends Base {
24
24
  isFit = {
25
25
  type: Boolean,
26
26
  default: true,
27
+ };
28
+
29
+
30
+ // 异步加载KML时间默认100毫秒
31
+ time = {
32
+ type: Number,
33
+ default: 100,
27
34
  };
28
35
 
29
36
  }
@@ -1,4 +1,3 @@
1
-
2
1
  import Base from '../base/base';
3
2
 
4
3
  export default class RyKMLDto extends Base {
@@ -43,4 +42,10 @@ export default class RyKMLDto extends Base {
43
42
  type: Object,
44
43
  default: () => null,
45
44
  };
46
- }
45
+
46
+ // 异步加载KML时间默认100毫秒
47
+ time = {
48
+ type: Number,
49
+ default: 100,
50
+ };
51
+ }
@@ -2,173 +2,175 @@
2
2
  </template>
3
3
 
4
4
  <script>
5
- import {
6
- fitNew,
7
- GPS,
8
- LKML,
9
- } from 'ry-map';
10
- import Dto from './../../models/ryKML/index.js';
11
- export default {
12
- name: 'RyKML',
13
- props: {
14
- ...new Dto(),
15
- },
16
- data() {
17
- return {
18
- bbox: [],
19
- bboxGCJ02: [],
20
- kml: null,
21
- lastType: -1,
22
- url:null,
23
- gcj02Url:null,
24
- };
25
- },
26
- watch: {
27
- model(val) {
28
- this._remove();
29
- if (!val) return;
30
- this.model = val;
31
- this.init(val);
32
- },
33
- clear(val) {
34
- if (val) {
35
- this._remove();
36
- }
37
- },
38
- isShow(val) {
39
- if (val) {
40
- this.showAll();
41
- return;
42
- }
43
- this.hideAll();
44
- },
45
- gpsType(val) {
46
- if (this.lastType == val) return;
47
- this.gpsType = val;
48
- this.lastType = val;
49
- this.selectGPSAll(this.gpsType);
50
- },
5
+ import {
6
+ fitNew,
7
+ GPS,
8
+ LKML,
9
+ } from 'ry-map';
10
+ import Dto from './../../models/ryKML/index.js';
11
+ export default {
12
+ name: 'RyKML',
13
+ props: {
14
+ ...new Dto(),
15
+ },
16
+ data() {
17
+ return {
18
+ bbox: [],
19
+ bboxGCJ02: [],
20
+ kml: null,
21
+ lastType: -1,
22
+ url: null,
23
+ gcj02Url: null,
24
+ };
25
+ },
26
+ watch: {
27
+ model(val) {
28
+ this._remove();
29
+ if (!val) return;
30
+ this.model = val;
31
+ this.init(val);
32
+ },
33
+ clear(val) {
34
+ if (val) {
35
+ this._remove();
36
+ }
37
+ },
38
+ isShow(val) {
39
+ if (val) {
40
+ this.showAll();
41
+ return;
42
+ }
43
+ this.hideAll();
44
+ },
45
+ gpsType(val) {
46
+ if (this.lastType == val) return;
47
+ this.gpsType = val;
48
+ this.lastType = val;
49
+ this.selectGPSAll(this.gpsType);
50
+ },
51
51
 
52
- },
52
+ },
53
53
 
54
- created() {
55
- this.lastType = this.gpsType;
56
- if(!this.model) return;
57
- this.init(this.model);
58
- },
54
+ created() {
55
+ this.lastType = this.gpsType;
56
+ if (!this.model) return;
57
+ this.init(this.model);
58
+ },
59
59
 
60
- methods: {
61
- init(model) {
62
- this._insert(model);
63
- if(this.isFit){
64
- setTimeout(() => {
65
- this.setFit();
66
- }, 50);
67
- }
68
-
69
- },
70
- _insert(dto) {
71
- const {
72
- id,
73
- url,
74
- bbox,
75
- is,
76
- stroke,
77
- fillColor,
78
- zIndex,
79
- width,
80
- extractStyles,
81
- gcj02Url
82
- } = dto;
83
- const lkml = new LKML({
84
- id,
85
- url: this.gpsType == 1 ? gcj02Url : url,
86
- bbox,
87
- is,
88
- stroke,
89
- fillColor,
90
- zIndex,
91
- width,
92
- },
93
- this.map,
94
- extractStyles);
95
- this.kml=lkml;
96
- this.url=url;
97
- this.gcj02Url=gcj02Url;
98
- this.setBBOXArr(bbox);
99
- },
100
- setBBOXArr(bbox) {
101
- this.bbox=bbox;
102
- const _bboxGCJ02 = this.convertBBoxGCJ02(bbox);
103
- this.bboxGCJ02=_bboxGCJ02;
104
- },
105
- setUrl(url) {
106
-
107
- if (this.kml) {
108
-
109
- this.kml.setUrl(url);
110
- }
111
- },
112
- setFit() {
113
-
114
- if (!this.bbox.length || !this.map) return;
115
- this.setFitFist(this.gpsType == 1 ? this.bboxGCJ02 : this.bbox);
116
- },
117
- // bbox.length =1 执行此处
118
- setFitFist(bbox) {
119
- const bbox2 = [bbox[0], bbox[3], bbox[2], bbox[1]];
120
- const bbox3 = [bbox[2], bbox[1], bbox[0], bbox[3]];
121
- fitNew(this.map, [bbox2, bbox3]);
122
- },
123
- convertBBoxGCJ02(bbox) {
124
- const pointArr = [];
125
- const {
126
- lat,
127
- lon
128
- } = GPS.gcj_encrypt(bbox[0], bbox[1]);
129
- const {
130
- lon: lon2,
131
- lat: lat2
132
- } = GPS.gcj_encrypt(bbox[2], bbox[3]);
133
- pointArr.push(lon);
134
- pointArr.push(lat);
135
- pointArr.push(lon2);
136
- pointArr.push(lat2);
137
- return pointArr;
138
- },
60
+ methods: {
61
+ async init(model) {
62
+ await this._insert(model);
63
+ if (this.isFit) {
64
+ setTimeout(() => {
65
+ this.setFit();
66
+ }, 50);
67
+ }
139
68
 
140
- _remove() {
141
- if(!this.kml) return;
142
- this.kml.removeKML();
143
- this.bbox = [];
144
- this.bboxGCJ02 = [];
145
- this.url=null;
146
- this.gcj02Url=null;
147
- },
69
+ },
70
+ async _insert(dto) {
71
+ const {
72
+ id,
73
+ url,
74
+ bbox,
75
+ is,
76
+ stroke,
77
+ fillColor,
78
+ zIndex,
79
+ width,
80
+ extractStyles,
81
+ gcj02Url
82
+ } = dto;
83
+ const lkml = new LKML({
84
+ id,
85
+ url: this.gpsType == 1 ? gcj02Url : url,
86
+ bbox,
87
+ is,
88
+ stroke,
89
+ fillColor,
90
+ zIndex,
91
+ width,
92
+ },
93
+ this.map,
94
+ extractStyles);
95
+ this.kml = lkml;
96
+ this.url = url;
97
+ this.gcj02Url = gcj02Url;
98
+ await lkml.init(this.time);
99
+ if (id) {
100
+ lkml.setId(id);
101
+ }
102
+ this.setBBOXArr(lkml.getExtent());
103
+ },
104
+ setBBOXArr(bbox) {
105
+ this.bbox = bbox;
106
+ const _bboxGCJ02 = this.convertBBoxGCJ02(bbox);
107
+ this.bboxGCJ02 = _bboxGCJ02;
108
+ },
109
+ setUrl(url) {
148
110
 
149
- selectGPSAll(type) {
150
- const url = type == 1 ? this.gcj02Url : this.url;
151
- this.setUrl(url);
152
- },
111
+ if (this.kml) {
153
112
 
154
- show() {
155
- if(!this.kml) return;
156
- this.kml.show();
157
- if(this.isFit){
158
- setTimeout(() => {
159
- this.setFit();
160
- }, 50);
161
- }
162
- },
113
+ this.kml.setUrl(url);
114
+ }
115
+ },
116
+ setFit() {
117
+ if (!this.bbox.length || !this.map) return;
118
+ this.setFitFist(this.gpsType == 1 ? this.bboxGCJ02 : this.bbox);
119
+ },
120
+ // bbox.length =1 执行此处
121
+ setFitFist(bbox) {
122
+ const bbox2 = [bbox[0], bbox[3], bbox[2], bbox[1]];
123
+ const bbox3 = [bbox[2], bbox[1], bbox[0], bbox[3]];
124
+ fitNew(this.map, [bbox2, bbox3]);
125
+ },
126
+ convertBBoxGCJ02(bbox) {
127
+ const pointArr = [];
128
+ const {
129
+ lat,
130
+ lon
131
+ } = GPS.gcj_encrypt(bbox[0], bbox[1]);
132
+ const {
133
+ lon: lon2,
134
+ lat: lat2
135
+ } = GPS.gcj_encrypt(bbox[2], bbox[3]);
136
+ pointArr.push(lon);
137
+ pointArr.push(lat);
138
+ pointArr.push(lon2);
139
+ pointArr.push(lat2);
140
+ return pointArr;
141
+ },
163
142
 
164
- hide() {
165
- if(!this.kml) return;
166
- this.kml.hide();
167
- },
143
+ _remove() {
144
+ if (!this.kml) return;
145
+ this.kml.removeKML();
146
+ this.bbox = [];
147
+ this.bboxGCJ02 = [];
148
+ this.url = null;
149
+ this.gcj02Url = null;
150
+ },
168
151
 
169
- },
170
- }
152
+ selectGPSAll(type) {
153
+ const url = type == 1 ? this.gcj02Url : this.url;
154
+ this.setUrl(url);
155
+ },
156
+
157
+ show() {
158
+ if (!this.kml) return;
159
+ this.kml.show();
160
+ if (this.isFit) {
161
+ setTimeout(() => {
162
+ this.setFit();
163
+ }, 50);
164
+ }
165
+ },
166
+
167
+ hide() {
168
+ if (!this.kml) return;
169
+ this.kml.hide();
170
+ },
171
+ },
172
+ }
171
173
  </script>
172
174
 
173
175
  <style>
174
- </style>
176
+ </style>
@@ -72,29 +72,24 @@
72
72
 
73
73
  },
74
74
 
75
- created() {
76
- this.lastType = this.gpsType;
77
- if(this.modelArr.length){
78
- this.init(this.modelArr);
79
- return;
80
- }
81
- if(this.inserts.length){
82
- this.init(this.inserts);
75
+ async created() {
76
+ this.lastType = this.gpsType;
77
+ if (this.modelArr.length) {
78
+ await this.init(this.modelArr);
79
+ return;
80
+ }
81
+ if (this.inserts.length) {
82
+ await this.init(this.inserts);
83
83
  }
84
84
  },
85
85
 
86
86
  methods: {
87
- init(arr) {
88
- // this._insert();
87
+ async init(arr) {
89
88
  if (!arr || !arr.length) return;
90
- arr.forEach(val => {
91
- this._insert(val);
92
- });
93
- if (this.isFit) {
94
- setTimeout(() => {
95
- this.setFit();
96
- }, 50);
89
+ for (let i = 0; i < arr.length; i++) {
90
+ await this._insert(arr[i]);
97
91
  }
92
+ this.setFit();
98
93
  },
99
94
  _inserts(arr) {
100
95
  this.lastType = this.gpsType;
@@ -107,7 +102,7 @@
107
102
  }, 50);
108
103
  }
109
104
  },
110
- _insert(dto) {
105
+ async _insert(dto) {
111
106
  const {
112
107
  id,
113
108
  url,
@@ -133,13 +128,19 @@
133
128
  },
134
129
  this.map,
135
130
  extractStyles);
131
+ await lkml.init(this.time);
132
+ if (id) {
133
+ lkml.setId(id);
134
+ }
136
135
  this.kmlMap.set(id, lkml);
137
136
  this.urls.set(id, url);
137
+
138
138
  if (gcj02Url) {
139
139
  this.gcj02Urls.set(id, gcj02Url);
140
- }
141
- }
142
- this.setBBOXArr(dto.id, bbox);
140
+ }
141
+ this.setBBOXArr(dto.id, lkml.getExtent());
142
+ }
143
+
143
144
  },
144
145
  // 刷新
145
146
  _setZoom() {
@@ -171,7 +172,7 @@
171
172
  }
172
173
  this.setFitFist(this.gpsType == 1 ? this.bboxGCJ02[0] : this.bbox[0]);
173
174
  },
174
- // bbox.length =1 执行此处
175
+
175
176
  setFitFist(bbox) {
176
177
  const bbox2 = [bbox[0], bbox[3], bbox[2], bbox[1]];
177
178
  const bbox3 = [bbox[2], bbox[1], bbox[0], bbox[3]];