React + mapbox-gl:包括弹出窗口?
React + mapbox-gl: Include popup?
我在 React 中使用 mapbox-gl,虽然 mapbox-gl 工作正常,但我无法弄清楚如何集成 mapbox-gl 的弹出窗口。我有 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}"
}
});
});
}
},
想通了。
let popup = new mapboxgl.Popup()
.setLngLat()
.setHTML(
'<div>lorem ipsum blah blah</div>'
)
.addTo(map);
我在 React 中使用 mapbox-gl,虽然 mapbox-gl 工作正常,但我无法弄清楚如何集成 mapbox-gl 的弹出窗口。我有 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}"
}
});
});
}
},
想通了。
let popup = new mapboxgl.Popup()
.setLngLat()
.setHTML(
'<div>lorem ipsum blah blah</div>'
)
.addTo(map);