Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isEditable) {
boundsLayer.enableEdit()
}
// set map view to region
try { // geometry calculcation are a bit hairy for invalid geometries (which may happen during polygon editing)
let viewPort = bboxPolygon(map.getBounds().toBBoxString().split(',').map(Number))
let xorAreaViewPort = erase(viewPort, L.polygon(boundsLayer.getLatLngs()[1]).toGeoJSON())
let fitboundsFunc
if (moveDirectly) {
fitboundsFunc = ::map.fitBounds
moveDirectly = false
} else if (
!xorAreaViewPort // new region fully includes viewport
|| area(xorAreaViewPort) > area(viewPort)*(1-0.01) // region is small compared to current viewport (<10% of the area covered) or feature is outside current viewport
) {
fitboundsFunc = ::map.flyToBounds
} else {
fitboundsFunc = () => {}
}
fitboundsFunc(
// zoom to inner ring!
boundsLayer.getLatLngs().slice(1)
.map(coords => L.polygon(coords).getBounds())
.reduce((bounds1, bounds2) => bounds1.extend(bounds2)),
{
paddingTopLeft: [20, 10+52],
paddingBottomRight: [20, 10+ ((fitBoundsWithBottomPadding) ? 212 : 52)]
})
} catch(e) {}
});
intersects.forEach((d,i) => {
const At = Turf.area(feature);
const Ast = Turf.area(d);
const Qt = feature.properties[options.weight];
const Qst = (Ast / At) * Qt;
const attributeValue = parseFloat(sourceFeatures[i].properties[options.attr]);
// wenn komplett im source feature,
const sb = Turf.extent(sourceFeatures[i]);
let isInside = true;
if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };
if(isInside) {
if(!isNaN(attributeValue)) {
result += Ps;
}
return;
intersects.forEach((d,i) => {
const Atsp2 = Turf.area(d);
const Gg = sourceFeatures[i].properties['Aggr'];
const Ps = Gg * ((sourceFeatures[i].properties['Relative']) / 100);
const Asp2 = d.properties.parentArea;
// const Asp2 = Turf.area(Asp.features[i]);
// const Ps = sourceFeatures[i].properties[options.attr];
// const As = Turf.area(sourceFeatures[i]);
result += (Atsp2 * Ps) / Asp2;
});
cities.features.forEach(function (item) {
console.log(item.properties.label + ',' + turf.area(item) / 1000000)
})
function dropTinyAreas(features){
var new_fc = new Array();
var count = 0;
for (var i=0; i< features.length; i++){
if (Turf.area(features[i]) > 10) {
new_fc.push(features[i]);
}
else {
count = count +1;
console.log('Dropping Tiny Feature.');
}
}
console.log("Dropping feature with tiny area: " + count +'/' + features.length);
return new_fc;
}
function intersectSourceMask(a, b) {
const resultFeatures = [];
for(let i = 0; i < a.features.length; i++) {
Logger.info(`[nClassDasymetricWeighting][intersectSourceMask][${i}/${a.features.length}]`);
for(let j = 0; j < b.features.length; j++) {
const d = a.features[i];
const e = b.features[j];
const isIntersect = Turf.intersect(d, e);
if(isIntersect) {
isIntersect.properties = objectAssign({}, d.properties, e.properties, { maskArea: Turf.area(e) });
resultFeatures.push(isIntersect);
}
}
}
return Turf.featurecollection(resultFeatures);
}
b.features.forEach(e => {
let isIntersect = Turf.intersect(d, e);
if(isIntersect && Turf.area(isIntersect) > 0) {
isIntersect = arealizeGeometryCollection(isIntersect);
isIntersect.properties = objectAssign({}, d.properties, e.properties)
resultFeatures.push(isIntersect);
}
});
});
function intersectSourceMask(a, b) {
const resultFeatures = [];
for(let i = 0; i < a.features.length; i++) {
Logger.info(`[nClassDasymetricWeightingRelative][intersectSourceMask][${i}/${a.features.length}]`);
for(let j = 0; j < b.features.length; j++) {
const d = a.features[i];
const e = b.features[j];
let isIntersect = Turf.intersect(d, e);
if(isIntersect) {
isIntersect = arealizeGeometryCollection(isIntersect);
isIntersect.properties = objectAssign({}, d.properties, e.properties, { maskArea: Turf.area(e) });
resultFeatures.push(isIntersect);
}
}
}
return Turf.featurecollection(resultFeatures);
}