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

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

Open crisner opened 4 years ago

crisner commented 4 years ago

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

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

Step 1:

Remove these lines: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L37-L65 https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L374-L382 https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L550

Step 2:

Change this: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L21-L23 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: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L97-L99 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: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L115

Step 5:

Change this: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L285 to: var content = this.generatePopup(data);

and change this: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L289 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: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L332

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: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L353

Step 8:

Change this: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L419 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: https://github.com/publiclab/leaflet-environmental-layers/blob/84da2d162eeeb0662be3c1e3de4c01a38086bf50/src/layercode.js#L423

  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.

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!

neelesh17 commented 4 years ago

Can I try this issue?

crisner commented 4 years ago

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 commented 4 years ago

Okay, Thanks for the advice @crisner .

robin-natale commented 4 years ago

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

crisner commented 4 years ago

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

robin-natale commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 1 year ago

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