agentscript icon indicating copy to clipboard operation
agentscript copied to clipboard

Might be nice to guess a good Z also.

Open m0ose opened this issue 2 years ago • 5 comments

The center is guessed from the bbox. It might be nice to guess the Z value also. https://github.com/backspaces/agentscript/blob/8e999fe5f2e6af122c35df2fcaa43499c2e8d3aa/gis/leafletInit.js#L68

m0ose avatar Jul 26 '22 18:07 m0ose

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 avatar Jul 30 '22 16:07 backspaces

Maybe tilebelt has a hint?

backspaces avatar Aug 12 '22 22:08 backspaces

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;
}

backspaces avatar Aug 13 '22 15:08 backspaces

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

m0ose avatar Aug 14 '22 00:08 m0ose

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]

backspaces avatar Aug 14 '22 14:08 backspaces