Skip to content

Commit

Permalink
add opensensemap layer (#142)
Browse files Browse the repository at this point in the history
A new layer has been added that gets data from opensensemap.org.

fixes #58
  • Loading branch information
rkpattnaik780 authored and jywarren committed Mar 19, 2019
1 parent 3af6591 commit 44fd6e0
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 19 deletions.
175 changes: 157 additions & 18 deletions dist/LeafletEnvironmentalLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26316,6 +26316,144 @@ L.layerGroup.aqicnLayer = function(options) {
}

},{}],11:[function(require,module,exports){

L.Icon.OpenSenseIcon = L.Icon.extend({
options: {
iconUrl: 'https://banner2.kisspng.com/20180409/qcw/kisspng-computer-icons-font-awesome-computer-software-user-cubes-5acb63cb589078.9265215315232787953628.jpg',
iconSize: [10,10],
popupAnchor: [1, -34]
}
});

L.icon.openSenseIcon = function () {
return new L.Icon.OpenSenseIcon();
};

L.LayerGroup.OpenSenseLayer = L.LayerGroup.extend({

options: {
popupOnMouseover: true,
clearOutsideBounds: true
},

initialize: function (options) {
options = options || {};
L.Util.setOptions(this, options);
this._layers = {};
},

onAdd: function (map) {
this._map = map;
this.requestRegionData();
},

onRemove: function (map) {
this.clearLayers();
this._layers = {};
},

populatePopUp: function(e){
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)
});
}
},

requestRegionData: function () {
var self = this;

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

if (typeof self._map.spin === 'function') {
self._map.spin(true);
}
$.getJSON(url, function (records) {
self.parseData(records);
if (typeof self._map.spin === 'function') {
self._map.spin(false);
}
});

})();
},

getMarker: function (data) {

var blackCube = new L.icon.openSenseIcon();

var lat = data.currentLocation.coordinates[1];
var lng = data.currentLocation.coordinates[0];

var loadingText = "Loading ...";

return L.marker([lat,lng], { icon: blackCube , boxId : data._id }).bindPopup(loadingText);

},

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

parseData: function (data) {
for (var i = 0; i < data.length; i++) {
this.addMarker(data[i],i);
}
},

clearOutsideBounds: function () {
var bounds = this._map.getBounds(),
latLng,
key;

for (key in this._layers) {
if (this._layers.hasOwnProperty(key)) {
latLng = this._layers[key].getLatLng();

if (!bounds.contains(latLng)) {
this.removeLayer(this._layers[key]);
delete this._layers[key];
}
}
}

}

});

L.layerGroup.openSenseLayer = function (options) {
return new L.LayerGroup.OpenSenseLayer(options);
}

},{}],12:[function(require,module,exports){
fracTrackerMobileLayer = function(map) {
var FracTracker_mobile = L.esri.featureLayer({
url: 'https://services.arcgis.com/jDGuO8tYggdCCnUJ/arcgis/rest/services/FracTrackerMobileAppNPCAMesaVerdeNationalPark_051416/FeatureServer/0/',
Expand All @@ -26340,7 +26478,7 @@ fracTrackerMobileLayer = function(map) {
return FracTracker_mobile ;
}

},{}],12:[function(require,module,exports){
},{}],13:[function(require,module,exports){
L.Icon.FracTrackerIcon = L.Icon.extend({
options: {
iconUrl: 'https://www.clker.com/cliparts/2/3/f/a/11970909781608045989gramzon_Barrel.svg.med.png',
Expand Down Expand Up @@ -26474,7 +26612,7 @@ L.layerGroup.fracTrackerLayer = function (options) {
return new L.LayerGroup.FracTrackerLayer(options) ;
};

},{}],13:[function(require,module,exports){
},{}],14:[function(require,module,exports){
L.LayerGroup.IndigenousLandsLanguagesLayer = L.LayerGroup.extend(

{
Expand Down Expand Up @@ -26635,7 +26773,7 @@ L.layerGroup.indigenousLandsLanguagesLayer = function (options) {
return new L.LayerGroup.IndigenousLandsLanguagesLayer(options);
};

},{}],14:[function(require,module,exports){
},{}],15:[function(require,module,exports){
L.LayerGroup.IndigenousLandsTerritoriesLayer = L.LayerGroup.extend(

{
Expand Down Expand Up @@ -26796,7 +26934,7 @@ L.layerGroup.indigenousLandsTerritoriesLayer = function (options) {
return new L.LayerGroup.IndigenousLandsTerritoriesLayer(options);
};

},{}],15:[function(require,module,exports){
},{}],16:[function(require,module,exports){
L.LayerGroup.IndigenousLandsTreatiesLayer = L.LayerGroup.extend(

{
Expand Down Expand Up @@ -26956,7 +27094,7 @@ L.layerGroup.indigenousLandsTreatiesLayer = function (options) {
return new L.LayerGroup.IndigenousLandsTreatiesLayer(options);
};

},{}],16:[function(require,module,exports){
},{}],17:[function(require,module,exports){
require('jquery') ;
require('leaflet') ;

Expand All @@ -26975,11 +27113,12 @@ require('./indigenousLandsTreatiesLayer.js') ;
require('./aqicnLayer.js');
require('./openaqLayer.js');
require('./luftdatenLayer.js')
require('./openSenseLayer.js');
require('./osmLandfillMineQuarryLayer.js');
require('./wisconsinLayer.js');
require('./fracTrackerMobileLayer.js');

},{"./aqicnLayer.js":8,"./openaqLayer.js":9,"./luftdatenLayer.js":10,"./fracTrackerMobileLayer.js":11,"./fractracker.js":12,"./indigenousLandsLanguagesLayer.js":13,"./indigenousLandsTerritoriesLayer.js":14,"./indigenousLandsTreatiesLayer.js":15,"./mapKnitterLayer.js":17,"./odorReportLayer.js":18,"./openWeatherMapLayer.js":19,"./osmLandfillMineQuarryLayer.js":20,"./purpleAirMarkerLayer.js":21,"./purpleLayer.js":22,"./skyTruthLayer.js":23,"./toxicReleaseLayer.js":24,"./wisconsinLayer.js":28,"jquery":2,"leaflet":6,"leaflet-providers":5}],17:[function(require,module,exports){
},{"./aqicnLayer.js":8,"./openaqLayer.js":9,"./luftdatenLayer.js":10,"./openSenseLayer.js":11,"./fracTrackerMobileLayer.js":12,"./fractracker.js":13,"./indigenousLandsLanguagesLayer.js":14,"./indigenousLandsTerritoriesLayer.js":15,"./indigenousLandsTreatiesLayer.js":16,"./mapKnitterLayer.js":18,"./odorReportLayer.js":19,"./openWeatherMapLayer.js":20,"./osmLandfillMineQuarryLayer.js":21,"./purpleAirMarkerLayer.js":22,"./purpleLayer.js":23,"./skyTruthLayer.js":24,"./toxicReleaseLayer.js":25,"./wisconsinLayer.js":29,"jquery":2,"leaflet":6,"leaflet-providers":5}],18:[function(require,module,exports){
L.Icon.MapKnitterIcon = L.Icon.extend({
options: {
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
Expand Down Expand Up @@ -27118,7 +27257,7 @@ L.layerGroup.mapKnitterLayer = function (options) {
return new L.LayerGroup.MapKnitterLayer(options) ;
};

},{}],18:[function(require,module,exports){
},{}],19:[function(require,module,exports){
L.Icon.OdorReportIcon = L.Icon.extend({
options: {
iconUrl: 'https://www.clker.com/cliparts/T/3/6/T/S/8/ink-splash-md.png',
Expand Down Expand Up @@ -27251,7 +27390,7 @@ L.layerGroup.odorReportLayer = function (options) {
return new L.LayerGroup.OdorReportLayer(options);
};

},{}],19:[function(require,module,exports){
},{}],20:[function(require,module,exports){
L.OWM = L.TileLayer.extend({
options: {
appId: '4c6704566155a7d0d5d2f107c5156d6e', /* pass your own AppId as parameter when creating the layer. Get your own AppId at https://www.openweathermap.org/appid */
Expand Down Expand Up @@ -28827,7 +28966,7 @@ L.OWM.Utils = {



},{}],20:[function(require,module,exports){
},{}],21:[function(require,module,exports){
L.LayerGroup.OSMLandfillMineQuarryLayer = L.LayerGroup.extend(

{
Expand Down Expand Up @@ -29020,7 +29159,7 @@ L.layerGroup.osmLandfillMineQuarryLayer = function(options) {
return new L.LayerGroup.OSMLandfillMineQuarryLayer(options);
};

},{}],21:[function(require,module,exports){
},{}],22:[function(require,module,exports){
require('jquery') ;
require('leaflet') ;

Expand Down Expand Up @@ -29136,7 +29275,7 @@ L.layerGroup.purpleAirMarkerLayer = function (options) {
return new L.LayerGroup.PurpleAirMarkerLayer(options) ;
};

},{"jquery":2,"leaflet":6}],22:[function(require,module,exports){
},{"jquery":2,"leaflet":6}],23:[function(require,module,exports){
require('heatmap.js') ;
require('leaflet-heatmap') ;

Expand Down Expand Up @@ -29266,7 +29405,7 @@ L.layerGroup.purpleLayer = function (options) {
return new L.LayerGroup.PurpleLayer(options) ;
};

},{"heatmap.js":1,"leaflet-heatmap":4}],23:[function(require,module,exports){
},{"heatmap.js":1,"leaflet-heatmap":4}],24:[function(require,module,exports){
L.Icon.SkyTruthIcon = L.Icon.extend({
options: {
iconUrl: 'https://www.clker.com/cliparts/T/G/b/7/r/A/red-dot.svg',
Expand Down Expand Up @@ -29379,7 +29518,7 @@ L.layerGroup.skyTruthLayer = function (options) {
return new L.LayerGroup.SkyTruthLayer(options);
};

},{}],24:[function(require,module,exports){
},{}],25:[function(require,module,exports){
L.Icon.ToxicReleaseIcon = L.Icon.extend({
options: {
iconUrl: 'https://www.clker.com/cliparts/r/M/L/o/R/i/green-dot.svg',
Expand Down Expand Up @@ -29519,7 +29658,7 @@ L.layerGroup.toxicReleaseLayer = function (options) {
return new L.LayerGroup.ToxicReleaseLayer(options);
};

},{}],25:[function(require,module,exports){
},{}],26:[function(require,module,exports){
L.Control.Layers.include({
getActiveOverlayNames: function() {

Expand All @@ -29536,7 +29675,7 @@ L.Control.Layers.include({
return layers;
}
});
},{}],26:[function(require,module,exports){
},{}],27:[function(require,module,exports){
L.SpreadsheetLayer = L.LayerGroup.extend({
//options: {
//Must be supplied:
Expand Down Expand Up @@ -29702,7 +29841,7 @@ L.SpreadsheetLayer = L.LayerGroup.extend({
L.spreadsheetLayer = function(options) {
return new L.SpreadsheetLayer(options);
};
},{}],27:[function(require,module,exports){
},{}],28:[function(require,module,exports){
L.Control.LegendControl = L.Control.extend({
options: {
position: 'bottomleft',
Expand Down Expand Up @@ -29761,7 +29900,7 @@ L.control.legendControl = function(options) {
return new L.Control.LegendControl(options);
}

},{}],28:[function(require,module,exports){
},{}],29:[function(require,module,exports){
wisconsinLayer = function (map) {
var Wisconsin_NM = L.esri.featureLayer({
url: 'https://services.arcgis.com/jDGuO8tYggdCCnUJ/arcgis/rest/services/Nonmetallic_and_Potential_frac_sand_mine_proposals_in_West_Central_Wisconsin/FeatureServer/0/',
Expand Down Expand Up @@ -29789,4 +29928,4 @@ wisconsinLayer = function (map) {
return Wisconsin_NM ;
};

},{}]},{},[3,7,16,25,26,27]);
},{}]},{},[3,7,17,26,27,28]);
3 changes: 3 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
var AQICNLayer = L.layerGroup.aqicnLayer();
var OpenAqLayer = L.layerGroup.openaqLayer();
var LuftdatenLayer = L.layerGroup.luftdatenLayer();
var OpenSenseLayer = L.layerGroup.openSenseLayer();

var city = L.OWM.current({intervall: 15, minZoom: 3});
var windrose = L.OWM.current({intervall: 15, minZoom: 3, markerFunction: myWindroseMarker, popup: false, clusterSize: 50,imageLoadingBgUrl: 'https://openweathermap.org/img/w0/iwind.png' });
Expand Down Expand Up @@ -199,6 +200,7 @@
"<span style='color: black'><strong>Air Quality Index</strong></span>": AQICNLayer,
"<span style='color: black'><strong>Open AQ </strong></span>": OpenAqLayer,
"<span style='color: black'><strong>Luftdaten Layer </strong></span>": LuftdatenLayer,
"<img src='https://banner2.kisspng.com/20180409/qcw/kisspng-computer-icons-font-awesome-computer-software-user-cubes-5acb63cb589078.9265215315232787953628.jpg' height='10px' width='10px'><span style='color: black'><strong> OpenSense </strong></span>": OpenSenseLayer,
"<strong>OSM <span style='color: red'>Landfills</span>, <span style='color: blue'>Mines</span>, <span style='color: green'>Quarries</span></strong>": OSMLandfillMineQuarryLayer

};
Expand Down Expand Up @@ -249,6 +251,7 @@
"AQI": AQICNLayer,
"OpenAq":OpenAqLayer,
"Luftaden" : LuftdatenLayer,
"Opensense" : OpenSenseLayer,
"LSM": OSMLandfillMineQuarryLayer
};
var hash = new L.Hash(map, allMapLayers);
Expand Down
3 changes: 2 additions & 1 deletion src/leafletEnvironmentalLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ require('./openaqLayer.js');
require('./osmLandfillMineQuarryLayer.js');
require('./wisconsinLayer.js');
require('./fracTrackerMobileLayer.js');
require('./luftdatenLayer.js');
require('./luftdatenLayer.js');
require('./openSenseLayer.js');
Loading

0 comments on commit 44fd6e0

Please sign in to comment.