custom marker icon with react-leaflet

后端 未结 3 1738
挽巷
挽巷 2021-01-03 23:56

I tried everything I found on the web, Stackoverflow and Github, and I still can\'t make it.

I want to make a custom marker with a custom icon, but with my code belo

3条回答
  •  离开以前
    2021-01-04 00:32

    I was brought here while trying to figure out how to render a custom icon server side (using react-leaflet-universal). I thought I'd post this in case anyone in the future finds themselves here for the same reason. Just as in the case of react-leaflet-markercluster, I was able to get this working by requiring leaflet inside the return function like:

    
                {() => {
                    const MarkerClusterGroup = require('react-leaflet-markercluster').default;
                    const L = require('leaflet');
    
                    const myIcon = L.icon({
                        iconUrl: require('../assets/marker.svg'),
                        iconSize: [64,64],
                        iconAnchor: [32, 64],
                        popupAnchor: null,
                        shadowUrl: null,
                        shadowSize: null,
                        shadowAnchor: null
                    });
    
                    return (
                        
                            
                            
                                {coordArray.map(item => {
                                    return (
                                        
                                            {item.title && 
                                                {item.title}
                                            }
                                        
                                    )
                                })}
                            
                        
                    );
                }}
            
    

提交回复
热议问题