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

Get data using bbox and populate popup data for opensense layer #391

Open
5 tasks
crisner opened this issue Feb 8, 2020 · 11 comments · May be fixed by robin-natale/leaflet-environmental-layers#1 or #429
Open
5 tasks

Comments

@crisner
Copy link
Contributor

crisner commented Feb 8, 2020

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

We know that the process of creating a pull request is the biggest barrier for new contributors. This issue is for you 💝

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

🤔 What you will need to know.

Nothing. This issue is meant to welcome you to Open Source :) We are happy to walk you through the process.

📋 Step by Step

  • 🙋 Claim this issue: Comment below. If someone else has claimed it, ask if they've opened a pull request already and if they're stuck -- maybe you can help them solve a problem or move it along!

  • 📝 Update the file layercode.js in the leaflet-environmental-layers repository.

See this page for some help in taking your first steps!

Step 1:

Remove these lines:

populatePopUp: function(e) {
if (this.layer == 'opensense') {
if (e) {
var popup = e.target.getPopup();
var $ = window.jQuery;
var url = 'https://api.opensensemap.org/boxes/' + e.target.options.boxId;
$.getJSON(url, function(data) {
var popUpContent = '';
if (data.name && data.grouptag) {
popUpContent += '<h3>' + data.name + ',' + data.grouptag + '</h3>';
}
else if (data.name) {
popUpContent += '<h3>' + data.name + '</h3>';
}
for (var i in data.sensors) {
if (data.sensors[i].lastMeasurement) {
popUpContent += '<span><b>' + data.sensors[i].title + ': </b>' +
data.sensors[i].lastMeasurement.value +
data.sensors[i].unit + '</span><br>';
}
}
if (data.lastMeasurementAt) {
popUpContent += '<br><small>Measured at <i>' + data.lastMeasurementAt + '</i>';
}
popup.setContent(popUpContent);
});
}
}
},

else {
var marker = this.getMarker(data);
var key = i;
if (!this._layers[key]) {
this._layers[key] = marker;
marker.on('click', this.populatePopUp);
this.addLayer(marker);
}
}

popupAnchor: [1, -34],

Step 2:

Change this:

map.on('moveend', this.requestData, this);
this._map = map;
this.requestData();

to:

this._map = map;
if (this.layer !== 'opensense') {
  this.requestData();
 } else if (this.layer === 'opensense' && this._map && map.getZoom() > 5) {
  this.requestData();
}
map.on('moveend', function() {
   if (this._map && ((this.layer === 'opensense' && this._map.getZoom() > 5) || this.layer !== 'opensense')) {
      this.requestData();
    }
}, this);

Step 3:

Change this:

if (self.layer === 'opensense') {
Layer_URL = 'https://api.opensensemap.org/boxes';
}

to

if (self.layer === 'opensense' && self._map.getZoom() > 5) {
    var bounds = self._map.getBounds();
    Layer_URL = 'https://api.opensensemap.org/boxes?full=true&bbox='+bounds._southWest.lng+','+bounds._southWest.lat+','+bounds._northEast.lng+','+bounds._northEast.lat;
 }

Step 4:

Insert this:

if (self.layer == 'opensense') {
    self.parseData(data);
}

above this line:

if (self.layer == 'openaq')

Step 5:

Change this:

var loadingText = 'Loading ...';

to:
var content = this.generatePopup(data);

and change this:

return marker.bindPopup(loadingText);

to:
return marker.bindPopup(content);

Step 6:

Add these lines:

if (this.layer == 'opensense') {
    var popUpContent = '';
    var noMeasurements = true;
    if (item.name && item.grouptag) {
          popUpContent += '<h4>' + item.name + ',' + item.grouptag + '</h4>';
    }  else if (item.name) {
          popUpContent += '<h4>' + item.name + '</h4>';
    }

   if (item.currentLocation.coordinates) {
          popUpContent += '<span><strong>Latitude:</strong> ' + item.currentLocation.coordinates[1] + '</span><br>' + '<span><strong>Longitude:</strong> ' + item.currentLocation.coordinates[0] + '</span><br>';
   }
        
  for (var i in item.sensors) {
      if (item.sensors[i].lastMeasurement) {
            noMeasurements = false;
            popUpContent += '<span><b>' + item.sensors[i].title + ': </b>' +
              item.sensors[i].lastMeasurement.value +
              item.sensors[i].unit + '</span><br>';
       }
  }

  if (noMeasurements) {
     popUpContent += '<span><b>No measurements available</span><br>';
  }
        
  if (item.lastMeasurementAt) {
      popUpContent += '<br><small>Measured at <i>' + item.lastMeasurementAt + '</i>';
  } else if (item.updatedAt) {
      popUpContent += '<br><small>Updated at <i>' + item.updatedAt + '</i>';
  }
  return popUpContent;
}

right after line 332 in the generatePopup method:

Step 7:

Add the following:

if (this.layer == 'opensense') {
   var marker = this.getMarker(data);
   var key;
   if (marker != null) {
      key = data._id; // ID
      if (!this._layers[key]) {
            this._layers[key] = marker;
            this.addLayer(marker);
      }
   }
}

right after line 353:

Step 8:

Change this:

if (this.layer == 'luftdaten' || this.layer == 'opensense') {

to:
if (this.layer == 'luftdaten') {

and add this:

if (this.layer == 'opensense') {
    for (var i = 0; i < data.length; i++) {
          this.addMarker(data[i]);
    }
}

after line 423:

  • 💾 Commit your changes

  • 🔀 Start a Pull Request. There are two ways how you can start a pull request:

  1. If you are familiar with the terminal or would like to learn it, here is a great tutorial on how to send a pull request using the terminal.

  2. You can also edit files directly in your browser and open a pull request from there.

  • 🏁 Done Ask in comments for a review :)

Please keep us updated

💬⏰ - We encourage contributors to be respectful to the community and provide an update within a week of claiming a first-timers-only issue. We're happy to keep it assigned to you as long as you need if you update us with a request for more time or help, but if we don't see any activity a week after you claim it we may reassign it to give someone else a chance. Thank you in advance!

If this happens to you, don't sweat it! Grab another open issue.

Is someone else already working on this?

🔗- We encourage contributors to link to the original issue in their pull request so all users can easily see if someone's already started on it.

👥- If someone seems stuck, offer them some help! Otherwise, take a look at some other issues you can help with. Thanks!

🤔❓ Questions?

Leave a comment below!

@crisner crisner changed the title Get data from bbox and populate popup data for opensense layer Get data using bbox and populate popup data for opensense layer Feb 8, 2020
@neelesh17
Copy link
Member

neelesh17 commented Feb 11, 2020

Can I try this issue?

@crisner
Copy link
Contributor Author

crisner commented Feb 11, 2020

Thank you @neelesh17! If you have completed a couple of FTO's would you like to try out issues tagged with help-wanted instead?

@neelesh17
Copy link
Member

Okay, Thanks for the advice @crisner .

@robin-natale
Copy link
Contributor

Hey @crisner can I give it a try on this issue too?

@crisner
Copy link
Contributor Author

crisner commented Feb 17, 2020

Sure, go ahead! 😄
As suggested in your previous PR, remember to make your changes in a new branch. Thanks!

@robin-natale
Copy link
Contributor

Hey @crisner i think I tried with a new branch now and then merging this with your master branch. Was it better this way? I welcome any feedback in case of any mistakes 👍

@crisner
Copy link
Contributor Author

crisner commented Feb 18, 2020

@robin-natale, go through the step-by-step procedure in this link https://codeburst.io/a-step-by-step-guide-to-making-your-first-github-contribution-5302260a2940. This will give you an idea of how an open-source contribution should be made. Here's another link: https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github

One thing to always remember, you should never alter or merge unapproved changes into a master branch. Reading the above article should clear up some confusion. Do reach out if you have any questions. 😄 You could also use the gitter chat room to ask for help.

@robin-natale
Copy link
Contributor

robin-natale commented Feb 18, 2020

Many thanks @crisner I will have a look through this documentation and hopefully next time will be fine 👍😄 Did those changes went through at the end or shall I delete everything I have committed so far?

@crisner
Copy link
Contributor Author

crisner commented Feb 18, 2020

You may have to open new PRs from clean branches. You got the changes right though. 😃 Just make sure to do the same on a new branch created from a clean master branch and make the PR from that new branch. :)

robin-natale added a commit to robin-natale/leaflet-environmental-layers that referenced this issue Mar 2, 2020
publiclab#391 Completed (step 2 missing as the code is changed)
@robin-natale
Copy link
Contributor

@crisner I think this time went all well with pulling request from separate branches, would you agree? 👍LEt me know if there are any feedback!!
Also would you mind inviting me again to the Publiclab project? For some reason the last invitation I received is not working.

@PawanAK
Copy link

PawanAK commented Apr 10, 2023

Hey @crisner can I give it a try on this issue?

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