Select to view content in your preferred language

When scrolling to zoom in and out of the map, the aggregation point will occasionally be left unrendered on one layer

334
0
10-19-2022 12:56 AM
Binf
by
New Contributor

Hi.

When scrolling to zoom in and out of the map, the aggregation point will occasionally be left unrendered on one layer. And the console reported no error. How can I solve this problem?

Use version: 4.17

code:

clusterPoint(points, layerName, icon, font, other) {
    const pointsArray = points && points.length > 0 ? JSON.parse(JSON.stringify(points)) : [];
    const id = Utils.uuid();
    layerName = layerName || id;
    let layer = this.getLayer(layerName);
    const zIndex = other && other.zIndex ? other.zIndex : 0;
    layer = !layer ? this.createGraphicsLayer(layerName, 'clusterPoint', zIndex) : layer;
    const defaultIcon = {
      url: SITE_CONFIG.host + '/libs/mapLib/icons/t1.png',
      clusterUrl: SITE_CONFIG.host + '/libs/mapLib/icons/markpoint_bg3.png',
      width: 20,
      height: 20,
    };
    icon = icon ? Object.assign(defaultIcon, icon) : defaultIcon;

    const defaultFont = {
      fontSize: '16px',
      color: '#fff',
      offset: [0, 0],
    };
    font = font ? Object.assign(defaultFont, font) : defaultFont;

    let simpleStyle = {
      bgColor: [255, 127, 80, 1], // 背景色
      borderColor: [255, 127, 80, 1], // 边框颜色
    }
    if (other && other.simpleStyle) simpleStyle = Object.assign(simpleStyle, other.simpleStyle)

    const textSymbol = {
      type: "text",
      color: font.color,
      font: {
        size: font.fontSize,
      },
      xoffset: 0,
      yoffset: 0,
    }
    const featureOptionsLabelingInfo = {
      labelsVisible: true,
      labelingInfo: [
        {
          symbol: textSymbol,
          labelPlacement: "center-center",
          deconflictionStrategy: 'none',
          labelExpressionInfo: {
            expression: `return $feature.text`
          },
        }
      ]
    }
 
    let labelingInfo = [
      {
        symbol: textSymbol,
        labelPlacement: "center-center",
        deconflictionStrategy: 'none',
        labelExpressionInfo: {
          expression: `
                    var label = Round($feature.cluster_avg_text * $feature.cluster_count); 
                    return label
                  `
        },
      },
    ];
    const clusterConfig = {
      type: "cluster",
      clusterRadius: 100,
      labelsVisible: true,
      popupEnabled: false,
      labelingInfo: labelingInfo,
      clusterMaxSize: '60px',
      clusterMinSize: '24px',
    };

    let renderer = {
      type: "class-breaks",
      field: 'cluster_count',
      valueExpression: `$feature.cluster_count`,
      visualVariables: [
        {
          type: "size",
          field: 'cluster_count',
          valueExpression: `$feature.cluster_count`,
          minDataValue: 1,
          maxDataValue: pointsArray.length,
          minSize: 36,
          maxSize: 60,
        }
      ],
      defaultSymbol: {
        type: 'picture-marker',
        url: icon.clusterUrl,
        width: icon.width,
        height: icon.height,
      },
      classBreakInfos: [
        // 合并数量$feature.cluster_count是1的时候展示的样式
        {
          minValue: 1,
          maxValue: 1,
          symbol: {
            type: 'picture-marker',
            url: icon.url,
            width: icon.width,
            height: icon.height,
            // xoffset: 0,
            // yoffset: 10,
          },
        },
      ],
    };


    let graphicPoints = [], fieldArr = [], textTotal = 0;
    for (let i = 0, len = pointsArray.length; i < len; i++) {
      let point = pointsArray[i]
      point.layerName = layerName;
      point.layer = layerName;
      point.pointId = point.pointId ? point.pointId : Utils.uuid();
      point.ObjectID = i;
      textTotal += point.text ? Number(point.text) : 0;

      if (i == 0) {
        fieldArr = Utils._getFields(point);
      }
      const geometry = new this.mapModules.Point({
        longitude: Number(point.lon),
        latitude: Number(point.lat),
        spatialReference: { wkid: dataWkid }
      })

      let graphic = new this.mapModules.Graphic({
        geometry: geometry,
        attributes: point,
        type: 'clusterPoint',
      })
      graphicPoints.push(graphic)
    }
    
    renderer.visualVariables[0].maxDataValue = textTotal;

    const featureOptions = {
      id: layerName,
      geometryType: "point",
      spatialReference: { wkid: dataWkid },
      source: graphicPoints,
      featureReduction: clusterConfig,
      objectIdField: 'ObjectID',
      typeIdField: 'text',
      popupEnabled: false,
      renderer: renderer,
      fields: fieldArr,
      outFields: ["*"]
    };

    featureOptions.labelsVisible = featureOptionsLabelingInfo.labelsVisible;
    featureOptions.labelingInfo = featureOptionsLabelingInfo.labelingInfo;

    let featureLayer = new this.mapModules.FeatureLayer(featureOptions);
    this.map.map.add(featureLayer)
    layer.add(graphicPoints)
  }

 

The effect

CESHI.gif

 

0 Kudos
0 Replies