Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// console.log(`getContours(): ${x}/${eleList.length}`);
let currentElevation = eleList[x];
let elevationPolys = geojson.features.filter((feature) => {
return feature.properties.ele === currentElevation;
});
try { // merge between tiles
let feats = turfHelpers.featureCollection(elevationPolys).features;
// console.log(currentElevation, feats.length, feats);
// feats.forEach(feat => { console.log('type:', feat.geometry.type); }); // 'Polygon'
let mergedElevationPoly = feats.reduce(((accm, feat) => turfUnion(accm, feat)), feats[0]);
// console.log('@@@', mergedElevationPoly, currentElevation);
if (0) { // trim to desired search area
mergedElevationPoly = turfIntersect( // use module version instead
polygon, mergedElevationPoly);
// console.log('@@@', polygon);
}
// console.log('@@@mergedElevationPoly:', mergedElevationPoly);
if (mergedElevationPoly) {
// console.log('@@@merge success', currentElevation);
let contourArea = turfArea(mergedElevationPoly.geometry);
// L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);
contours.push({
'geometry': mergedElevationPoly,
'ele': currentElevation,
'area': contourArea,
});
}
);
return null;
}
const feature = {
type: 'Feature',
geometry
};
let updatedGeometry;
if (modeConfig.booleanOperation === 'union') {
updatedGeometry = turfUnion(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'difference') {
updatedGeometry = turfDifference(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'intersection') {
updatedGeometry = turfIntersect(selectedFeature, feature);
} else {
// eslint-disable-next-line no-console,no-undef
console.warn(`Invalid booleanOperation ${modeConfig.booleanOperation}`);
return null;
}
if (!updatedGeometry) {
// eslint-disable-next-line no-console,no-undef
console.warn('Canceling edit. Boolean operation erased entire polygon.');
return null;
}
const featureIndex = props.selectedIndexes[0];
const updatedData = new ImmutableFeatureCollection(props.data)
.replaceGeometry(featureIndex, updatedGeometry.geometry)
);
return null;
}
const feature = {
type: 'Feature',
geometry
};
let updatedGeometry;
if (modeConfig.booleanOperation === 'union') {
updatedGeometry = turfUnion(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'difference') {
updatedGeometry = turfDifference(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'intersection') {
updatedGeometry = turfIntersect(selectedFeature, feature);
} else {
// eslint-disable-next-line no-console,no-undef
console.warn(`Invalid booleanOperation ${modeConfig.booleanOperation}`);
return null;
}
if (!updatedGeometry) {
// eslint-disable-next-line no-console,no-undef
console.warn('Canceling edit. Boolean operation erased entire polygon.');
return null;
}
const featureIndex = this.getSelectedFeatureIndexes()[0];
const updatedData = this.getImmutableFeatureCollection()
.replaceGeometry(featureIndex, updatedGeometry.geometry)
featureEach(polygonizedUnionGeom, cuttedSection => {
// checks to see if segment is in polygon
const segmentInPolygon = intersect(cuttedSection, outerPolygon);
if (segmentInPolygon && segmentInPolygon.geometry.type === 'Polygon') {
let polygonWithoutHoles = [];
if (innerPolygon.features.length > 0) {
// iterates over all the holes and removes their intersection with the cutted polygon
innerPolygon.features.forEach(holes => {
const toCut = polygonWithoutHoles.length > 0 ? polygonWithoutHoles : [segmentInPolygon];
toCut.forEach((tocutPart, i) => {
let intersection = difference(tocutPart, holes);
if (intersection && (intersection.geometry.type === 'Polygon' || intersection.geometry.type === 'MultiPolygon')) {
if (intersection.geometry.type === 'MultiPolygon') {
intersection.geometry.coordinates.forEach(intersectPolyCoords => {
polygonWithoutHoles.push(makePolygon(intersectPolyCoords));
});
} else {
polygonWithoutHoles[i] = intersection;
}
var squareTasks = squares.map(square => {
// Clip the square with the input geometry. In this way we work with a
// smaller area..
let workArea = intersect(adminArea, square);
return createProcessAreaTask(workArea, poiByType, villages, osrm, maxTime, maxSpeed, id);
});
sines).forEach(function (triangle) {
if (options.mask) {
if (intersect(options.mask, triangle)) results.push(triangle);
} else {
results.push(triangle);
}
});
} else {
cellTriangle1 = polygon([[
[currentX, currentY],
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY]
]], options.properties);
cellTriangle2 = polygon([[
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY + cellHeight]
]], options.properties);
}
if (options.mask) {
if (intersect(options.mask, cellTriangle1)) results.push(cellTriangle1);
if (intersect(options.mask, cellTriangle2)) results.push(cellTriangle2);
} else {
results.push(cellTriangle1);
results.push(cellTriangle2);
}
currentY += cellHeight;
yi++;
}
xi++;
currentX += cellWidth;
}
return featureCollection(results);
}
} else if (yi % 2 === 1 && xi % 2 === 1) {
cellTriangle1 = polygon([[
[currentX, currentY],
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY]
]], options.properties);
cellTriangle2 = polygon([[
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY + cellHeight]
]], options.properties);
}
if (options.mask) {
if (intersect(options.mask, cellTriangle1)) results.push(cellTriangle1);
if (intersect(options.mask, cellTriangle2)) results.push(cellTriangle2);
} else {
results.push(cellTriangle1);
results.push(cellTriangle2);
}
currentY += cellHeight;
yi++;
}
xi++;
currentX += cellWidth;
}
return featureCollection(results);
}
if (intersect(options.mask, triangle)) results.push(triangle);
} else {
results.push(triangle);
}
});
} else {
var hex = hexagon(
[center_x, center_y],
cellWidth / 2,
cellHeight / 2,
options.properties,
cosines,
sines
);
if (options.mask) {
if (intersect(options.mask, hex)) results.push(hex);
} else {
results.push(hex);
}
}
}
}
return featureCollection(results);
}