Showing
1 changed file
with
77 additions
and
48 deletions
| 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: 2024-09-02 15:32:36 | 4 | + * @LastEditTime: 2024-09-10 17:37:37 |
| 5 | * @FilePath: /map-demo/src/views/index.vue | 5 | * @FilePath: /map-demo/src/views/index.vue |
| 6 | * @Description: 公众地图主体页面 | 6 | * @Description: 公众地图主体页面 |
| 7 | --> | 7 | --> |
| ... | @@ -423,57 +423,86 @@ export default { | ... | @@ -423,57 +423,86 @@ export default { |
| 423 | // }) | 423 | // }) |
| 424 | // // marker合集 | 424 | // // marker合集 |
| 425 | // this.markerSum.push(marker); | 425 | // this.markerSum.push(marker); |
| 426 | - // 创建一个 LabelMarker 实例 | 426 | + // 创建一个 文字 实例 - 适配竖型文字 |
| 427 | - var labelMarker = new AMap.LabelMarker({ | 427 | + // let writing_mode = 'vertical'; // 文字方向 |
| 428 | - position: entity_info[i].position, | 428 | + if (entity_info[i]?.writing_mode === 'vertical') { // 标题文字垂直 |
| 429 | - opacity: 1, | 429 | + var textMarker = new AMap.Text({ |
| 430 | - zIndex: 2, | 430 | + text: entity_info[i].name, //标记显示的文本内容 |
| 431 | - opacity: 0.9, | 431 | + anchor: "center", //设置文本标记锚点位置 |
| 432 | - // rank: 10, | 432 | + // draggable: true, //是否可拖拽 |
| 433 | - icon: { | 433 | + // cursor: "pointer", //指定鼠标悬停时的鼠标样式。 |
| 434 | - image: marker_icon, | 434 | + // angle: 10, //点标记的旋转角度 |
| 435 | - anchor: 'bottom-center', | ||
| 436 | - size: [36, 36], | ||
| 437 | - }, | ||
| 438 | - text: { | ||
| 439 | - zooms: [18, 20], | ||
| 440 | - content: entity_info[i].name, | ||
| 441 | - direction: 'top', | ||
| 442 | - offset: [0, 5], | ||
| 443 | style: { | 435 | style: { |
| 444 | - padding: [10, 10], | 436 | + //设置文本样式,Object 同 css 样式表 |
| 445 | - fontSize: 14, | 437 | + // "padding": ".75rem 1.25rem", |
| 446 | - fillColor: '#fff', | 438 | + // "margin-bottom": "1rem", |
| 447 | - strokeWidth: 0, | 439 | + // "border-radius": ".25rem", |
| 448 | - backgroundColor: '#965f13', | 440 | + "background-color": "#965f13", |
| 449 | - borderWidth: 0, | 441 | + "width": "1rem", |
| 442 | + "border-width": 0, | ||
| 443 | + // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)", | ||
| 444 | + "text-align": "center", | ||
| 445 | + "font-size": "0.8rem", | ||
| 446 | + "color": "white", | ||
| 447 | + "writing-mode": "vertical-rl", | ||
| 448 | + "text-orientation": "mixed", | ||
| 449 | + }, | ||
| 450 | + position: entity_info[i].position, //点标记在地图上显示的位置 | ||
| 451 | + }); | ||
| 452 | + textMarker.setMap(this.map); //将文本标记设置到地图上 | ||
| 453 | + } else { // 默认方向 | ||
| 454 | + // 创建一个 LabelMarker 实例 | ||
| 455 | + var labelMarker = new AMap.LabelMarker({ | ||
| 456 | + position: entity_info[i].position, | ||
| 457 | + opacity: 1, | ||
| 458 | + zIndex: 2, | ||
| 459 | + opacity: 0.9, | ||
| 460 | + // rank: 10, | ||
| 461 | + icon: { | ||
| 462 | + image: marker_icon, | ||
| 463 | + anchor: 'bottom-center', | ||
| 464 | + size: [36, 36], | ||
| 465 | + }, | ||
| 466 | + text: { | ||
| 467 | + zooms: [18, 20], | ||
| 468 | + content: entity_info[i].name, | ||
| 469 | + direction: 'top', | ||
| 470 | + offset: [0, 5], | ||
| 471 | + style: { | ||
| 472 | + padding: [10, 10], | ||
| 473 | + fontSize: 14, | ||
| 474 | + fillColor: '#fff', | ||
| 475 | + strokeWidth: 0, | ||
| 476 | + backgroundColor: '#965f13', | ||
| 477 | + borderWidth: 0, | ||
| 478 | + } | ||
| 450 | } | 479 | } |
| 480 | + }); | ||
| 481 | + if (clickListener) { | ||
| 482 | + labelMarker.off('click', clickListener) | ||
| 451 | } | 483 | } |
| 452 | - }); | 484 | + // 绑定景点的点击事件 - 文字出现才能触发 |
| 453 | - if (clickListener) { | 485 | + var clickListener = labelMarker.on('click', (e) => { |
| 454 | - labelMarker.off('click', clickListener) | 486 | + // 不同弹框类型 |
| 487 | + if (entity_info[i].window_type === 'normal') { | ||
| 488 | + this.positionMarker(entity_info[i]) | ||
| 489 | + } else if (entity_info[i].window_type === 'lite') { | ||
| 490 | + this.positionLiteMarker(entity_info[i]) | ||
| 491 | + } else if (entity_info[i].window_type === 'warn') { | ||
| 492 | + this.positionWarnMarker(entity_info[i]) | ||
| 493 | + } | ||
| 494 | + }) | ||
| 495 | + // 使用LabelsLayer包裹缩放地图时,图标不会自动显示和消失需要配置rank排序 | ||
| 496 | + // 创建一个 LabelsLayer 实例来承载 LabelMarker,[LabelsLayer 文档](https://lbs.amap.com/api/jsapi-v2/documentation#labelslayer) | ||
| 497 | + var labelsLayer = new AMap.LabelsLayer({ | ||
| 498 | + collision: true, | ||
| 499 | + }); | ||
| 500 | + // // 将 LabelMarker 实例添加到 LabelsLayer 上 | ||
| 501 | + labelsLayer.add(labelMarker); | ||
| 502 | + // 将 LabelsLayer 添加到地图上 | ||
| 503 | + // this.map.add(labelsLayer); | ||
| 504 | + this.markerSum.push(labelsLayer); | ||
| 455 | } | 505 | } |
| 456 | - // 绑定景点的点击事件 - 文字出现才能触发 | ||
| 457 | - var clickListener = labelMarker.on('click', (e) => { | ||
| 458 | - // 不同弹框类型 | ||
| 459 | - if (entity_info[i].window_type === 'normal') { | ||
| 460 | - this.positionMarker(entity_info[i]) | ||
| 461 | - } else if (entity_info[i].window_type === 'lite') { | ||
| 462 | - this.positionLiteMarker(entity_info[i]) | ||
| 463 | - } else if (entity_info[i].window_type === 'warn') { | ||
| 464 | - this.positionWarnMarker(entity_info[i]) | ||
| 465 | - } | ||
| 466 | - }) | ||
| 467 | - // 使用LabelsLayer包裹缩放地图时,图标不会自动显示和消失需要配置rank排序 | ||
| 468 | - // 创建一个 LabelsLayer 实例来承载 LabelMarker,[LabelsLayer 文档](https://lbs.amap.com/api/jsapi-v2/documentation#labelslayer) | ||
| 469 | - var labelsLayer = new AMap.LabelsLayer({ | ||
| 470 | - collision: true, | ||
| 471 | - }); | ||
| 472 | - // // 将 LabelMarker 实例添加到 LabelsLayer 上 | ||
| 473 | - labelsLayer.add(labelMarker); | ||
| 474 | - // 将 LabelsLayer 添加到地图上 | ||
| 475 | - // this.map.add(labelsLayer); | ||
| 476 | - this.markerSum.push(labelsLayer); | ||
| 477 | }) | 506 | }) |
| 478 | this.map.add(this.markerSum); | 507 | this.map.add(this.markerSum); |
| 479 | }, | 508 | }, | ... | ... |
-
Please register or login to post a comment