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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue