Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

support single point in fitBounds #95

Open
xoddong opened this issue Jul 3, 2019 · 2 comments
Open

support single point in fitBounds #95

xoddong opened this issue Jul 3, 2019 · 2 comments

Comments

@xoddong
Copy link

xoddong commented Jul 3, 2019

Currently, there isn't support for a single point to the fitBounds function.
We get an assertion error if we were to do

const width = 800
const height= 800
const bounds = [[-74.0066517, 40.7083267]]
const viewport = new WebMercatorViewport({ width, height }).fitBounds(bounds)

My issue and use case is similar to that of mapbox-gl issue #3307.

Would it be possible to do something where we center around that point if a single point is passed in?

@coyotespike
Copy link

Same here.

Currently I am making a viewport manually, by setting the lat and lng equal to my single point, and height/width/zoom to sensible defaults.

WebMercatorViewport.getMapCenterByLngLatPosition requires a pixel location as well, and so isn't a great substitute.

@arminrosu
Copy link

The issue is caused by these lines:

const scaleX = targetSize[0] / size[0];
const scaleY = targetSize[1] / size[1];

size is [0, 0] for point bounds. Then scaleY / scaleY becomes Infinity and from there it all goes sideways.

A default scale parameter / value would fix this. I would prefer a parameter, since a point can be displayed at any scale, but applications might be different based on your use case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants