-
Notifications
You must be signed in to change notification settings - Fork 32
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
Ensure addGrid.js code is drawing a grid to a decimal precision #18
Comments
Mridul, I think this may actually be he next place to work -- if we can get this grid to be on a specific scale, the other work on precision makes more sense. Think about it this way: for a given zoom level, what's the smallest decimal place grid (lines every 0.1, 0.01, or 0.001) you can draw where the grid squares will still be larger than 100px across? That's the grid we should draw. |
You can work from the |
To calculate the precision, you could iterate --
How's that? |
@jywarren I didn't get it. Do you want me to locate top corners of the middle box and set precision accordingly? |
No -- the grid itself should be drawn to a given precision, not the other way around. Think -- on the globe, there are set lines on each degree of latitude and longitude. If we drew a grid for each degree, we'd have 360 vertical lines and 180 horizontal ones for the whole globe. That would be a precision of zero -- that is, 0 decimals after the If we just wanted to look within one degree box of that, say, 71-72 and 33-34, we'd then be able to subdivide that box into 10x10 -- where each line would then fall on Take a look at this page: http://leafletjs.com/examples/zoom-levels/ But the zoom levels don't scale the same as the longitude/latitude subdivisions, because zoom is based on (from the article above):
We decide to draw the grid that's most appropriate for the current zoom level. So if you're at zoom level 6, we need to know what's the highest precision that results in something near 100 pixel wide grid squares. That's what the iteration above is designed to determine. |
Okay so I looked for the documentation and for 0 zoom it shows the whole map. And zooms by 2*2 for each lat and lon. Thus if we want 6 boxes for 360 degrees(i.e 1 box per 60 degrees), we set |
Ah, not quite -- i still think you're approaching it backwards -- it's not that we want to make 6 boxes for a given # of degrees, it's that we want to make one box for each degree, or each tenth of a degree, or each hundredth of a degree, or thousandth of a degree. We don't want to set the zoom at all -- let the user change the zoom, and we just want to figure out what's the smallest grid we should show them -- degrees (0), tenths (1), hundredths (2), and so on. |
So we're trying to figure out how far to subdivide! |
If we set zoom = 6 we have 1 box per pixel, don't we? |
If we zoom out of the map does the size of grid change or remain the same? |
the grid would recalculate each time we zoom in or out. hang on, i'm trying to write another note to help... |
But we can break this down into parts and tackle them one by one. Let's say, the first is:
We could write functions for these:
|
So we have the total pixels in map to be 400px*400px and for zoom = 0 we have 360 degrees in 400px thus pixels in 1 degree will be 400/360, right? |
That's right -- but we're never going to show the whole map, so that's not a common view. I think we can come up with a solution for that as well, though -- for example, we could draw lines every 10 degrees, in that case. |
so pixels per degree will be (400*(2^zoom))/360 right. Thats what we want? |
That would be only for a 400px wide map, and that may change. I think the best way to calculate pixels per degree may be to use the conversion tools in Leaflet, which will also ensure you don't make a mistake with projections -- think about the fact that the grid isn't evenly spaced depending on your latitude. Lines of longitude converge at the poles! So, you can calculate the pixel position of two points, |
Can you suggest any conversion methods from leaflet? |
Yes, sorry, i had added this link to an earlier comment but it's way up there now: http://leafletjs.com/reference-1.0.3.html#map-latlngtocontainerpoint |
Perfect so I just take two points varying with difference of one and get there container points, take there difference, and that will be the number of pixels per degree, each for lat and lon. Am I getting it right? |
Yes, exactly! Two points varying with difference of -- whatever the current fraction of a degree we're wondering about -- And you know, i think we can leave this part of it at just measuring latitude, because for regions we're looking at they'll be reasonably close to longitude. As we get to northern Russia, it could be like 2:1, but that's still OK for our drawn grid. |
So first we try with 1 then 0.1 and so on till we have |
Exactly.
…On Jun 17, 2017 3:24 PM, "Mridul Nagpal" ***@***.***> wrote:
So first we try with 1 then 0.1 and so on till we have (gridWidthInPixels(degrees)
< width) where gridWidthInPixels is nothing but the difference between
the outputs of the latlngtocontainerpoint, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3lZH5_Aq1erobFNZ4WVUqk4K8fPks5sFCf6gaJpZM4N8-jc>
.
|
And we'll get width from the |
Well, for now, just let |
@jywarren Added the two methods we are talking about. Should I write test specs for them as well? |
Let's move forward for a bit -- first i left some comments, but second, can you get the addGrid grid drawer to use this? |
We can call addGrid with an options argument, which will set the block size.Something like |
yes, perfect |
Added the options part, also renamed it to gridSystem. What next? |
i left a request about the latlng of 1,1 -- take a look! |
Great, #32 merged. Copying in my notes from the end of that: OK, this looks good -- why don't we merge it and then do another one where you create a method called: options.gridSystem.setCellSizeInDegrees(degrees); And let's rename var degrees = getMinimumGridWidth(100).degrees;
options.gridSystem.setCellSizeInDegrees(degrees); Makes sense? |
Take a short break and delete location_tags -- check off #11 -- it'll feel good! :-) |
Sure, thanks Jeff 😄 |
ok! i think you can begin integrating varying cellSize into https://github.com/publiclab/leaflet-blurred-location/blob/master/src/core/gridSystem.js -- give it a try! A test might be -- zoom the map, then show that the cell size has changed. |
What would be the cell size for different degrees? |
sorry, can you be more specific? I'm not sure I follow.
…On Sun, Jun 18, 2017 at 6:30 PM, Mridul Nagpal ***@***.***> wrote:
What would be the cell size for different degrees?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ1ECRGxPjp6XoQXZffDWzk0qNqhfks5sFaUggaJpZM4N8-jc>
.
|
As in if I enter degrees into the method setCellWidth what would I set the
cellSize to be? what relation would be between degrees and cellSize
…On 19-Jun-2017 6:47 AM, "Jeffrey Warren" ***@***.***> wrote:
sorry, can you be more specific? I'm not sure I follow.
On Sun, Jun 18, 2017 at 6:30 PM, Mridul Nagpal ***@***.***>
wrote:
> What would be the cell size for different degrees?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/publiclab/leaflet-blurred-location/
issues/18#issuecomment-309307191>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
AABfJ1ECRGxPjp6XoQXZffDWzk0qNqhfks5sFaUggaJpZM4N8-jc>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVULlPSjVnyn-sDbbkCnxtrMSONKXEmAks5sFcw_gaJpZM4N8-jc>
.
|
Ah, you can set cell size in degrees, no? Leaflet conversion methods can
help you if the codes not already able to accept that. But do conversions
inside gridSystem please.
On Jun 18, 2017 11:42 PM, "Mridul Nagpal" <notifications@github.com> wrote:
As in if I enter degrees into the method setCellWidth what would I set the
cellSize to be? what relation would be between degrees and cellSize
On 19-Jun-2017 6:47 AM, "Jeffrey Warren" ***@***.***> wrote:
sorry, can you be more specific? I'm not sure I follow.
On Sun, Jun 18, 2017 at 6:30 PM, Mridul Nagpal ***@***.***>
wrote:
> What would be the cell size for different degrees?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/publiclab/leaflet-blurred-location/
issues/18#issuecomment-309307191>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
AABfJ1ECRGxPjp6XoQXZffDWzk0qNqhfks5sFaUggaJpZM4N8-jc>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/publiclab/leaflet-blurred-location/
issues/18#issuecomment-309316851>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVULlPSjVnyn-
sDbbkCnxtrMSONKXEmAks5sFcw_gaJpZM4N8-jc>
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ0Q07F66LOt2mGZdkE1gKSjUsEncks5sFe4kgaJpZM4N8-jc>
.
|
@jywarren So if I enter 0.1 as degrees first I will have to calculate cellSize in pixels using |
Well, so you calculate cellSize in pixels to be sure it's less than 100px,
but then draw the grid based on degrees (ideally). I think if that really
doesn't work, we can just be sure to calculate the cell size locally enough
that as latitude/longitude change (say, when you're zoomed out enough) the
grid doesn't mismatch. But the strong preference is to draw the grid by
actual degrees, then we don't have to worry about conversion messing up.
…On Mon, Jun 19, 2017 at 4:56 PM, Mridul Nagpal ***@***.***> wrote:
@jywarren <https://github.com/jywarren> So if I enter 0.1 as degrees
first I will have to calculate cellSize in pixels using
latLngToContainerPoint() method?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3eG53Ubz6hOiY4p5jdIjhRaQBHOks5sFuBigaJpZM4N8-jc>
.
|
I got it now, what we are trying to do. Please have a look at the PR I have posted. The grid is made according to degrees it that. |
@jywarren Is there anything left of this issue or are we through? |
Let's assume it's done once we check it via your gh-pages demo. Thanks!
…On Thu, Jun 22, 2017 at 4:48 PM, Mridul Nagpal ***@***.***> wrote:
@jywarren <https://github.com/jywarren> Is there anything left of this
issue or are we through?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ40JJ8gBvYT-8buNHiQsuCJUXSXjks5sGtMagaJpZM4N8-jc>
.
|
Please have a look at #36 posted the snaps there, also pushed changes. |
Is this done? |
Merging into #36 |
The grid seems to have a statically set size of 64 -- https://github.com/publiclab/leaflet-blurred-location/blob/master/src/core/addGrid.js#L24
But it should be drawing a grid that's based on a precision of latitude/longitude, so, for example grid lines on:
Am i misunderstanding the code, and this is actually the case?
The text was updated successfully, but these errors were encountered: