2017-03-07 75 views
0

我使用的地圖沒有任何城鎮標籤。我正在放置標籤,我需要這些標籤在放大/縮小時出現並消失。縮小時縮小顯示所有城鎮時,只有大城鎮出現。現有反應傳單中是否有這種功能? 還我試圖讓插件Leaflet.LayerGroup.Collision, 我試圖從反應小葉React Leaflet Collision

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

任何幫助,如何實現這個或任何替代理念?

回答

1

圖層組應與資本L,圖層組

import { LayerGroup } from 'leaflet'; 

或另一種嘗試:

import L from 'leaflet'; 

然後

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

這幫助了錯誤。 –

+0

嗨,如果這解決了您在問題中遇到的錯誤,您應該接受答案。謝謝! –