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-06-30 17:33:58 4 + * @LastEditTime: 2023-07-04 14:50:06
5 * @FilePath: /map-demo/src/views/index.vue 5 * @FilePath: /map-demo/src/views/index.vue
6 * @Description: 地图主体页面 6 * @Description: 地图主体页面
7 --> 7 -->
...@@ -214,6 +214,18 @@ export default { ...@@ -214,6 +214,18 @@ export default {
214 navList: [], 214 navList: [],
215 navKey: '', 215 navKey: '',
216 markerSum: [], // marker合集 216 markerSum: [], // marker合集
217 + titleLayerSet: {
218 + 17: {
219 + x: [109439, 109441],
220 + y: [53519, 53521]
221 + },
222 + 18: {
223 + x: [218879, 218882],
224 + y: [107039, 107042]
225 + }
226 + },
227 + defaultZoom: 18,
228 + defaultCenter: [120.587382, 31.313900]
217 } 229 }
218 }, 230 },
219 mounted() { 231 mounted() {
...@@ -297,9 +309,8 @@ export default { ...@@ -297,9 +309,8 @@ export default {
297 this.closeInfoWindow(); 309 this.closeInfoWindow();
298 setTimeout(() => { 310 setTimeout(() => {
299 // 地图zooms调整 311 // 地图zooms调整
300 - this.map.setZoom(18); 312 + this.map.setZoom(this.defaultZoom);
301 - // this.map.setZoomAndCenter(18, [this.xys_lng, this.xys_lat]); 313 + this.map.setZoomAndCenter(this.defaultZoom, this.defaultCenter);
302 - this.map.setZoomAndCenter(18, [120.587382, 31.313900]);
303 }, 100); 314 }, 100);
304 this.removeNavRoute() 315 this.removeNavRoute()
305 }, 316 },
...@@ -354,42 +365,42 @@ export default { ...@@ -354,42 +365,42 @@ export default {
354 removeLayer () { 365 removeLayer () {
355 this.map.remove(this.markerSum); 366 this.map.remove(this.markerSum);
356 }, 367 },
357 - setMapBoundary() { // 地图描边 368 + // setMapBoundary() { // 地图描边
358 - new AMap.Polygon({ 369 + // new AMap.Polygon({
359 - cursor: 'pointer', 370 + // cursor: 'pointer',
360 - bubble: true, 371 + // bubble: true,
361 - path: [[120.587704, 31.312785], [120.587669, 31.313028], [120.587554, 31.313086], [120.586883, 31.313019], [120.586826, 31.314066], [120.586736, 31.314426], [120.585872, 31.314466], [120.585675, 31.315276], [120.585817, 31.315397], [120.586251, 31.31542], [120.586229, 31.31618], [120.588248, 31.316367], [120.588533, 31.314761], [120.588479, 31.31474], [120.588482, 31.314172], [120.588251, 31.314145], [120.588337, 31.313184], [120.588337, 31.313184], [120.588154, 31.313163], [120.588152, 31.312835]], 372 + // path: [[120.587704, 31.312785], [120.587669, 31.313028], [120.587554, 31.313086], [120.586883, 31.313019], [120.586826, 31.314066], [120.586736, 31.314426], [120.585872, 31.314466], [120.585675, 31.315276], [120.585817, 31.315397], [120.586251, 31.31542], [120.586229, 31.31618], [120.588248, 31.316367], [120.588533, 31.314761], [120.588479, 31.31474], [120.588482, 31.314172], [120.588251, 31.314145], [120.588337, 31.313184], [120.588337, 31.313184], [120.588154, 31.313163], [120.588152, 31.312835]],
362 - map: this.map, 373 + // map: this.map,
363 - fillOpacity: 0.5, 374 + // fillOpacity: 0.5,
364 - strokeWeight: 1, 375 + // strokeWeight: 1,
365 - fillColor: '#CFE7AA' 376 + // fillColor: '#CFE7AA'
366 - }); 377 + // });
367 - }, 378 + // },
368 - isPointInRing() { // 是否在景区范围 379 + // isPointInRing() { // 是否在景区范围
369 - let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [ 380 + // let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [
370 - [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005] 381 + // [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005]
371 - ]); 382 + // ]);
372 - return isPointInRing 383 + // return isPointInRing
373 - }, 384 + // },
374 - setLocation() { // 开启定位服务 385 + // setLocation() { // 开启定位服务
375 - // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置 386 + // // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置
376 - if (!this.current_lng || !this.current_lat) { 387 + // if (!this.current_lng || !this.current_lat) {
377 - this.getLocation() 388 + // this.getLocation()
378 - } else { 389 + // } else {
379 - // 使用纠正偏移后的地址,打一个定位标记 390 + // // 使用纠正偏移后的地址,打一个定位标记
380 - var marker = new AMap.Marker({ 391 + // var marker = new AMap.Marker({
381 - position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] 392 + // position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
382 - }); 393 + // });
383 - this.map.add(marker); 394 + // this.map.add(marker);
384 - // 定位到地图中心-西园寺 395 + // // 定位到地图中心-西园寺
385 - this.map.setCenter([120.587334, 31.314823]); 396 + // this.map.setCenter([120.587334, 31.314823]);
386 - // 判断是否在范围内 397 + // // 判断是否在范围内
387 - if (!this.isPointInRing()) { 398 + // if (!this.isPointInRing()) {
388 - this.dialog_show = true; 399 + // this.dialog_show = true;
389 - this.dialog_text = '您不在景区范围内'; 400 + // this.dialog_text = '您不在景区范围内';
390 - } 401 + // }
391 - } 402 + // }
392 - }, 403 + // },
393 getLocation() { // 获取经纬度 404 getLocation() { // 获取经纬度
394 AMap.plugin(['AMap.Geolocation'], () => { 405 AMap.plugin(['AMap.Geolocation'], () => {
395 this.geolocation = new AMap.Geolocation(this.location_options); 406 this.geolocation = new AMap.Geolocation(this.location_options);
...@@ -418,10 +429,10 @@ export default { ...@@ -418,10 +429,10 @@ export default {
418 addSafeRoute() { // 新增路径 429 addSafeRoute() { // 新增路径
419 // 行动路线 430 // 行动路线
420 var path = [ 431 var path = [
421 - [120.587512, 31.313796], 432 + [120.586841, 31.314543],
422 - [120.587495, 31.314204],
423 [120.586862, 31.314304], 433 [120.586862, 31.314304],
424 - [120.586841, 31.314543] 434 + [120.587495, 31.314204],
435 + [120.587512, 31.313796],
425 ]; 436 ];
426 // 生成折线地图路径 437 // 生成折线地图路径
427 this.current_route = new AMap.Polyline({ 438 this.current_route = new AMap.Polyline({
...@@ -458,7 +469,7 @@ export default { ...@@ -458,7 +469,7 @@ export default {
458 marker1.setLabel({ 469 marker1.setLabel({
459 direction: 'right', 470 direction: 'right',
460 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 471 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
461 - content: "<div class='info'>点</div>", //设置文本标注内容 472 + content: "<div class='info'>点</div>", //设置文本标注内容
462 }); 473 });
463 var marker2 = new AMap.Marker({ 474 var marker2 = new AMap.Marker({
464 icon: new AMap.Icon({ 475 icon: new AMap.Icon({
...@@ -476,7 +487,7 @@ export default { ...@@ -476,7 +487,7 @@ export default {
476 marker2.setLabel({ 487 marker2.setLabel({
477 direction: 'right', 488 direction: 'right',
478 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 489 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
479 - content: "<div class='info'>点</div>", //设置文本标注内容 490 + content: "<div class='info'>点</div>", //设置文本标注内容
480 }); 491 });
481 // 新增逃生路线标记 492 // 新增逃生路线标记
482 this.route_marker = [marker1, marker2] 493 this.route_marker = [marker1, marker2]
...@@ -554,30 +565,28 @@ export default { ...@@ -554,30 +565,28 @@ export default {
554 // 关闭导航提示 565 // 关闭导航提示
555 this.show_walk_route = true; 566 this.show_walk_route = true;
556 }, 567 },
568 + computedMapSource(x, y, z) { // 根据图层信息生成图层实际地址
569 + return `images/tiles/${z}/${x}_${y}.png`
570 + },
557 setTitleLayer() { // 生成瓦片图 571 setTitleLayer() { // 生成瓦片图
572 + const _this = this;
558 var layer = new AMap.TileLayer.Flexible({ 573 var layer = new AMap.TileLayer.Flexible({
559 cacheSize: 50, 574 cacheSize: 50,
560 opacity: 1, 575 opacity: 1,
561 zIndex: 100, 576 zIndex: 100,
562 createTile: function (x, y, z, success, fail) { 577 createTile: function (x, y, z, success, fail) {
563 - if (z === 17) { 578 + // 控制地图等级显示图片范围-过滤不显示的图层渲染
564 - if (x < 109439 || x > 109441) { 579 + for (const key in _this.titleLayerSet) {
565 - fail() 580 + if (z == key) {
566 - return; 581 + const scope = _this.titleLayerSet[key];
567 - } 582 + if (x < scope.x[0] || x > scope.x[1]) {
568 - if (y < 53519 || y > 53521) {
569 - fail()
570 - return;
571 - }
572 - }
573 - if (z === 18) {
574 - if (x < 218879 || x > 218882) {
575 fail() 583 fail()
576 - return; 584 + return;
577 - } 585 + }
578 - if (y < 107039 || y > 107042) { 586 + if (y < scope.y[0] || y > scope.y[1]) {
579 - fail() 587 + fail()
580 - return; 588 + return;
589 + }
581 } 590 }
582 } 591 }
583 592
...@@ -590,26 +599,9 @@ export default { ...@@ -590,26 +599,9 @@ export default {
590 fail() 599 fail()
591 }; 600 };
592 601
593 - img.src = `images/tiles/${z}/${x}_${y}.png` 602 + // img.src = `images/tiles/${z}/${x}_${y}.png`;
603 + img.src = _this.computedMapSource(x, y, z);
594 }, 604 },
595 - // createTile: function (x, y, z, success, fail) {
596 - // console.warn(z);
597 - // if ((x + y) % 3) {
598 - // fail();
599 - // return;
600 - // }
601 -
602 - // var img = document.createElement('img');
603 - // img.onload = function () {
604 - // success(img)
605 - // };
606 - // img.crossOrigin = "anonymous";// 必须添加,同时图片要有跨域头
607 - // img.onerror = function () {
608 - // fail()
609 - // };
610 -
611 - // img.src = 'https://a.amap.com/jsapi_demos/static/images/amap.png';
612 - // }
613 }); 605 });
614 606
615 this.map.addLayer(layer); 607 this.map.addLayer(layer);
...@@ -642,15 +634,15 @@ export default { ...@@ -642,15 +634,15 @@ export default {
642 634
643 }, 635 },
644 // 限制地图范围 636 // 限制地图范围
645 - lockMapBounds() { 637 + // lockMapBounds() {
646 - // var bounds = this.map.getBounds(); 638 + // // var bounds = this.map.getBounds();
647 - var myBounds = new AMap.Bounds( 639 + // var myBounds = new AMap.Bounds(
648 - [120.583246, 31.31645], 640 + // [120.583246, 31.31645],
649 - [120.589973, 31.311949] 641 + // [120.589973, 31.311949]
650 - ); 642 + // );
651 643
652 - this.map.setLimitBounds(myBounds); 644 + // this.map.setLimitBounds(myBounds);
653 - }, 645 + // },
654 showInfoClick(e) { 646 showInfoClick(e) {
655 // console.log(e); 647 // console.log(e);
656 var zoom = this.map.getZoom(); //获取当前地图级别 648 var zoom = this.map.getZoom(); //获取当前地图级别
...@@ -667,30 +659,30 @@ export default { ...@@ -667,30 +659,30 @@ export default {
667 // 关闭弹出底部导航弹框 659 // 关闭弹出底部导航弹框
668 this.show_nav_popup = false; 660 this.show_nav_popup = false;
669 }, 661 },
670 - setWalkRoute(start = { lng: 120.587799, lat: 31.313276 }, end = { lng: 120.587912, lat: 31.315169 }) { 662 + // setWalkRoute(start = { lng: 120.587799, lat: 31.313276 }, end = { lng: 120.587912, lat: 31.315169 }) {
671 - //步行导航 663 + // //步行导航
672 - let walking_CallBack = (result) => { 664 + // let walking_CallBack = (result) => {
673 - if (result.type === 'complete') { 665 + // if (result.type === 'complete') {
674 - console.warn(result); 666 + // console.warn(result);
675 - console.warn('绘制步行路线完成'); 667 + // console.warn('绘制步行路线完成');
676 - } else { 668 + // } else {
677 - console.error('步行路线数据查询失败' + result); 669 + // console.error('步行路线数据查询失败' + result);
678 - } 670 + // }
679 - } 671 + // }
680 - AMap.plugin(["AMap.Walking"], () => { //加载步行导航插件 672 + // AMap.plugin(["AMap.Walking"], () => { //加载步行导航插件
681 - this.walk_route = new AMap.Walking({ 673 + // this.walk_route = new AMap.Walking({
682 - map: this.map, 674 + // map: this.map,
683 - }); //构造步行导航类 675 + // }); //构造步行导航类
684 - AMap.Event.addListener(this.walk_route, "complete", walking_CallBack); //返回导航查询结果 676 + // AMap.Event.addListener(this.walk_route, "complete", walking_CallBack); //返回导航查询结果
685 - //根据起、终点坐标规划步行路线 677 + // //根据起、终点坐标规划步行路线
686 - this.walk_route.search(new AMap.LngLat(start.lng, start.lat), new AMap.LngLat(end.lng, end.lat)); 678 + // this.walk_route.search(new AMap.LngLat(start.lng, start.lat), new AMap.LngLat(end.lng, end.lat));
687 - }); 679 + // });
688 - this.show_walk_route = false; 680 + // this.show_walk_route = false;
689 - }, 681 + // },
690 - removeWalkRoute() { 682 + // removeWalkRoute() {
691 - this.walk_route.clear(); 683 + // this.walk_route.clear();
692 - this.show_walk_route = true; 684 + // this.show_walk_route = true;
693 - }, 685 + // },
694 infoWindowLocation(path) { // 监听前往按钮回调 686 infoWindowLocation(path) { // 监听前往按钮回调
695 // TODO: 实际获取精确定位后导航到位置 687 // TODO: 实际获取精确定位后导航到位置
696 // // 判断是否在范围内 688 // // 判断是否在范围内
......