mariusandra / pigeon-maps

ReactJS Maps without external dependencies
https://pigeon-maps.js.org/
MIT License
3.45k stars 143 forks source link

GeoJson TypeError: latLngToPixel is not a function #174

Closed djeka07 closed 5 months ago

djeka07 commented 1 year ago

First want to say that i love this library, switching from mapbox for performance reasons and already seeing massive performance gains.

I have a problem with GeoJson though. I get an error that latLngToPixel is not a funcion and in the source code, i dont see it being sent from the MultiLineString component to the LineString component.

MultiLineString component looks like this:

export function MultiLineString(props: GeometryProps): JSX.Element {
  return (
    <>
      {props.coordinates.map((line, i) => (
        <LineString coordinates={line} key={i} />
      ))}
    </>
  )
}

And the LineString component deconstruct the latLngToPixel from props:

export function LineString(props: GeometryProps): JSX.Element {
  const { latLngToPixel } = props
  const p =
    'M' +
    (props.coordinates as Array<[number, number]>).reduce((a, [y, x]) => {
      const [v, w] = latLngToPixel([x, y])
      return a + ' ' + v + ' ' + w
    }, '')

  return <path d={p} {...(props.svgAttributes as SVGProps<SVGPathElement>)} />
}

The MultiPolygon component for example spreads props and therefore the Polygon gets the latLngToPixel props.

export function MultiPolygon(props: GeometryProps): JSX.Element {
  return (
    <>
      {props.coordinates.map((polygon, i) => (
        <Polygon {...props} coordinates={polygon} key={i} />
      ))}
    </>
  )
}

Am i missing something or is this a bug?

Thanks in advance!

//André

aloxe commented 5 months ago

@djeka07 Thanks a lot for this diagnostic, this is exactly the answer to a problem that stuck me for too long. Now let's hope my PR gets merged quickly.

mariusandra commented 5 months ago

Out with v0.21.5