publiclab / leaflet-environmental-layers

Collection of different environmental map layers in an easy to use Leaflet library, similar to https://github.com/leaflet-extras/leaflet-providers#leaflet-providers
https://publiclab.github.io/leaflet-environmental-layers/example/
GNU General Public License v3.0
99 stars 77 forks source link

Show questions asked on publiclab.org on map #30

Open sagarpreet-chadha opened 6 years ago

sagarpreet-chadha commented 6 years ago

@liz wants to know whether we can show the questions asked on publiclab.org on map .

sagarpreet-chadha commented 6 years ago

Hi @jywarren ...do we have an API to get questions with tag = map ? or leaflet ? or layer ? and have lat/lon tags ?

jywarren commented 6 years ago

I think so - @stefannibrasil may know more about this!

On Thu, Jul 12, 2018 at 1:54 PM Sagarpreet Chadha notifications@github.com wrote:

Hi @jywarren https://github.com/jywarren ...do we have an API to get questions with tag = map ? or leaflet ? or layer ? and have lat/lon tags ?

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/leaflet-environmental-layers/issues/30#issuecomment-404596305, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJz9ltqGnUh5lHlkYZ9Sf8ysCu3j7ks5uF405gaJpZM4VKhq6 .

stefannibrasil commented 6 years ago

Hi, everyone!

yeah, can you try using this?

https://publiclab.org/api/srch/taglocations?srchString=lat,lon&tagName=tag

jywarren commented 5 years ago

This page may be a good example of how to add such a layer: https://github.com/publiclab/leaflet-environmental-layers/blob/master/src/mapKnitterLayer.js

In addition to this guide: https://github.com/publiclab/leaflet-environmental-layers/issues/50

jywarren commented 5 years ago

Hmm, this may not be right anymore - i think it was changed to:

https://publiclab.org/api/srch/taglocations?query=lat,lon&tagName=tag

However, we want to show all tagged with question:* -- is this possible, @stefannibrasil ? or is there another relatively easy way to get only questions?

Thank you!

jywarren commented 5 years ago

This was added to the GCI dashboard!

nonas-hunter commented 5 years ago

Hi, I am a GCI participant.

I have been trying to solve this issue, but I have been having a hard time accessing the api.

I haven't touched the mapping part yet... I am just trying to query the information from the API. But I can not seem to have it return any questions. When I search:

https://publiclab.org/api/srch/taglocations?query=18.00,-66.00 (this is directly from the documentation)

Nothing shows up, even if I change the numbers.

I have tried using https://publiclab.org/api/srch/all?query=[question title] and I am not even able to find the question I was looking for.

Maybe the API has to be set up first so that it includes information needed to create this map? (I could be very wrong and just don't know how to use the API).

Could anybody help? @jywarren or @sagarpreet-chadha do you have any suggestions?

jywarren commented 5 years ago

Hmm, we may have just changed this according to https://github.com/publiclab/plots2/pull/3700 -- let's see!

jywarren commented 5 years ago

Hmm, i'm also not seeing anything for https://publiclab.org/api/srch/taglocations?query=42.00,-71.00&tag=balloon-mapping ... looking...

@milaaraujo do you know why this might not be returning results? Thank you!

jywarren commented 5 years ago

This test is supposed to demonstrate this API call functioning:

https://github.com/publiclab/plots2/blob/c97968aa6bce38dbb2d66548ee05cae0dc4cdc23/test/functional/api/search_api_test.rb#L101-L119

nonas-hunter commented 5 years ago

I tried doing a test of the API myself (queried the API with the same command as used in the test file) and I am not getting any result despite the test saying that it is supposed to give a result.

This is the command I ran: https://publiclab.org/api/srch/taglocations?query=71.00,52.00 (gave no results) This are the inputs used in the test query: /api/srch/taglocations?query=71.00,52.00 (should give at least 1 result)

Am I doing something wrong? How can I fix this?

@jywarren - Thanks for all the help. I really appreciate it!

milaaraujo commented 5 years ago

@nonas-hunter, the test is using data from plots2/test/fixtures/, so by calling https://publiclab.org/api/srch/taglocations?query=71.00,52.00, you will not retrieve the same example.


@jywarren, I think the problem here is the range of the search... For example, I have this question here with 'lat:1.010689' and 'lon:9.997558'. I can retrieve this question by calling:

But it does not work with: 'https://publiclab.org/api/srch/taglocations?query=1.0,8.9'

The "problem" is probably here:

items = Node.includes(:tag)
      .references(:node, :term_data)
      where('node.nid IN (?) AND term_data.name LIKE ?', nids, 'lon:' + lon[0..lon.length - 2] + '%')
      .order('node.nid DESC')
      .limit(limit)

This part of the code is a legacy from the first version of the API. Stefannni and I didn't work on this query that is why I'm not really sure about it!

milaaraujo commented 5 years ago

And it is not possible to search with the wildcard, for example: "tag=question:*".

sagarpreet-chadha commented 5 years ago

I guess we should make a new API to get :

Similar to this : https://www.purpleair.com/data.json?fetchData=true&minimize=true&sensorsActive2=10080&orderby=L&nwlat=71.01695975726373&selat=4.390228926463396&nwlng=-172.79296875&selng=80.33203125

milaaraujo commented 5 years ago

@sagarpreet-chadha, do you mean a new endpoint in the search API? Or a new API?

jywarren commented 5 years ago

Perhaps we could modify this one in stages. If 4 coordinates are offered, it could do bounding box, instead of "nearby".

If no coordinates are offered, it could just show all questions (sorted/filtered by time, say).

What do you think?

On Thu, Nov 15, 2018 at 1:52 PM Camila AraΓΊjo notifications@github.com wrote:

@sagarpreet-chadha https://github.com/sagarpreet-chadha, do you mean a new endpoint in the search API? Or a new API?

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/leaflet-environmental-layers/issues/30#issuecomment-439149892, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ0tlxoVyb07hqc1_DjuX6SuZz8BYks5uvbfUgaJpZM4VKhq6 .

jywarren commented 5 years ago

Hmm, ok, so this page used to show results using this API call:

https://publiclab.org/wiki/inline-maps

It uses: $.getJSON("/api/srch/taglocations?query="+s , function(data){

image

The call is getting an error, and is: https://publiclab.org/api/srch/taglocations?query=43,-71

As @milaaraujo pointed out, this does work: https://publiclab.org/api/srch/taglocations?query=1.9,9.9

Ah! So the fix I'd added that pads zeroes doesn't work - they get stripped back out because it's not a string. This works: https://publiclab.org/api/srch/taglocations?query=43.0,-71.0

It also works with a tag: https://publiclab.org/api/srch/taglocations?query=29.9,-90.0&tag=mapknitter

I'll fix the padding issue: https://github.com/publiclab/plots2/blob/52ca105d7e89d7640a95110b2c947990bbc5618b/app/views/map/_leaflet.html.erb#L34

What's left is what @milaaraujo and @sagarpreet-chadha pointed out, 2 parts:

  1. get the API query in this code to accept a wildcard, like in this code so we can query question:* via the API
  2. potentially allow setting the bounding box of that API call by two coordinate pairs instead of the more ambiguous "nearby"

Other follow-ups we ought to look into:

  1. get the inline map generator to pass along a tagname to the leaflet template
  2. get the leaflet template to pass the tagname to the API call IF it exists
  3. write a test for the tag-based search API endpoint (i think it doesn't test for this)

This is a lot, but broken into small parts! How does it sound?

jywarren commented 5 years ago

Thanks everyone for untangling this complex web! πŸ•Έ πŸ˜„

jywarren commented 5 years ago

@milaaraujo pointed out some... creative coding (i can probably take credit πŸ˜‚ ) -- the existing code just truncates the last two digits, and matches any node that has those same initial digits. So it can fail easily if you're looking "near" 10.00 but the point you're looking for is at 9.99, even though they're very close! Because 10. and 9. don't match.

However, since we don't actually store the lat/lon in full decimal form, but only as strings, we have to get creative. We could potentially manually detect if we need to expand the search criteria, but that sounds messy. Alternatively we could start storing latitudes and longitudes in tag records, as decimals... @sagarpreet-chadha @milaaraujo what do you think?

milaaraujo commented 5 years ago

@jywarren, I think storing latitudes and longitudes as decimals would be a great improvement! With numbers would be much more easy to control the range of the search.

milaaraujo commented 5 years ago

But first we should work on the points you listed:

1- get the API query in this code to accept a wildcard, like in this code so we can query question:* via the API 2- potentially allow setting the bounding box of that API call by two coordinate pairs instead of the more ambiguous "nearby"

sagarpreet-chadha commented 5 years ago

Awesome πŸ‘ πŸ˜„ !

jywarren commented 5 years ago

OK, @sagarpreet-chadha would you be able to open issues for these two? They could potentially be GCI issues as we have a number of GCI folks who are ready for bigger projects!