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

add opensensemap layer #142

Merged
merged 1 commit into from
Mar 19, 2019
Merged

Conversation

rkpattnaik780
Copy link
Collaborator

A new layer has been added that gets data from opensensemap.org.

image

fixes #58

A new layer has been added that gets data from opensensemap.org.

fixes publiclab#58

(function () {
var $ = window.jQuery;
var url = "https://api.opensensemap.org/boxes";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! This looks great, just a small question --

Are we requesting only one region's worth of data at a time, and how are we submitting the lat/lon coordinates? Thanks!!

Also, this PR would make a great example for #136 -- thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jywarren . I implemented the layer in this manner owing to the api of opensensemap. The current implementation has used two endpoints of the api :-

  • /boxes - Gets data of all the boxes.
  • /boxes/:boxId - Gets data of a particular box.

Looking at the previously implemented layers, hitting the /boxes endpoint seemed sufficient to create the markers and their popups, but the problem was that it didn't return the values recorded by the sensors. So /boxes/:boxId had to be hit to get the values.

So whenever an user opens the Opensense layer, the /boxes endpoint is first hit which provides the coordinates and the boxID, using which the markers are created. Whenever a marker is clicked, the popup is populated at that point only by making a get request to boxes/:boxId that returns the values recorded by the sensors for that particular region. That is why we can see a loading text before the data is loaded.

Please let me know if it requires changes. Thanks :)

@jywarren
Copy link
Member

jywarren commented Mar 11, 2019 via email

@rkpattnaik780
Copy link
Collaborator Author

@jywarren a box is short for a sensebox as defined by the opensensemap API. A sensebox is a group of sensors at a particular location. Each box object returned by /boxes comes with its coordinates and a unique boxId. The current implementation stores this boxId to be used later for hitting the /boxes/:boxId route, which returns finer details of the box with that boxId. I would like to summarize my answers : -

  1. A box is a collection of sensors at a particular location each having a list of sensors, a unique id and lat/lng coordinates.
  2. We don't generate a boxId, we get it as a key of the box objects returned on hitting the /boxes route.
  3. Yeah, each box maps to a lat/lng coordinate.

I hope this answers all the queries. Please let me know if anything is still unclear. Thanks :).

@jywarren
Copy link
Member

OK, thanks! Does the code request all boxes, or are we restricting to only request boxes for the currently viewed region (and if so, could you point me at that section of code?) Thank you!

@rkpattnaik780
Copy link
Collaborator Author

@jywarren The code requests all the boxes when we select the layer. It had to be done cause there is no API endpoint that can fetch the boxes region-wise.
The code that gets all the boxes is in the file dist/LeafletEnvironmentalLayers.js at line no. 26393.
I hope this answers your question, thanks :).

@jywarren jywarren merged commit 44fd6e0 into publiclab:master Mar 19, 2019
@jywarren
Copy link
Member

Great, thank you so much!!!! 👍 We'd love some help with some of the organizational issues in #134 if you're interested!

@rkpattnaik780
Copy link
Collaborator Author

@jywarren thank you :). I will be working on it soon.

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

Successfully merging this pull request may close these issues.

Add layer: opensensemap.org
2 participants