忧伤的王尓德 2022-08-11 09:22 采纳率: 33.3%
浏览 116
已结题

高德地图灵活的点ElasticMarker在react的使用

有个需求是要标注点随地图缩放等级变化大小,所以就想着使用高德地图API里的ElasticMarker,但是结果无法在地图上显示
使用Marker就可以正常显示。
求各位帮我看看问题出在哪了
代码如下:

import { Component } from 'react';
import './MapPage.css';
import AMapLoader from '@amap/amap-jsapi-loader';

class MapPage extends Component {
  constructor(props: any) {
    super(props);
    this.state = {
      map: {},
    };
    this.map = {};
  }

  componentDidMount() {
    AMapLoader.load({
      key: 'c9ea62b51d53c7f76a8ecaca52dfb814',
      version: '2.0',
      plugins: ['AMap.ToolBar', 'AMap.Driving', 'AMap.MapType', 'AMap.ElasticMarker'],
      AMapUI: {
        version: '1.1',
        plugins: [],
      },
      Loca: {
        version: '2.0.0',
      },
    })
      .then((AMap) => {
        this.map = new AMap.Map('container', {
          viewMode: '3D',
          zoom: 5,
          zooms: [2, 22],
          center: [105.602725, 37.076636],
        });
        this.map.addControl(new AMap.MapType({ defaultType: 0 }));
        let facilities = [];
        let positionArr = [
          [113.357224, 34.977186],
          [114.555528, 37.727903],
          [112.106257, 36.962733],
          [109.830097, 31.859027],
          [116.449181, 39.98614],
        ];
        for (let item of positionArr) {
          let marker = new AMap.ElasticMarker({
            // map: this.map,
            position: [item[0], item[1]],
            zooms: [2, 22],
            styles: [
              {
                icon: {
                  img: '../../assets/img/point1-0.jpg',
                  size: [60, 60],
                  ancher: 'bottom-center',
                  fitZoom: 14,
                  scaleFactor: 2,
                  maxScale: 1.4,
                  minScale: 0.8,
                },
              },
            ],
          });
          facilities.push(marker);
          // console.log(facilities);
          this.map.add(facilities);
        }
      })
      .catch((e) => {
        console.log(e);
      });
  }
  render() {
    return <div id="container" style={{ width: '1278px', height: '580px', margin: '-24px' }} />;
  }
}
export default MapPage;

  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2022-08-11 09:34
    关注

    你map 怎么给注释了 。这个是显示的地图对象没有这个 应该显示不了吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月19日
  • 已采纳回答 8月11日
  • 创建了问题 8月11日

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数