Android 从URI动态响应本机mapbox符号层渲染图标
我需要显示自定义图标在我的地方,图标是从一个特定的URL动态加载。这是我的密码Android 从URI动态响应本机mapbox符号层渲染图标,android,react-native,icons,react-native-mapbox-gl,Android,React Native,Icons,React Native Mapbox Gl,我需要显示自定义图标在我的地方,图标是从一个特定的URL动态加载。这是我的密码 const PlacesMarker = props => { const { places } = props const [geoJson, setGeoJson] = useState([]) useEffect(() => { if (places) renderPlaces(places) }, [places])
const PlacesMarker = props => {
const { places } = props
const [geoJson, setGeoJson] = useState([])
useEffect(() => {
if (places)
renderPlaces(places)
}, [places])
const renderPlaces = (places) => {
let features = places.content.map((item) => {
return {
type: "Feature",
id: item.id,
properties: {
id: item.id,
icon: item.type.iconUri,
name: item.name,
type: item.type.name
},
geometry: {
type: "Point",
coordinates: [item.location.lon, item.location.lat],
},
}
})
setGeoJson(features)
}
return (
<View>
{geoJson.length > 0 ?
<MapboxGL.ShapeSource id={'places-map'}
shape={{ type: "FeatureCollection", features: geoJson }}>
<MapboxGL.SymbolLayer
id={Math.random().toString()}
style={{
iconImage: ['get', 'icon']
iconAllowOverlap: true,
// iconSize: 0.80,
iconIgnorePlacement: true,
textField: ['get', 'icon']
}}
/>
</MapboxGL.ShapeSource> : null
}
</View >
)
}
export default PlacesMarker
const PlacesMarker=props=>{
常量{places}=props
const[geoJson,setGeoJson]=useState([])
useffect(()=>{
若有(地方)
渲染位置(位置)
},[地点])
常量渲染位置=(位置)=>{
让features=places.content.map((项目)=>{
返回{
键入:“功能”,
id:item.id,
特性:{
id:item.id,
图标:item.type.iconUri,
名称:item.name,
类型:item.type.name
},
几何图形:{
键入:“点”,
坐标:[item.location.lon,item.location.lat],
},
}
})
setGeoJson(功能)
}
返回(
{geoJson.length>0?
:null
}
)
}
导出默认PlacesMarker
在样式中,我使用了表达式“get”,它可以工作,因为我用图标URI值设置了textField,它显示了URI。但是,如果我使用URI设置iconImage属性,则图标将成功显示在react native mapbox gl 7.0中。如果
iconImage
为常量,则可以使用url
-s。但是如果它是一个表达式,那么它应该是图像中的一个键
看