Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix extend seems broken for some geoJson #245

Closed
lpas opened this issue Jul 26, 2021 · 2 comments
Closed

fix extend seems broken for some geoJson #245

lpas opened this issue Jul 26, 2021 · 2 comments

Comments

@lpas
Copy link

lpas commented Jul 26, 2021

const MINIMAP_PADDING = 40 // should be smaller than SIZE/2
const SIZE = 200 // actual size is size - padding
const poly = {
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [13.056508703137666,52.362012953186536],
                [13.055221242810262,52.36091224014757],
                [13.057088060284428,52.36012599975746],
                [13.058139486218977,52.36137087391279],
                [13.056508703137666,52.362012953186536]
            ]
        ]
    }
} 
const fc = { 'type': 'FeatureCollection', 'features': [poly] }
const projection = geoMercator().fitExtent([[MINIMAP_PADDING, MINIMAP_PADDING], [SIZE - MINIMAP_PADDING, SIZE - MINIMAP_PADDING]], fc)
const geoGenerator = geoPath().projection(projection)

results in a projection with scale 19.098593171019434 and translate of  [100, 99.99999999997485]

if i now get the path and display the poly with something like

const geoGenerator = geoPath().projection(projection)
geoGenerator(fc)

i get a super small path that is barely visible

there seems to be a problem with the calculation of the bounding box of the poly but I'm not familiar enough with the lib to pinpoint where this happens. the poly seems to get clipped and this results in a to big bounding box

if i calculate the bbox with something like turf i don't have this problem. if i calculate the scale & translate myself it comes out to something like scale 2225147.3776166504 translate [-506971.1720894703, 2395335.8344671903]

@lpas
Copy link
Author

lpas commented Jul 27, 2021

I looked at this a little more and i guess the poly is in the wrong winding order for d3 and thus creates a big square with a little hole in it that i couldn't see (because the image was very small and i only used outline)

Screenshot 2021-07-27 at 08 28 52

looks kinda strange to me but if this the intended behaviour the ticket can be closed

@Fil
Copy link
Member

Fil commented Jul 27, 2021

yes, see #227 ; you can probably use turf.rewind to change to winding order?

@Fil Fil closed this as completed Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants