init()

in src/Wmap/index.tsx [390:485]


  init(chart: Chart, config: WmapConfig) {
    // 同步度量
    chart.scale({
      longitude: {
        sync: true,
      },
      latitude: {
        sync: true,
      },
      x: {
        nice: false,
        sync: true,
      },
      y: {
        nice: false,
        sync: true,
      },
    });

    // 设置了 geo.projection 变换后,几何体的坐标系和图表的坐标系(从左下角到右上角)上下相反,所以设置镜像使地图的坐标正确。
    chart.coordinate().reflect('y');

    chart.axis(false);

    rectTooltip(
      this,
      chart,
      config,
      {
        showTitle: false,
      },
      (ev: any) => {
        if (typeof config.tooltip === 'boolean') {
          return;
        }
        const { nameFormatter, valueFormatter } = config.tooltip;
        const { items } = ev.data;
        items.forEach((item: any, index: number) => {
          const raw = item.data || {};

          if (valueFormatter) {
            item.value = valueFormatter(item.value, raw, index, items);
          }
          if (nameFormatter) {
            item.name = nameFormatter(item.name, raw, index, items);
          }
        });
      },
      {
        showTitle: false,
        showCrosshairs: false,
        // crosshairs: null,
        showMarkers: false,
      },
    );

    // 设置图例
    rectLegend(this, chart, config, {}, 'multiple');

    const ds = new DataSet();
    this.ds = ds;

    drawMapBackground(this, chart, ds, config);

    React.Children.forEach(this.props.children, (child: MapChild, index) => {
      if (!child) {
        return;
      }
      // @ts-ignore
      const { props, type, key } = child;
      if (!props || !type) {
        return;
      }
      const layerConfig = Object.assign({}, filterKey(config, ['padding']), props.config);
      // G2 图层需要转化数据格式
      let { data } = props;
      if (layerConfig.dataType !== 'g2') {
        data = convertMapData(data, type.displayName);
      }
      if (type.displayName === MapArea.displayName) {
        drawMapArea(this, chart, ds, layerConfig, data, key || index);
      }
      if (type.displayName === MapPoint.displayName) {
        drawMapPoint(this, chart, ds, layerConfig, data, key || index);
      }
      if (type.displayName === MapHeatMap.displayName) {
        drawHeatMap(this, chart, ds, layerConfig, data, key || index);
      }
    });

    if (config.labels || config.label) {
      drawMapLabel(this, chart, config);
    }

    // chart.render();
  }