1

アイコンが特定の URL から動的に読み込まれるように、自分の場所にカスタム アイコンを表示する必要があります。これが私のコードです。

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

このスタイルでは、式「get」を使用しましたが、textField に Icon URI 値を設定し、URI を表示するため、機能します。ただし、URI でiconImageプロパティを設定すると、アイコンが正常に表示されます

4

1 に答える 1

1

react-native-mapbox-gl 7.0 では、iconImage定数の場合はurl-s を使用できます。しかし、それが式である場合は、イメージのイメージ dict のキーである必要があります<Images images={images} />

https://github.com/react-native-mapbox-gl/maps/issues/652を参照してください

于 2020-02-07T05:26:56.117 に答える