hookehuyr

fix

1 <!-- 1 <!--
2 * @Date: 2023-05-19 14:54:27 2 * @Date: 2023-05-19 14:54:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-07-24 15:06:47 4 + * @LastEditTime: 2023-07-24 16:11:12
5 * @FilePath: /map-demo/src/views/inner.vue 5 * @FilePath: /map-demo/src/views/inner.vue
6 * @Description: 地图主体页面 6 * @Description: 地图主体页面
7 --> 7 -->
...@@ -252,16 +252,16 @@ export default { ...@@ -252,16 +252,16 @@ export default {
252 navList: [], 252 navList: [],
253 navKey: '', 253 navKey: '',
254 markerSum: [], // marker合集 254 markerSum: [], // marker合集
255 - titleLayerSet: { 255 + // titleLayerSet: {
256 - 17: { 256 + // 17: {
257 - x: [109439, 109441], 257 + // x: [109439, 109441],
258 - y: [53519, 53521] 258 + // y: [53519, 53521]
259 - }, 259 + // },
260 - 18: { 260 + // 18: {
261 - x: [218879, 218882], 261 + // x: [218879, 218882],
262 - y: [107039, 107042] 262 + // y: [107039, 107042]
263 - } 263 + // }
264 - }, 264 + // },
265 defaultZoom: 18, 265 defaultZoom: 18,
266 defaultCenter: [120.587382, 31.313900], 266 defaultCenter: [120.587382, 31.313900],
267 mapTiles: [], 267 mapTiles: [],
...@@ -269,7 +269,6 @@ export default { ...@@ -269,7 +269,6 @@ export default {
269 }, 269 },
270 async mounted() { 270 async mounted() {
271 const code = this.$route.query.id; 271 const code = this.$route.query.id;
272 - // const code = '362800';
273 const { data } = await mapAPI({i: code}); 272 const { data } = await mapAPI({i: code});
274 data.list = data.list.concat(map_yard); 273 data.list = data.list.concat(map_yard);
275 data.list = data.list.concat(map_members); 274 data.list = data.list.concat(map_members);
...@@ -284,14 +283,6 @@ export default { ...@@ -284,14 +283,6 @@ export default {
284 this.getLocation() 283 this.getLocation()
285 // 设置贴片地图 284 // 设置贴片地图
286 this.setTitleLayer(); 285 this.setTitleLayer();
287 - // 每隔5分钟刷新地图
288 - // setInterval(() => {
289 - // this.map.resize();
290 - // }, 1000 * 60 * 1);
291 - // setInterval(() => {
292 - // this.map.resize();
293 - // console.warn(0);
294 - // }, 1000 * 10);
295 }, 286 },
296 watch: { 287 watch: {
297 show_popup(val) { 288 show_popup(val) {
...@@ -523,18 +514,16 @@ export default { ...@@ -523,18 +514,16 @@ export default {
523 this.dialog_show = true; 514 this.dialog_show = true;
524 this.dialog_text = '您不在景区范围内'; 515 this.dialog_text = '您不在景区范围内';
525 } else { 516 } else {
517 + // this.current_lng = '120.587643'
518 + // this.current_lat = '31.314853'
526 // 使用纠正偏移后的地址,打一个定位标记 519 // 使用纠正偏移后的地址,打一个定位标记
527 - var marker = new AMap.Marker({ 520 + var marker = new AMap.LabelMarker({
528 - icon: new AMap.Icon({ 521 + icon: {
529 image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A.png', 522 image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A.png',
530 - size: new AMap.Size(40, 40), 523 + anchor: 'bottom-center',
531 - // 图标所用图片大小 524 + size: [36, 36],
532 - imageSize: new AMap.Size(40, 40), 525 + },
533 - // 图标取图偏移量
534 - imageOffset: new AMap.Pixel(0, 0)
535 - }),
536 position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] 526 position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
537 - offset: new AMap.Pixel(-20, -20)
538 }); 527 });
539 this.map.add(marker); 528 this.map.add(marker);
540 // 定位到地图中心-西园寺 529 // 定位到地图中心-西园寺
...@@ -802,6 +791,29 @@ export default { ...@@ -802,6 +791,29 @@ export default {
802 } 791 }
803 }, 792 },
804 setTitleLayer() { // 生成瓦片图 793 setTitleLayer() { // 生成瓦片图
794 + // 获取瓦片图渲染范围
795 + function getFirstProperty(obj) {
796 + for (var prop in obj) {
797 + return prop;
798 + }
799 + }
800 + function getLastProperty(obj) {
801 + var props = [];
802 + for (var prop in obj) {
803 + props.push(prop);
804 + }
805 + return props[props.length - 1];
806 + }
807 + let obj_scope = {};
808 + for (const key in this.mapTiles) {
809 + const element = this.mapTiles[key];
810 + let first = getFirstProperty(element).split('-');
811 + let last = getLastProperty(element).split('-');
812 + obj_scope[key] = {
813 + x: [first[0], last[0]],
814 + y: [first[1], last[1]]
815 + }
816 + }
805 const _this = this; 817 const _this = this;
806 var layer = new AMap.TileLayer.Flexible({ 818 var layer = new AMap.TileLayer.Flexible({
807 cacheSize: 50, 819 cacheSize: 50,
...@@ -809,9 +821,9 @@ export default { ...@@ -809,9 +821,9 @@ export default {
809 zIndex: 100, 821 zIndex: 100,
810 createTile: function (x, y, z, success, fail) { 822 createTile: function (x, y, z, success, fail) {
811 // 控制地图等级显示图片范围-过滤不显示的图层渲染 823 // 控制地图等级显示图片范围-过滤不显示的图层渲染
812 - for (const id in _this.titleLayerSet) { 824 + for (const id in obj_scope) {
813 if (z == id) { 825 if (z == id) {
814 - const scope = _this.titleLayerSet[id]; 826 + const scope = obj_scope[id];
815 if (x < scope.x[0] || x > scope.x[1]) { 827 if (x < scope.x[0] || x > scope.x[1]) {
816 fail() 828 fail()
817 return; 829 return;
......