Plots2: Geographic: Set a default location of user's profile location on /post/

Created on 9 Dec 2019  ยท  15Comments  ยท  Source: publiclab/plots2

My goal here is to:

  • check if the currently logged in user has a location saved
  • if they do, pre-fill the location form with that info
  • present a way for them to remove that info

Most helpful comment

Ok perfect! I'll add these tasks to my list for the week and create issues for them. :+1:

All 15 comments

One problem I'm seeing with the maps is that the blurred location is not saving zoom level. When I save my blurred location in my profile it looks like this:

FireShot Capture 099 - ๐ŸŽˆ Public Lab_ admin - localhost

But when those numbers carry over to /post it's showing this:
FireShot Capture 100 - ๐ŸŽˆ Public Lab_ Post - localhost

When I zoom in it changes:
FireShot Capture 101 - ๐ŸŽˆ Public Lab_ Post - localhost

Is this just how blurredlocation works?

Hi! Zoom level is inferred from the number of digits of precision,
actually! https://github.com/publiclab/leaflet-blurred-location#how-it-works

However, we are allowing for a specific "override" tag of zoom:____ if
you want to override how LBL calculates zoom.

Thanks!

On Mon, Dec 9, 2019 at 2:22 PM Natalie St Jean notifications@github.com
wrote:

One problem I'm seeing with the maps is that the blurred location is not
saving zoom level. When I save my blurred location in my profile it looks
like this:

[image: FireShot Capture 099 - ๐ŸŽˆ Public Lab_ admin - localhost]
https://user-images.githubusercontent.com/49460529/70465544-2e70a080-1a8f-11ea-9c58-ac5b0c739bcc.png

But when those numbers carry over to /post it's showing this:
[image: FireShot Capture 100 - ๐ŸŽˆ Public Lab_ Post - localhost]
https://user-images.githubusercontent.com/49460529/70465572-3a5c6280-1a8f-11ea-91e7-d6c3d7fead09.png

When I zoom in it changes:
[image: FireShot Capture 101 - ๐ŸŽˆ Public Lab_ Post - localhost]
https://user-images.githubusercontent.com/49460529/70465606-4b0cd880-1a8f-11ea-9cca-c712c8274974.png

Is this just how blurredlocation works?

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/6946?email_source=notifications&email_token=AAAF6J6AP4TXREB27ZUZHE3QX2LGZA5CNFSM4JYP57Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGKK47A#issuecomment-563392124,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAF6J4ZH6MLLEYX3U6H623QX2LGZANCNFSM4JYP57QQ
.

Hmmm. I don't know that it's doing that calculation correctly in this map, because this is what I get when I input a tight zoom of lat:61.5 and lon:9.7

FireShot Capture 102 - ๐ŸŽˆ Public Lab_ Post - localhost

Looks look instead of setting the zoom appropriately it's rounding the numbers to the nearest 10.

Hm, ok, can we document exactly what the handoffs are here? Like, am I
understanding that it's [user profile geo tags (no zoom)] => [/post to
draft a new post]... and it's sourcing lat/lon from the user profile tags?

Thanks for taking a close look here! We'll want to be sure this is well
plumbed and system tested.

On Mon, Dec 9, 2019 at 3:08 PM Natalie St Jean notifications@github.com
wrote:

Hmmm. I don't know that it's doing that calculation correctly in this map,
because this is what I get when I input a tight zoom of lat:61.5 and lon:9.7

[image: FireShot Capture 102 - ๐ŸŽˆ Public Lab_ Post - localhost]
https://user-images.githubusercontent.com/49460529/70468736-a0e47f00-1a95-11ea-972f-bd79dd96d545.png

Looks look instead of setting the zoom appropriately it's rounding the
numbers to the nearest 10.

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/6946?email_source=notifications&email_token=AAAF6J5Y77DNEOCEHYKGVEDQX2QR5A5CNFSM4JYP57Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGKQDSI#issuecomment-563413449,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAF6JYA42FW3L4ACBIB7ETQX2QR5ANCNFSM4JYP57QQ
.

Yes. It's reading the correct lat/lon from the user tags, and I have it checking if there is a tag for location:blurred and setting that option as well. If I uncheck the "blur my location" box it's showing the correct lat/lon, but when I check the box it rounds the numbers again. The lat/lon gets passed into the PL.Editor here:

https://github.com/publiclab/plots2/blob/68245096cf4bac7635bc7c7a3f9c8b2663b56a59/app/views/editor/rich.html.erb#L317-L320

Found it... the default zoom level is hardcoded at 5 in PL.Editor:
https://github.com/publiclab/PublicLab.Editor/blob/e009d67aa3a26307f1f35d1cca983ffe579117d9/src/modules/PublicLab.MapModule.js#L32

I'm assuming I'll have to either calculate the zoom level myself, or create a function that calculates it given the number of precision in the saved lat and lon? It can't be hardcoded, obviously. I'm in leaflet-blurred-location for any methods that might calculate appropriate zoom level, but all I'm seeing is setZoom and setZoomByPrecision (which I believe depends on the map, which is the opposite of what I need).

@sagarpreet-chadha where do we make the calculation already, and can we standardize how we do this using, perhaps, https://github.com/publiclab/blurred-location or a Ruby port of one of its basic utility methods?

Also want to note @nfarve has been working on https://github.com/publiclab/plots2/pull/6858 which could overlap here.

@sagarpreet-chadha Can you take a look at this? Is there anywhere in leafleft-blurred-location where it calculates the appropriate zoom level according to the precision of the saved lat and lon?

I think possibly we're only doing this in plots2, but we should standardize
as much as possible...

https://github.com/publiclab/plots2/blob/7a6d9316193e1cb5b9318aa49dca665d52c54f27/app/views/map/_leaflet.html.erb#L24

But Sagarpreet may know more recent info than me on this feature. Thanks!!!

On Wed, Dec 11, 2019 at 2:39 PM Natalie St Jean notifications@github.com
wrote:

@sagarpreet-chadha https://github.com/sagarpreet-chadha Can you take a
look at this? Is there anywhere in leafleft-blurred-location where it
calculates the appropriate zoom level according to the precision of the
saved lat and lon?

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/6946?email_source=notifications&email_token=AAAF6J3D2VQG2QCCGKIUBRTQYE6WRA5CNFSM4JYP57Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGUKINY#issuecomment-564700215,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAF6JYGDJ2KVBMIII2A7KTQYE6WRANCNFSM4JYP57QQ
.

I'm thinking it would probably be good to have a function in LBL that takes in lat and lon, does the calculation and returns a zoom level.

<%= lat.to_s.length.to_i %> + 6 I'm not even sure this would give consistent results... wouldn't this give different zoom levels for 46.25 and 4.25?

These are the zoom numbers given on the LBL docs. Should I use these numbers instead of the formula above?
https://github.com/publiclab/leaflet-blurred-location#human-readable-blurring

Zoom level | Lat/lon coordinate precision | Human-readable placename
-- | -- | --
0 | x0.0 | planet
5 | x0.0 | state, province, country
6 | x.0 | state, province, region
10 | 0.x | city, postal code
13 | 0.0x | neighborhood
16 | 0.00x | block

This code in LBL is different than the table above, this is what's actually used:

https://github.com/publiclab/leaflet-blurred-location/blob/1040824864a3e05a83e1e3d9ac75626d56a01ae6/src/blurredLocation.js#L204-L207

var precisionTable = {'-2': 2, '-1': 3, '0':6, '1':10, '2':13, '3':16};

Okay, let's break it:

  1. @nfarve has been working on #6858 .
    -> So after this has been done, PL.editor will take ZOOM level as input and on /post page that zoom level will be applied.

  2. Now we need to preserve the zoom level when a person adds location using LBL model. For this lwe need to change LBL model to give zoom level as output along with lat/lng . Maybe let's make a separate function getZoom which would be straightforward to implement.
    Taking that zoom level to create a POWER TAGzoom:xx in plots2.

  3. Now for the existing users who do not have zoom:xx tags yet,

  4. We need to implement a function in LBL getZoomFromCoordinates(lat, lng)
  5. -> This function takes lat and lng as input and returns a zoom level.
  6. To implement this you need to change LBL API to take an array as input of format -
    More details here:
    https://github.com/publiclab/leaflet-blurred-location-display#zoom_filter--changing-the-zoom-levels-range-where-x-precision-marker-should-be-visible-
    If this array is not passed we can use default array : zoom_filter = [[0,4,0] , [5,7,2] , [8,11,4] , [12,18,5]] ;
  7. Using this zoom_filter array, the getZoomFromCoordinates will return zoom level.
  8. So in plots2 now, if zoom:xx is not present we will call this function.

  9. Also we should make POWER TAG zoom:xx from the zoom level returned by above getZoomFromCoordinates.

Tell me if anything is unclear. Thanks ๐Ÿ˜„ !

This is awesome! Thanks all!

On Sat, Dec 14, 2019, 4:37 AM Sagarpreet Chadha notifications@github.com
wrote:

Okay, let's break it:

1.

@nfarve https://github.com/nfarve has been working on #6858
https://github.com/publiclab/plots2/pull/6858 .
-> So after this has been done, PL.editor will take ZOOM level as
input and on /post page that zoom level will be applied.
2.

Now we need to preserve the zoom level when a person adds location
using LBL model. For this lwe need to change LBL model to give zoom level
as output along with lat/lng . Maybe let's make a separate function
getZoom which would be straightforward to implement.
Taking that zoom level to create a POWER TAGzoom:xx in plots2.
3.

Now for the existing users who do not have zoom:xx tags yet,

  • We need to implement a function in LBL getZoomFromCoordinates(lat,
    lng)
  • -> This function takes lat and lng as input and returns a zoom level.
  • To implement this you need to change LBL API to take an array as
    input of format -
    More details here:

    https://github.com/publiclab/leaflet-blurred-location-display#zoom_filter--changing-the-zoom-levels-range-where-x-precision-marker-should-be-visible-
    If this array is not passed we can use default array : zoom_filter =
    [[0,4,0] , [5,7,2] , [8,11,4] , [12,18,5]] ;

  • Using this zoom_filter array, the getZoomFromCoordinates will return
    zoom level.
  • So in plots2 now, if zoom:xx is not present we will call this
    function.

  • Also we should make POWER TAG zoom:xx from the zoom level returned
    by above getZoomFromCoordinates.

Tell me if anything is unclear. Thanks ๐Ÿ˜„ !

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/6946?email_source=notifications&email_token=AAAF6JYOYHTKN6OEMTS7I6DQYSSPHA5CNFSM4JYP57Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG362AA#issuecomment-565701888,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAF6JZLMIKJHQ77RMROKJLQYSSPHANCNFSM4JYP57QQ
.

Ok perfect! I'll add these tasks to my list for the week and create issues for them. :+1:

Was this page helpful?
0 / 5 - 0 ratings