albersUsa errors with Markers
See original GitHub issueOn react-simple-maps
v0.11.2, adding Markers to an AlbersUsa projection map produces the following client error:
Uncaught TypeError: Cannot read property '0' of null
at Marker.render (Marker.js:194)
...bunch of react errors
Here’s my code:
// @flow
import React, {Component} from 'react'
import {
ComposableMap,
ZoomableGroup,
Geographies,
Geography,
Markers,
Marker
} from 'react-simple-maps'
const schools = [{name: "Tennessee State University", coordinates: [36.165874, 86.830337]}]
export default class Map extends Component<{}> {
render() {
return (
<div>
<div className="oom-map__map">
<ComposableMap
projectionConfig={{
scale: 1000
}}
width={980}
height={551}
projection="albersUsa"
style={{
width: '100%',
height: 'auto'
}}
>
<ZoomableGroup disablePanning>
<Geographies
geography={geographies}
disableOptimization
>
{(geographies, projection) =>
geographies.map((geography, key) => {
return (
<Geography
key={key}
geography="https://raw.githubusercontent.com/jgoodall/us-maps/master/topojson/state.topo.json"
projection={projection}
style={{
default: {
fill: 'pink',
outline: 'none',
transition: 'all 200ms ease-in-out'
},
hover: {
fillOpacity: 0.7,
outline: 'none'
},
pressed: {
outline: 'none'
}
}}
/>
)
})}
</Geographies>
<Markers>
{schools.map((marker, i) => (
<Marker
key={i}
marker={marker}
>
<circle
cx={0}
cy={0}
r={10}
style={{
stroke: '#FF5722',
strokeWidth: 3,
opacity: 0.9
}}
/>
<text
textAnchor="middle"
y={0}
style={{
fontFamily: 'Roboto, sans-serif',
fill: '#607D8B'
}}
>
{marker.name}
</text>
</Marker>
))}
</Markers>
</ZoomableGroup>
</ComposableMap>
</div>
</div>
)
}
}
I haven’t tried every projection yet, but went through a handful and it seems that this is the only one that produces an error.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Cannot read property '0' of null - Interactive Geo Maps
If the map does not display and instead it displays this error, most likely it's something related with your markers coordinates.
Read more >Adding round markers results in “Cannot read property '0' of null”
When I edit an existing map, as soon as I add a round marker to my map the preview only shows the message...
Read more >New: Globe and Albers USA support in React-Simple-Maps v ...
Using Markers with Globes. Markers present a special challenge when implementing globes as they now have to become invisible as they move behind ......
Read more >d3 US state map with markers, zooming transform issues
Step 1. Add all the points in the group and not in the svg. This will ensure that the marker points translate with...
Read more >hrbrmstr/albersusa: Tools, Shapefiles & Data to Work with an ...
... is time consuming and potentially error-prone. Functions and data sets are provided to make it easier to produce maps with a composite...
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 Free
Top 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
Oop! That did, thanks.
I would change this then to a feature request- better error handling for coordinates that are not in the map view. I would expect the marker singular to not appear, not the whole map to error. Would you agree? Happy to add that in.
I ran into this when trying to zoom in with the geoAlbersUsa projection, and realized the default center [0,0] from the react-simple-maps demo was off the map. Using [-97,37] fixed it. Also, for the handle zoom in function, I make sure it’s in bounds.