Map of active fires

This commit is contained in:
vjrj 2017-12-01 13:33:24 +01:00
parent f87cf02c2d
commit 0b4f895506
7 changed files with 430 additions and 61 deletions

View file

@ -0,0 +1,65 @@
/* eslint-disable consistent-return */
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const ActiveFires = new Mongo.Collection('activefires');
ActiveFires.allow({
insert: () => false,
update: () => false,
remove: () => false,
});
ActiveFires.deny({
insert: () => true,
update: () => true,
remove: () => true,
});
/* Sample:
* {
* "_id" : ObjectId("5a208d7579095a1adba48191"),
* "ourid" : {
* "type" : "Point",
* "coordinates" : [
* -42.84192,
* -25.54453
* ]
* },
* "lat" : 9.743,
* "lon" : -63.483,
* "updatedAt" : ISODate("2017-11-30T22:02:39.644Z"),
* "type" : "viirs",
* "when" : ISODate("2017-11-30T05:30:00Z"),
* "acq_date" : "2017-11-30",
* "acq_time" : "04:12",
* "scan" : 0.5,
* "track" : 0.4,
* "satellite" : "N",
* "confidence" : "nominal",
* "version" : "1.0NRT",
* "frp" : 4.3,
* "daynight" : "N",
* "bright_ti4" : 330.2,
* "bright_ti5" : 291,
* "createdAt" : ISODate("2017-11-30T08:07:33.720Z")
* }
* */
ActiveFires.schema = new SimpleSchema({
lat: SimpleSchema.Integer,
lon: SimpleSchema.Integer,
scan: Number,
type: String,
acq_date: String,
acq_time: String,
when: Date,
createdAt: Date,
updatedAt: Date
}
);
ActiveFires.attachSchema(ActiveFires.schema);
export default ActiveFires;

View file

@ -0,0 +1,74 @@
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import ActiveFires from '../ActiveFires';
Meteor.publish('activefires', function activefires() {
return ActiveFires.find();
});
const validZoom = Match.Where((zoom) => {
// http://wiki.openstreetmap.org/wiki/Zoom_levels
check(zoom, Number);
return zoom >= 0 && zoom <= 19;
});
// https://github.com/3stack-software/meteor-match-library
var NumberBetween = function (min, max) {
return Match.Where(function (x) {
check(x, Number);
return min <= x && x <= max;
});
};
var NullOr = function (type) {
return Match.Where(function (x) {
if (x === null) {
return true;
}
check(x, type);
return true;
});
};
const zoomMetersPerPixel = [156412, 78206, 39103, 19551, 9776, 4888, 2444, 1222, 610.984, 305.492, 152.746, 76.373, 38.187, 19.093, 9.547, 4.773, 2.387, 1.193, 0.596, 0.298];
var activefires = function(zoom, lat, lng) {
// latitude -90 and 90 and the longitude between -180 and 180
check(lat, NumberBetween(-90, 90));
check(lng, NumberBetween(-180, 180));
// console.log("Zoom: " + zoom + " lat: " + lat + " lng: " + lng);
// console.log("Meters per pixel: " + zoomMetersPerPixel[zoom]);
// console.log(geoData);
return ActiveFires.find({
ourid: {
$near : {
$geometry: {
type: "Point",
coordinates: [ lng, lat]
},
$minDistance: 0,
$maxDistance: zoomMetersPerPixel[zoom] * 1000
}
}
});
}
Meteor.publish('activefiresmyloc', function(zoom, lat, lng) {
check(zoom, validZoom);
check(lat, NullOr(Number));
check(lng, NullOr(Number));
if (lat === null || lng === null) {
var clientIP = this.connection.clientAddress;
if (clientIP === '127.0.0.1') {
clientIP = '80.58.61.250' // Some Spain IP address
}
var geoData = IPGeocoder.geocode(clientIP);
var location = geoData.location;
lat = location.latitude;
lng = location.longitude;
}
return activefires(zoom, lat, lng);
});