Feature not showing up on map when using images prop with svg
See original GitHub issuehaving an issue where feature doesn’t show up on map.
I’m loading a custom image with images prop. confirmed via logs the images prop is being set correctly.
import marker from './marker.svg';
// tslint:disable-next-line:no-var-requires
const { token, styles } = require('./config.json');
// full options found at: https://github.com/alex3165/react-mapbox-gl/blob/master/docs/API.md
const Map = ReactMapboxGl({ accessToken: token });
const MapComponent = (props) => {
const [images, setImages] = React.useState(null)
React.useEffect(() => {
const markerImage = new Image(30, 30)
markerImage.src = marker
setImages(['custom-marker', markerImage])
}, [])
// long, lat
const center = [-83.0458, 42.3314] as [number, number];
if (images === null) {
return null
}
console.log(images)
return (
<Map
style="mapbox://styles/mapbox/light-v9"
center={center}
zoom={[9]}
containerStyle={{
height: '100vh',
width: '100vw'
}}
>
{images.length > 0 ? (
<Layer
type="symbol"
id="marker"
images={images}
layout={{ 'icon-image': 'custom-marker' }}
>
<Feature coordinates={center} />
</Layer>
) : (
<div></div>
)
}
</Map>
);
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:15
Top Results From Across the Web
How can I use an SVG image as a map marker in OpenLayers ...
style. Icon source (“src”) property attribute just fine. However, this fails using an SVG image. Is there some other way to use an...
Read more >Troubleshooting SVG image errors in Mapbox Studio | Help
Learn how to fix SVG upload errors in Mapbox Studio. ... Sometimes SVGs fail to upload or upload successfully, but do not appear...
Read more >How to use SVGs in React | Sanity.io guide
There are a few ways to use an SVG in a React app: Use it as a regular image; Import it as a...
Read more >Accessible SVGs | CSS-Tricks
This example is fine to use as just a basic image replacement, ... role="img" (so that the SVG is not traversed by browsers...
Read more >How to create SVG maps in React with react-simple-maps
Most features offered by react-simple-maps are in form of simple React components that you import and render with the appropriate props.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Guys,
I think this bug has been introduced in v5.
I’ve installed v4.8.6 and it works (got the marker showing up)
<Map style="mapbox://styles/mapbox/streets-v8" zoom={[8]} containerStyle={{ height: '100%', width: '500px' }} > <Layer type="symbol" id="marker" layout={{ 'icon-image': 'marker-15' }}> <Feature coordinates={[-0.481747846041145, 51.3233379650232]} /> </Layer> </Map>
even if i use the example from the npm page, still doesn’t work