反应传单碰撞

React Leaflet Collision

我使用的地图没有任何城镇标签。我正在放置标签,我需要这些标签在缩放 in/out 时出现和消失。缩小时只出现大城镇,放大时出现所有城镇。在现有的 react-leaflet 中是否具有此功能? 我也在尝试为 Leaflet.LayerGroup.Collision 制作插件, 我尝试从 react-leaflet

覆盖 LayerGroup
import React, { PropTypes } from 'react';
import { MapLayer } from 'react-leaflet';
import { layerGroup } from 'leaflet';
import './leaflet-layergroup-collision';

export default class LayerGroupCollision extends MapLayer {
  static childContextTypes = {
    layerContainer: PropTypes.shape({
      addLayer: PropTypes.func.isRequired,
      removeLayer: PropTypes.func.isRequired,
    })
  }

  getChildContext() {
    return {
      layerContainer: this.leafletElement,
    }
  }

  createLeafletElement() {
    return layerGroup(this.getOptions()).collision({margin:5});
  }
}

但我收到错误

Uncaught TypeError: (0 , _leaflet.layerGroup)(...).collision is not a function

任何帮助如何实现这个或任何替代想法?

layerGroup要大写L,LayerGroup

import { LayerGroup } from 'leaflet';

或另一种尝试:

import L from 'leaflet';

然后是

L.LayerGroup(this.getOptions()).collision({margin:5});