【发布时间】:2020-11-04 03:25:30
【问题描述】:
我正在使用 MAP-BOX 在屏幕上绘制地图。我想对鼠标悬停产生一些影响。
我使用geojson 源和react-map-gl 作为包装器创建了行。
我想在鼠标悬停时为线条设置一些不透明度。
export const layer = {
'id': 'route',
'type': 'line',
'source': 'route',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#E95617',
'line-width': 2,
'line-dasharray':[1,2,3]
}
}
export const route1={
type: "Feature",
properties: {
id="route1"
},
geometry: {
type: "LineString",
coordinates: [
[76.994168,31.780632],
[76.993894,31.781929],
[76.997771,31.783204 ],
//------ more data
]
}
}
import ReactMapGL,{Source, Layer} from "react-map-gl";
const Routes=()=>{
return <ReactMapGL {...props}>
<Source type="geojson" data={tempdata.route1}>
<Layer {...tempdata.layer}/>
</Source>
<Source type="geojson" data={tempdata.route2}>
<Layer {...tempdata.layer1}/>
</Source>
</ReactMapGL>
}
当我打开浏览器控制台并查找 id route and route 然后它报告我为空。我没有看到任何将类名添加到 geojson 源的示例或文档。
如何创建悬停效果?
【问题讨论】:
-
docs.mapbox.com/mapbox-gl-js/example/hover-styles它提供了一种方式,但是我们需要使用原生api。
标签: reactjs mapbox-gl-js react-map-gl