From 9d2994b240c98fec6a158eff0bdbc3c878116e16 Mon Sep 17 00:00:00 2001
From: Robin <43668539+robin-natale@users.noreply.github.com>
Date: Mon, 2 Mar 2020 17:45:40 +0000
Subject: [PATCH 1/2] Add files via upload
---
CONTRIBUTING.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2258e1271..5f26fca2e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,4 +1,4 @@
-Contributing to Leaflet Environmental Layers
+Robin Contributing to Leaflet Environmental Layers
==========================
We welcome community contributions to Leaflet Environmental Layers! For local installation, follow the instructions in the [README.md file](./README.md).
From 4722cb58a1cca89acb0d51a0a0daa934a05b2d93 Mon Sep 17 00:00:00 2001
From: Robin <43668539+robin-natale@users.noreply.github.com>
Date: Mon, 2 Mar 2020 17:53:58 +0000
Subject: [PATCH 2/2] Add files via upload
Step 1 completed
---
layercode.js | 545 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 545 insertions(+)
create mode 100644 layercode.js
diff --git a/layercode.js b/layercode.js
new file mode 100644
index 000000000..b1f64d0f3
--- /dev/null
+++ b/layercode.js
@@ -0,0 +1,545 @@
+require('jquery');
+require('leaflet');
+
+L.LayerGroup.LayerCode = L.LayerGroup.extend(
+
+ {
+ options: {
+ popupOnMouseover: false,
+ clearOutsideBounds: true,
+ target: '_self',
+ },
+
+ initialize: function(name, options) {
+ this.layer = name;
+ options = options || {};
+ L.Util.setOptions(this, options);
+ this._layers = {};
+ },
+
+ onAdd: function(map) {
+ var info = require('./info.json');
+ this._map = map;
+ switch(this.layer) {
+ case this.layer:
+ if (this.layer === 'fractracker' || this.layer === 'skytruth' ||
+ this.layer === 'odorreport' || this.layer === 'mapknitter') {
+ map.on('moveend', function() {
+ if(this._map && this._map.getZoom() > info[this.layer].extents.minZoom - 1) {
+ this.requestData();
+ }
+ }, this);
+ }
+ default:
+ if (this.layer === 'luftdaten' || this.layer === 'openaq' ||
+ this.layer === 'opensense' || this.layer === 'purpleairmarker') {
+ map.on('moveend', this.requestData, this);
+ }
+ this.requestData();
+ }
+ },
+
+ onRemove: function(map) {
+ map.off('moveend', this.requestData, this);
+ if (typeof map.spin === 'function') {
+ map.spin(false);
+ }
+ this.clearLayers();
+ map.closePopup();
+ // oms.clearMarkers();
+ this._layers = {};
+ },
+
+
+ requestData: function() {
+ var self = this;
+ var info = require('./info.json');
+ (function() {
+ var zoom;
+ var Layer_URL;
+ var $ = window.jQuery;
+
+ if (self.layer === 'fractracker') {
+ Layer_URL = info.fractracker.api_url; ;
+ }
+ if (self.layer === 'skytruth') {
+ zoom = self._map.getZoom(), northeast = self._map.getBounds().getNorthEast(), southwest = self._map.getBounds().getSouthWest();
+ Layer_URL = info.skytruth.api_url + '?n=100&l='+(southwest.lat)+','+(southwest.lng)+','+(northeast.lat)+','+(northeast.lng);
+ }
+ if (self.layer === 'odorreport') {
+ zoom = self._map.getZoom(), origin = self._map.getCenter();
+ Layer_URL = info.odorreport.api_url;
+ }
+ if (self.layer === 'mapknitter') {
+ zoom = self._map.getZoom(), northeast = self._map.getBounds().getNorthEast(), southwest = self._map.getBounds().getSouthWest();
+ Layer_URL = info.mapknitter.api_url + '?minlon='+(southwest.lng)+'&minlat='+(southwest.lat)+'&maxlon='+(northeast.lng)+'&maxlat='+(northeast.lat);
+ }
+ if (self.layer === 'luftdaten') {
+ Layer_URL = 'https://maps.luftdaten.info/data/v2/data.dust.min.json';
+ }
+ if (self.layer === 'openaq') {
+ Layer_URL = 'https://api.openaq.org/v1/latest?limit=5000';
+ }
+ if (self.layer === 'opensense') {
+ Layer_URL = 'https://api.opensensemap.org/boxes';
+ }
+ if (self.layer == 'purpleairmarker') {
+ zoom = self._map.getZoom(), northwest = self._map.getBounds().getNorthWest(), southeast = self._map.getBounds().getSouthEast();
+ if (zoom < info.purpleair.layers.purpleairmarker.extents.minZoom) {
+ return;
+ }
+ Layer_URL = info.purpleair.api_url + '?fetchData=true&minimize=true&sensorsActive2=10080&orderby=L&nwlat='+(northwest.lat)+'&selat='+(southeast.lat)+'&nwlng='+(northwest.lng)+'&selng='+(southeast.lng);
+ }
+
+
+ if (self._map && typeof self._map.spin === 'function') {
+ self._map.spin(true);
+ }
+ $.getJSON(Layer_URL, function(data) {
+ if (self.layer == 'fractracker')
+ { self.parseData(data.feed.entry); }
+ if (self.layer == 'openaq')
+ { self.parseData(data.results); }
+ else
+ { self.parseData(data); }
+ if (self._map && typeof self._map.spin === 'function') {
+ self._map.spin(false);
+ }
+ });
+ })();
+ },
+
+ getMarker: function(data) {
+ if (this.layer == 'fractracker') {
+ var redDotIcon = new L.icon.fracTrackerIcon();
+ var props = ['timestamp', 'name', 'summary', 'website', 'contact', 'email', 'phone', 'streetaddress', 'city', 'state', 'zipcode', 'latitude', 'longitude', 'category'];
+ var item = {};
+ props.forEach(function(element) {
+ item[element] = data['gsx$' + element]['$t'];
+ });
+ item['updated'] = data.updated.$t;
+ item['use'] = (data.gsx$useformap.$t.replace(/\s+/g, '').toLowerCase() === 'use');
+ item['latitude'] = item['latitude'].replace(/[^\d.-]/g, '');
+ item['latitude'] = item['latitude'].replace(/[^\d.-]/g, '');
+ var defaultMarker = L.marker([item['latitude'], item['longitude']], {
+ icon: redDotIcon,
+ });
+ var minimalMarker = L.circleMarker(L.latLng([item['latitude'], item['longitude']]), { radius: 5, weight: 1, fillOpacity: 1, color: '#7c7c7c', fillColor: '#e8e800' });
+ var content = this.generatePopup(item);
+ var fracTracker;
+ fracTracker = this._map && this._map._minimalMode ? minimalMarker : defaultMarker;
+ return fracTracker.bindPopup(content);
+ }
+
+ if (this.layer == 'skytruth') {
+ var redDotIcon =new L.icon.skyTruthIcon();
+ var lat = data.lat;
+ var lng = data.lng;
+ var title = data.title;
+ var url = data.link;
+ var defaultMarker = L.marker([lat, lng], {icon: redDotIcon});
+ var minimalMarker = L.circleMarker(L.latLng([lat, lng]), { radius: 5, weight: 1, fillOpacity: 1, color: '#7c7c7c', fillColor: '#f00' });
+ var content = '' +title + '
' +
+ '
lat: ' + lat +
+ '
lon: ' + lng +
+ '
Data provided by alerts.skytruth.org/';
+ var skymarker;
+ if (!isNaN(lat) && !isNaN(lng) ) {
+ skymarker = this._map && this._map._minimalMode ? minimalMarker.bindPopup(content) : defaultMarker.bindPopup(content);
+ }
+ return skymarker;
+ }
+
+ if (this.layer == 'odorreport') {
+ var redDotIcon =new L.icon.odorReportIcon();
+ var lat = data.values['bcc29002-c4d3-4c2c-92c7-1c9032c3b0fd'][0].lat;
+ var lng = data.values['bcc29002-c4d3-4c2c-92c7-1c9032c3b0fd'][0].lon;
+ var title = data.title;
+ var url = data.url;
+ var defaultMarker = L.marker([lat, lng], {icon: redDotIcon});
+ var minimalMarker = L.circleMarker(L.latLng([lat, lng]), { radius: 5, weight: 1, fillOpacity: 1, color: '#7c7c7c', fillColor: '#ff00ff' });
+ var content = title +
+ '
' + url +'' +
+ '
lat: ' + lat +
+ '
lon: ' + lng +
+ '
Data provided by https://odorlog.ushahidi.io';
+ var odormarker;
+ if (!isNaN(lat) && !isNaN(lng) ) {
+ odormarker = this._map && this._map._minimalMode ? minimalMarker.bindPopup(content) : defaultMarker.bindPopup(content);
+ }
+ // oms.addMarker(odormarker);
+ return odormarker;
+ }
+
+ if (this.layer == 'mapknitter') {
+ var redDotIcon =new L.icon.mapKnitterIcon();
+ var lat = data.lat;
+ var lng = data.lon;
+ var title = data.name;
+ var location = data.location;
+ var author = data.author;
+ var url = 'https://publiclab.org/profile/' + author;
+ var map_page = 'https://mapknitter.org/maps/'+ title;
+ var image_url;
+ if (data.image_urls.length > 0) {
+ image_url = data.image_urls[0];
+ }
+ var defaultMarker = L.marker([lat, lng], {icon: redDotIcon});
+ var minimalMarker = L.circleMarker(L.latLng([lat, lng]), { radius: 5, weight: 1, fillOpacity: 1, color: '#7c7c7c', fillColor: '#ca283b' });
+ var content = 'Title : '+ '' + title + '' +
+ '
Author : ' + '' + author +'' +
+ '
Location : ' + location +
+ '
Lat : ' + lat + ' , Lon : ' + lng +
+ '
'+
+ '
For more info on MapKnitter Layer, visit here';
+ var mapknitter;
+ if (!isNaN(lat) && !isNaN(lng) ) {
+ if (image_url !== undefined) {
+ mapknitter = this._map && this._map._minimalMode ? minimalMarker.bindPopup(content) : defaultMarker.bindPopup(content);
+ // oms.addMarker(mapknitter);
+ }
+ else {
+ content = 'Title : '+ '' + title + '' +
+ '
Author : ' + '' + author +'' +
+ '
Location : ' + location +
+ '
Lat : ' + lat + ' , Lon : ' + lng +
+ '
For more info on MapKnitter Layer, visit here';
+ mapknitter = this._map && this._map._minimalMode ? minimalMarker.bindPopup(content) : defaultMarker.bindPopup(content);
+ // oms.addMarker(mapknitter);
+ }
+ }
+ return mapknitter;
+ }
+
+ if (this.layer == 'luftdaten')
+ {
+ var greenIcon = new L.icon.luftdatenIcon();
+ var country = data.location.country;
+ var lng = data.location.longitude;
+ var lat = data.location.latitude;
+ var sensorID = data.sensor.id;
+ var popupContent = '';
+ if (country) {
+ popupContent += '