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

Might be nice to guess a good Z also. #64

Open
m0ose opened this issue Jul 26, 2022 · 5 comments
Open

Might be nice to guess a good Z also. #64

m0ose opened this issue Jul 26, 2022 · 5 comments

Comments

@m0ose
Copy link
Collaborator

m0ose commented Jul 26, 2022

The center is guessed from the bbox. It might be nice to guess the Z value also.

const center = gis.latlon(model.world.bboxCenter())

@backspaces
Copy link
Owner

So the center is basically the center coords of the model. That seems reasonable for Leaflet's Map constructor .. centers the model in the middle of Leaflet.

What could we do for Z? Possibly figure out the Z that would make sure all the model is in Leaflet's view? I imagine there is a power of 2 stunt for that.

For both LeafletDraw and leafleIInit we could calculate these in the options object.
And possibly add the Z calc in src/gis.js. I think center is already there.

We might want to add pixel versions too? I.e. the programmer could know the pixel width/height of Leaflet's div and prefer to not bother with lon/lats

@backspaces
Copy link
Owner

Maybe tilebelt has a hint?

@backspaces
Copy link
Owner

backspaces commented Aug 13, 2022

tilebelt has a function that gives a zoom given a bbox. It is not documented or mentioned, but is used by bboxToTile which "Get the smallest tile to cover a bbox"

I have no idea how it works!

function getBboxZoom(bbox) {
    var MAX_ZOOM = 28;
    for (var z = 0; z < MAX_ZOOM; z++) {
        var mask = 1 << (32 - (z + 1));
        if (((bbox[0] & mask) !== (bbox[2] & mask)) ||
            ((bbox[1] & mask) !== (bbox[3] & mask))) {
            return z;
        }
    }

    return MAX_ZOOM;
}

@m0ose
Copy link
Collaborator Author

m0ose commented Aug 14, 2022

That is wild. Is bbox in the form [west, south, east, north] ?

@backspaces
Copy link
Owner

backspaces commented Aug 14, 2022

Yup, but I'm not so sure it works. It gave a pretty odd result for the santa fe bbox:

bbox = [-109.050044, 31.332301, -103.001964, 37.000104]
(4) [-109.050044, 31.332301, -103.001964, 37.000104]
bboxToTile(bbox)
(3) [3, 6, 4]

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

No branches or pull requests

2 participants