riku
2024-02-05 7607d55d6597d772de1a37598d36e74c4542223e
lib/map.js
@@ -50,18 +50,49 @@
    this._map.remove(views);
  },
  addMarkers(markers) {
  addElasticMarkers(markers) {
    const zoomStyleMapping = {
      14: 0,
      15: 0,
      16: 0,
      17: 0,
      18: 0,
      19: 0,
      20: 0,
    };
    const mList = [];
    markers.forEach((m) => {
      var marker = new AMap.Marker({
        position: new AMap.LngLat(m.lng, m.lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
      let name = m.name;
      if (m.name.length > 9) {
        const i = m.name.length / 2;
        const str1 = m.name.slice(0, i + 1);
        const str2 = m.name.slice(i + 1, m.name.length);
        name = `${str1}<br />${str2}`;
      }
      var marker = new AMap.ElasticMarker({
        title: m.name,
        offset: new AMap.Pixel(-13, -12),
        // anchor: 'center',
        icon: new AMap.Icon({
          image: './asset/mipmap/c_level_no.png',
          // imageSize: [12, 12],
        }),
        zoom: [14, 20],
        position: new AMap.LngLat(m.lng, m.lat),
        styles: [
          {
            icon: {
              img: './asset/mipmap/scene.png',
              size: [16, 16], //可见区域的大小
              ancher: [8, 16], //锚点
              fitZoom: 14, //最合适的级别
              scaleFactor: 1.4, //地图放大一级的缩放比例系数
              maxScale: 2, //最大放大比例
              minScale: 1, //最小放大比例
            },
            label: {
              content: `<div>${name}</div>`,
              offset: [-35, 0],
              position: 'BM',
              minZoom: 15,
            },
          },
        ],
        zoomStyleMapping: zoomStyleMapping,
      });
      mList.push(marker);
    });
@@ -180,14 +211,14 @@
    // 创建样式对象
    var styleObject = {
      url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png',
      url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png',
      // url: './asset/mipmap/ic_up_white.png', // 图标地址
      size: new AMap.Size(11, 11), // 图标大小
      anchor: new AMap.Pixel(5, 5), // 图标显示位置偏移量,基准点为图标左上角
    };
    var massMarks = new AMap.MassMarks(data, {
      zIndex: 5, // 海量点图层叠加的顺序
      zooms: [3, 18], // 在指定地图缩放级别范围内展示海量点图层
      zooms: [15, 18], // 在指定地图缩放级别范围内展示海量点图层
      style: styleObject, // 设置样式对象
    });
    massMarks.on('click', (event) => {
@@ -207,11 +238,10 @@
      this.drawSector3(lnglats[i], windDir, windSpeed);
      // 2. 绘制对话框
      const window = DialogUtil.createInfoWindow(fDatas, i, () => {
      DialogUtil.openNewWindow(fDatas, i, MapUtil._map, lnglats[i], () => {
        // 移除扇形区域
        this.clearSector3();
        // this.clearSector3();
      });
      window.open(MapUtil._map, lnglats[i]);
      // 3. 趋势图跳转定位
      const progress = FChart.locate(
@@ -289,10 +319,11 @@
  _sector: undefined,
  _sectorViews3: {},
  drawSector3: function (lnglat, windDir, windSpeed) {
    // this._map.remove(MapUtil._sectorViews)
    // MapUtil._sectorViews = []
    if (windSpeed > 10) {
      return;
    }
    if (MapUtil._sectorViews3['text10'] != undefined) {
      this.clearSector3();
    }
    var sector = new AMap.Object3D.Mesh();
@@ -364,89 +395,129 @@
      geometry.faces.push(index + 3, index + 4, index + 5);
      geometry.faces.push(index + 4, index + 5, index + 6);
    }
    if (this._sector != undefined) {
      this._object3Dlayer.remove(this._sector);
    }
    this._object3Dlayer.add(sector);
    this._sector = sector;
    distance = distance.toFixed(0);
    distance2 = distance2.toFixed(0);
    const zoomStyleMapping = {
      14: 0,
      15: 0,
      16: 0,
      17: 0,
      18: 0,
      19: 0,
      20: 0,
    };
    //10分钟扇形
    if (MapUtil._sectorViews3['text10'] == undefined) {
      var text15 = new AMap.Text({
        text: '10分钟',
    var text15 = new AMap.ElasticMarker({
      zoom: [14, 20],
        position: list[2],
        // animation: "AMAP_ANIMATION_DROP"
      styles: [
        {
          icon: {
            img: './asset/mipmap/location.png',
            size: [16, 16], //可见区域的大小
            ancher: [8, 16], //锚点
            fitZoom: 18, //最合适的级别
            scaleFactor: 1, //地图放大一级的缩放比例系数
            maxScale: 2, //最大放大比例
            minScale: 1, //最小放大比例
          },
          label: {
            content: '<div>10分钟</div>',
            offset: [-35, 0],
            position: 'BM',
            minZoom: 15,
          },
        },
      ],
      zoomStyleMapping: zoomStyleMapping,
      });
      MapUtil._sectorViews3['text10'] = text15;
      var textM = new AMap.Text({
        text: distance + 'm',
    var textM = new AMap.ElasticMarker({
      zoom: [14, 20],
        position: list[1],
        // animation: "AMAP_ANIMATION_DROP"
      styles: [
        {
          icon: {
            img: './asset/mipmap/location.png',
            size: [16, 16], //可见区域的大小
            ancher: [8, 16], //锚点
            fitZoom: 18, //最合适的级别
            scaleFactor: 1, //地图放大一级的缩放比例系数
            maxScale: 2, //最大放大比例
            minScale: 1, //最小放大比例
          },
          label: {
            content: `<div>${distance}m</div>`,
            offset: [-35, 0],
            position: 'BM',
            minZoom: 15,
          },
        },
      ],
      zoomStyleMapping: zoomStyleMapping,
      });
      MapUtil._sectorViews3['textM'] = textM;
    } else {
      MapUtil._sectorViews3['text10'].setPosition(list[2]);
      MapUtil._sectorViews3['textM'].setPosition(list[1]);
      MapUtil._sectorViews3['textM'].setText(distance + 'm');
    }
    MapUtil._map.add(MapUtil._sectorViews3['text10']);
    MapUtil._map.add(MapUtil._sectorViews3['textM']);
    // 缩放地图到合适的视野级别
    // if (animation != false) {
    //     MapUtil._map.setFitView([bezierCurve, line1, line2])
    // }
    //5分钟扇形
    pList = list2;
    // MapUtil._map.setCenter(pList[0])
    path = [
      [pList[0].lng, pList[0].lat],
      [pList[1].lng, pList[1].lat, pList[2].lng, pList[2].lat],
    ];
    if (MapUtil._sectorViews3['textM5'] == undefined) {
      var bezierCurve = new AMap.BezierCurve({
        path: path,
        // isOutline: true,
        // outlineColor: '#ffeeff',
        borderWeight: 1,
        strokeColor: '#ffeeff',
        strokeOpacity: 1,
        // strokeWeight: 6,
        // 线样式还支持 'dashed'
        strokeStyle: 'solid',
        // strokeStyle是dashed时有效
        strokeDasharray: [10, 10],
        lineJoin: 'round',
        lineCap: 'round',
        zIndex: 50,
      });
      // bezierCurve.setMap(MapUtil._map)
      // MapUtil._sectorViews3['bezierCurve'] = bezierCurve
      var text5 = new AMap.Text({
        text: '5分钟',
    var text5 = new AMap.ElasticMarker({
        position: pList[1],
        // animation: "AMAP_ANIMATION_DROP"
      styles: [
        {
          icon: {
            img: './asset/mipmap/location.png',
            size: [16, 16], //可见区域的大小
            ancher: [8, 16], //锚点
            fitZoom: 18, //最合适的级别
            scaleFactor: 1, //地图放大一级的缩放比例系数
            maxScale: 2, //最大放大比例
            minScale: 1, //最小放大比例
          },
          label: {
            content: `<div>5分钟</div>`,
            offset: [-35, 0],
            position: 'BM',
            minZoom: 15,
          },
        },
      ],
      zoomStyleMapping: zoomStyleMapping,
      });
      MapUtil._sectorViews3['text5'] = text5;
      var textM5 = new AMap.Text({
        text: distance2 + 'm',
    var textM5 = new AMap.ElasticMarker({
        position: pList[0],
        // animation: "AMAP_ANIMATION_DROP"
      styles: [
        {
          icon: {
            img: './asset/mipmap/location.png',
            size: [16, 16], //可见区域的大小
            ancher: [8, 16], //锚点
            fitZoom: 18, //最合适的级别
            scaleFactor: 1, //地图放大一级的缩放比例系数
            maxScale: 2, //最大放大比例
            minScale: 1, //最小放大比例
          },
          label: {
            content: `<div>${distance2}m</div>`,
            offset: [-35, 0],
            position: 'BM',
            minZoom: 15,
          },
        },
      ],
      zoomStyleMapping: zoomStyleMapping,
      });
      MapUtil._sectorViews3['textM5'] = textM5;
    } else {
      // MapUtil._sectorViews3['bezierCurve'].setPath(path)
      MapUtil._sectorViews3['text5'].setPosition(pList[1]);
      MapUtil._sectorViews3['textM5'].setPosition(pList[0]);
      MapUtil._sectorViews3['textM5'].setText(distance2 + 'm');
    }
    MapUtil._map.add(MapUtil._sectorViews3['textM5']);
    MapUtil._map.add(MapUtil._sectorViews3['text5']);