0

I'm using mapbox-gl in React, and while mapbox-gl is working fine, I'm having trouble figuring out how to integrate mapbox-gl's Popups. I have the let Popup function, but don't know how to implement it.

renderMap() {
    if (this.props.bird.location) {
        let birdLocation = this.props.bird.location;
        let map = new mapboxgl.Map({
            container: 'mapbox-container',
            style: config.mapbox.style,
            center: birdLocation,
            zoom: 13,
            interactive: false,
            preserveDrawingBuffer: true
        });
        let popup = new mapboxgl.Popup({
            setLngLat: [-96, 37.8],
            setHTML: '<h1>Hello World!</h1>',
            addTo: map
        });

        map.on('load', function () {
            map.addSource("points", {
                "type": "geojson",
                "data": {
                    "type": "FeatureCollection",
                    "features": [{
                        "type": "Feature",
                        "geometry": {
                            "type": "Point",
                            "coordinates": birdLocation
                        },
                        "properties": {
                            "icon": "dark-map-pin"
                        }
                    }]
                }
            });

            map.addLayer({
                "id": "points",
                "type": "symbol",
                "source": "points",
                "layout": {
                    "icon-image": "{icon}"
                }
            });
        });
    }
},
eclipsis
  • 1,541
  • 3
  • 20
  • 56

1 Answers1

1

Figured it out.

let popup = new mapboxgl.Popup()
    .setLngLat()
    .setHTML(
        '<div>lorem ipsum blah blah</div>'
    )
    .addTo(map);
eclipsis
  • 1,541
  • 3
  • 20
  • 56
  • 1
    This answer is not correct. Where do you use a react component in this code? The question is asking how to use a react component in the mapbox-gl popup. The correct answer is here https://stackoverflow.com/questions/48916901/possible-to-render-react-component-within-mapboxgl-popup-in-sethtml-or-setdo – nntona Sep 28 '20 at 00:59