简体   繁体   English

React + mapbox-gl:包括弹出窗口?

[英]React + mapbox-gl: Include popup?

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. 我在React中使用mapbox-gl,虽然mapbox-gl正常工作,但我在弄清楚如何集成mapbox-gl的Popups时遇到了麻烦。 I have the let Popup function, but don't know how to implement it. 我有let Popup函数,但是不知道如何实现它。

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}"
                }
            });
        });
    }
},

Figured it out. 弄清楚了。

let popup = new mapboxgl.Popup()
    .setLngLat()
    .setHTML(
        '<div>lorem ipsum blah blah</div>'
    )
    .addTo(map);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM