More work with unify, circle/square
This commit is contained in:
parent
c4b2f8cd73
commit
a208eb7ea1
6 changed files with 182 additions and 58 deletions
|
|
@ -17,20 +17,24 @@ Meteor.publish('falsePositivesTotal', function total() {
|
|||
});
|
||||
|
||||
export const firesUnion = (fires) => {
|
||||
const group = new L.FeatureGroup();
|
||||
const firesArray = Array.isArray(fires) ? fires : fires.fetch(); // if not is a cursor
|
||||
const remap = firesArray.map(function remap(doc) {
|
||||
// default scan: 1 for neightbor alerts
|
||||
return { location: { lat: doc.lat, lon: doc.lon }, distance: doc.scan || 1 };
|
||||
const isNASA = doc.type === 'modis' || doc.type === 'viirs';
|
||||
const pixelSize = doc.type === 'viirs' ? 0.375 : 1; // viirs has 375m pixel size, modis 1000m
|
||||
// default 1 km for neightbor alerts
|
||||
return {
|
||||
location: { lat: doc.lat, lon: doc.lon },
|
||||
distance: isNASA ? doc.scan * pixelSize : 1,
|
||||
distanceY: isNASA ? doc.track * pixelSize : 1
|
||||
};
|
||||
});
|
||||
const union = calcUnion(remap, group, sub => sub);
|
||||
const union = calcUnion(L, remap, sub => sub, false);
|
||||
return union;
|
||||
};
|
||||
|
||||
export const zoneToUnion = (lat, lon, distance) => {
|
||||
const group = new L.FeatureGroup();
|
||||
const remap = [{ location: { lat, lon }, distance }];
|
||||
const union = calcUnion(remap, group, sub => sub);
|
||||
const union = calcUnion(L, remap, sub => sub, true);
|
||||
return union;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,8 @@ Meteor.startup(() => {
|
|||
const noNoisy = sub => sub;
|
||||
|
||||
const process = (isPublic) => {
|
||||
const group = new L.FeatureGroup();
|
||||
const subscribers = Subscriptions.find().fetch();
|
||||
const result = calcUnion(subscribers, group, isPublic ? addNoisy : noNoisy);
|
||||
const result = calcUnion(L, subscribers, isPublic ? addNoisy : noNoisy, true);
|
||||
const union = result[0];
|
||||
const bounds = result[1];
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ const subsUnion = (union, options) => {
|
|||
options.map.leafletElement.fitBounds(L.latLngBounds(bounds._northEast, bounds._southWest));
|
||||
}
|
||||
} else if (options.subs.length > 0) {
|
||||
const unionGroup = new L.FeatureGroup();
|
||||
const result = calcUnion(options.subs, unionGroup, sub => sub);
|
||||
const result = calcUnion(L, options.subs, sub => sub, true);
|
||||
const unionJson = result[0];
|
||||
const bounds = result[1];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
import { check } from 'meteor/check';
|
||||
import LGeo from 'leaflet-geodesy';
|
||||
import tunion from '@turf/union';
|
||||
import ttrunc from '@turf/truncate';
|
||||
import { rectangleAround } from 'map-common-utils';
|
||||
import tcircle from '@turf/circle';
|
||||
|
||||
// https://stackoverflow.com/questions/35394577/leaflet-js-union-merge-circles
|
||||
// https://stackoverflow.com/questions/35394577/leaflet-js-union-merge-circles
|
||||
const truncOptions = { precision: 6, coordinates: 2 };
|
||||
|
||||
const unify = (polyList) => {
|
||||
let unionTemp;
|
||||
for (let i = 0; i < polyList.length; i += 1) {
|
||||
const pol = polyList[i].toGeoJSON();
|
||||
const pol = polyList[i];
|
||||
const cleanPol = ttrunc(pol, truncOptions);
|
||||
if (i === 0) {
|
||||
unionTemp = cleanPol;
|
||||
|
|
@ -20,11 +21,9 @@ const unify = (polyList) => {
|
|||
return unionTemp;
|
||||
};
|
||||
|
||||
const calcUnion = (subs, group, decorated) => {
|
||||
const unionGroup = group;
|
||||
const copts = {
|
||||
parts: 144
|
||||
};
|
||||
const calcUnion = (L, subs, decorated, typeCircle) => {
|
||||
const unionGroup = [];
|
||||
const doCircle = (typeof typeCircle !== 'undefined') ? typeCircle : true;
|
||||
subs.forEach((osub) => {
|
||||
try {
|
||||
if (osub.location && osub.location.lat && osub.location.lon && osub.distance) {
|
||||
|
|
@ -32,17 +31,26 @@ const calcUnion = (subs, group, decorated) => {
|
|||
check(osub.location.lat, Number);
|
||||
check(osub.distance, Number);
|
||||
const dsub = decorated(osub);
|
||||
const circle = LGeo.circle([dsub.location.lat, dsub.location.lon], dsub.distance * 1000, copts);
|
||||
circle.addTo(unionGroup);
|
||||
const jsonPolygon = doCircle ?
|
||||
tcircle(
|
||||
[dsub.location.lon, dsub.location.lat], dsub.distance,
|
||||
{ units: 'kilometers', steps: 144 }
|
||||
) :
|
||||
rectangleAround(
|
||||
{ lon: dsub.location.lon, lat: dsub.location.lat },
|
||||
dsub.distance,
|
||||
(typeof dsub.distanceY !== 'undefined') ? dsub.distanceY : dsub.distance
|
||||
);
|
||||
unionGroup.push(jsonPolygon);
|
||||
} else {
|
||||
console.info(`Wrong subscription ${JSON.stringify(osub)}`);
|
||||
console.info(`Wrong element to do union ${JSON.stringify(osub)}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e, `Wrong subscription trying to make union ${JSON.stringify(osub)}`);
|
||||
console.error(e, `Wrong element trying to make union ${JSON.stringify(osub)}`);
|
||||
}
|
||||
});
|
||||
const unionJson = unify(unionGroup.getLayers());
|
||||
return [unionJson, unionGroup.getBounds()];
|
||||
const unionJson = unify(unionGroup);
|
||||
return [unionJson, L.geoJSON(unionJson).getBounds()];
|
||||
};
|
||||
|
||||
export default calcUnion;
|
||||
|
|
|
|||
179
package-lock.json
generated
179
package-lock.json
generated
|
|
@ -37,12 +37,30 @@
|
|||
}
|
||||
},
|
||||
"@turf/bbox": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-5.1.5.tgz",
|
||||
"integrity": "sha1-MFHfUUrUxQ9KT5uKLRX9i2hA7aM=",
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-6.0.1.tgz",
|
||||
"integrity": "sha512-EGgaRLettBG25Iyx7VyUINsPpVj1x3nFQFiGS3ER8KCI1MximzNLsam3eXRabqQDjyAKyAE1bJ4EZEpGvspQxw==",
|
||||
"requires": {
|
||||
"@turf/helpers": "5.1.5",
|
||||
"@turf/meta": "5.2.0"
|
||||
"@turf/helpers": "6.1.4",
|
||||
"@turf/meta": "6.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/meta": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@turf/meta/-/meta-6.0.2.tgz",
|
||||
"integrity": "sha512-VA7HJkx7qF1l3+GNGkDVn2oXy4+QoLP6LktXAaZKjuT1JI0YESat7quUkbCMy4zP9lAUuvS4YMslLyTtr919FA==",
|
||||
"requires": {
|
||||
"@turf/helpers": "6.1.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/bbox-polygon": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@turf/bbox-polygon/-/bbox-polygon-6.0.1.tgz",
|
||||
"integrity": "sha512-f6BK6GOzUNjmJeOYHklk/5LNcQMQbo51gvAM10dTM5IqzKP01KM5bgV88uOKfSZB0HRQVpaRV1tgXk2bg5cPRg==",
|
||||
"requires": {
|
||||
"@turf/helpers": "6.1.4"
|
||||
}
|
||||
},
|
||||
"@turf/buffer": {
|
||||
|
|
@ -57,6 +75,22 @@
|
|||
"@turf/projection": "5.1.5",
|
||||
"d3-geo": "1.7.1",
|
||||
"turf-jsts": "1.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/bbox": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-5.1.5.tgz",
|
||||
"integrity": "sha1-MFHfUUrUxQ9KT5uKLRX9i2hA7aM=",
|
||||
"requires": {
|
||||
"@turf/helpers": "5.1.5",
|
||||
"@turf/meta": "5.2.0"
|
||||
}
|
||||
},
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/center": {
|
||||
|
|
@ -66,6 +100,31 @@
|
|||
"requires": {
|
||||
"@turf/bbox": "5.1.5",
|
||||
"@turf/helpers": "5.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/bbox": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-5.1.5.tgz",
|
||||
"integrity": "sha1-MFHfUUrUxQ9KT5uKLRX9i2hA7aM=",
|
||||
"requires": {
|
||||
"@turf/helpers": "5.1.5",
|
||||
"@turf/meta": "5.2.0"
|
||||
}
|
||||
},
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/circle": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@turf/circle/-/circle-6.0.1.tgz",
|
||||
"integrity": "sha512-pF9XsYtCvY9ZyNqJ3hFYem9VaiGdVNQb0SFq/zzDMwH3iWZPPJQHnnDB/3e8RD1VDtBBov9p5uO2k7otsfezjw==",
|
||||
"requires": {
|
||||
"@turf/destination": "6.0.1",
|
||||
"@turf/helpers": "6.1.4"
|
||||
}
|
||||
},
|
||||
"@turf/clone": {
|
||||
|
|
@ -74,12 +133,43 @@
|
|||
"integrity": "sha1-JT6NNUdxgZduM636tQoPAqfw42c=",
|
||||
"requires": {
|
||||
"@turf/helpers": "5.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/destination": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@turf/destination/-/destination-6.0.1.tgz",
|
||||
"integrity": "sha512-MroK4nRdp7as174miCAugp8Uvorhe6rZ7MJiC9Hb4+hZR7gNFJyVKmkdDDXIoCYs6MJQsx0buI+gsCpKwgww0Q==",
|
||||
"requires": {
|
||||
"@turf/helpers": "6.1.4",
|
||||
"@turf/invariant": "6.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "6.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-6.1.4.tgz",
|
||||
"integrity": "sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
"version": "6.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-6.1.4.tgz",
|
||||
"integrity": "sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g=="
|
||||
},
|
||||
"@turf/invariant": {
|
||||
"version": "6.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@turf/invariant/-/invariant-6.1.2.tgz",
|
||||
"integrity": "sha512-WU08Ph8j0J2jVGlQCKChXoCtI50BB3yEH21V++V0T4cR1T27HKCxkehV2sYMwTierfMBgjwSwDIsxnR4/2mWXg==",
|
||||
"requires": {
|
||||
"@turf/helpers": "6.1.4"
|
||||
}
|
||||
},
|
||||
"@turf/meta": {
|
||||
"version": "5.2.0",
|
||||
|
|
@ -87,6 +177,13 @@
|
|||
"integrity": "sha1-OxrUhe4MOwsXdRMqMsOE1T5LpT0=",
|
||||
"requires": {
|
||||
"@turf/helpers": "5.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/projection": {
|
||||
|
|
@ -97,6 +194,13 @@
|
|||
"@turf/clone": "5.1.5",
|
||||
"@turf/helpers": "5.1.5",
|
||||
"@turf/meta": "5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/truncate": {
|
||||
|
|
@ -106,6 +210,13 @@
|
|||
"requires": {
|
||||
"@turf/helpers": "5.1.5",
|
||||
"@turf/meta": "5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@turf/union": {
|
||||
|
|
@ -115,6 +226,13 @@
|
|||
"requires": {
|
||||
"@turf/helpers": "5.1.5",
|
||||
"turf-jsts": "1.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@turf/helpers": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-5.1.5.tgz",
|
||||
"integrity": "sha1-FTQFInq5M9AEpbuWQantmZ/L4M8="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
|
|
@ -6383,7 +6501,6 @@
|
|||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"osenv": {
|
||||
|
|
@ -6875,14 +6992,6 @@
|
|||
"is-property": "1.0.2"
|
||||
}
|
||||
},
|
||||
"geojson-area": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/geojson-area/-/geojson-area-0.0.1.tgz",
|
||||
"integrity": "sha1-ESunTm8FB5lerfm0IVh909ia9/Y=",
|
||||
"requires": {
|
||||
"wgs84": "0.0.0"
|
||||
}
|
||||
},
|
||||
"get-caller-file": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz",
|
||||
|
|
@ -10205,16 +10314,6 @@
|
|||
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.3.1.tgz",
|
||||
"integrity": "sha512-adQOIzh+bfdridLM1xIgJ9VnJbAUY3wqs/ueF+ITla+PLQ1z47USdBKUf+iD9FuUA8RtlT6j6hZBfZoA6mW+XQ=="
|
||||
},
|
||||
"leaflet-geodesy": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/leaflet-geodesy/-/leaflet-geodesy-0.2.1.tgz",
|
||||
"integrity": "sha1-2EmordFrXZs3+cXyFOb+dCK7c3s=",
|
||||
"requires": {
|
||||
"geojson-area": "0.0.1",
|
||||
"spherical": "0.1.0",
|
||||
"wgs84": "0.0.0"
|
||||
}
|
||||
},
|
||||
"leaflet-graphicscale": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/leaflet-graphicscale/-/leaflet-graphicscale-0.0.2.tgz",
|
||||
|
|
@ -10745,6 +10844,20 @@
|
|||
"tmpl": "1.0.4"
|
||||
}
|
||||
},
|
||||
"map-common-utils": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/map-common-utils/-/map-common-utils-0.2.0.tgz",
|
||||
"integrity": "sha512-kI71M3pLACkGlrGHzOnC31tP3uSrNxyo9l1ABGXkGuvDZ4M4IvA2K1geukQih/iJLTnZXjbO5tr9/9qpqgxyqw==",
|
||||
"requires": {
|
||||
"@turf/bbox": "6.0.1",
|
||||
"@turf/bbox-polygon": "6.0.1",
|
||||
"@turf/destination": "6.0.1",
|
||||
"@turf/helpers": "6.1.4",
|
||||
"@turf/invariant": "6.1.2",
|
||||
"spherical": "0.2.0",
|
||||
"wgs84": "0.0.0"
|
||||
}
|
||||
},
|
||||
"maxmind": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/maxmind/-/maxmind-2.3.0.tgz",
|
||||
|
|
@ -19327,9 +19440,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"spherical": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/spherical/-/spherical-0.1.0.tgz",
|
||||
"integrity": "sha1-H+rMS4O80NwtiV74rbhfil7FQ8I=",
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/spherical/-/spherical-0.2.0.tgz",
|
||||
"integrity": "sha1-IHYdntltoSoPQil1XmKssaPcchA=",
|
||||
"requires": {
|
||||
"wgs84": "0.0.0"
|
||||
}
|
||||
|
|
@ -19811,9 +19924,9 @@
|
|||
"integrity": "sha1-uZkjZZpGc3uBQT7P+b1w42C6F1M="
|
||||
},
|
||||
"twit": {
|
||||
"version": "2.2.9",
|
||||
"resolved": "https://registry.npmjs.org/twit/-/twit-2.2.9.tgz",
|
||||
"integrity": "sha1-ZxBXT4FkHaoDeWobS457eNPXVnY=",
|
||||
"version": "2.2.11",
|
||||
"resolved": "https://registry.npmjs.org/twit/-/twit-2.2.11.tgz",
|
||||
"integrity": "sha512-BkdwvZGRVoUTcEBp0zuocuqfih4LB+kEFUWkWJOVBg6pAE9Ebv9vmsYTTrfXleZGf45Bj5H3A1/O9YhF2uSYNg==",
|
||||
"requires": {
|
||||
"bluebird": "3.5.1",
|
||||
"mime": "1.6.0",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"@cleverbeagle/dates": "^0.5.1",
|
||||
"@cleverbeagle/seeder": "^1.3.1",
|
||||
"@turf/buffer": "^5.1.5",
|
||||
"@turf/circle": "^6.0.1",
|
||||
"@turf/truncate": "^5.1.5",
|
||||
"@turf/union": "^5.1.5",
|
||||
"babel-runtime": "^6.26.0",
|
||||
|
|
@ -40,12 +41,12 @@
|
|||
"jsend": "^1.0.2",
|
||||
"juice": "^4.2.2",
|
||||
"leaflet": "^1.3.1",
|
||||
"leaflet-geodesy": "^0.2.1",
|
||||
"leaflet-graphicscale": "0.0.2",
|
||||
"leaflet-headless": "^0.2.6",
|
||||
"leaflet-sleep": "^0.5.1",
|
||||
"lodash": "^4.17.4",
|
||||
"loms.perlin": "^1.0.1",
|
||||
"map-common-utils": "^0.2.0",
|
||||
"maxmind": "^2.3.0",
|
||||
"meteor-accounts-t9n": "^2.0.3",
|
||||
"meteor-node-stubs": "^0.3.2",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue