Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const clickSequence = this.getClickSequence();
if (!selectedGeometry) {
// eslint-disable-next-line no-console,no-undef
console.warn('A polygon must be selected for splitting');
this._setTentativeFeature(null);
return editAction;
}
const pt = {
type: 'Point',
coordinates: clickSequence[clickSequence.length - 1]
};
const isPointInPolygon = booleanPointInPolygon(pt, selectedGeometry);
if (clickSequence.length > 1 && tentativeFeature && !isPointInPolygon) {
this.resetClickSequence();
const isLineInterectingWithPolygon = lineIntersect(tentativeFeature, selectedGeometry);
if (isLineInterectingWithPolygon.features.length === 0) {
this._setTentativeFeature(null);
return editAction;
}
return this.splitPolygon();
}
return editAction;
}
for (var i = 0; i < coords.length - 1; i++) {
//start
var start = point(coords[i]);
start.properties.dist = distance(pt, start, options);
//stop
var stop = point(coords[i + 1]);
stop.properties.dist = distance(pt, stop, options);
// sectionLength
var sectionLength = distance(start, stop, options);
//perpendicular
var heightDistance = Math.max(start.properties.dist, stop.properties.dist);
var direction = bearing(start, stop);
var perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
var perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
var intersect = lineIntersects(
lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
lineString([start.geometry.coordinates, stop.geometry.coordinates])
);
var intersectPt = null;
if (intersect.features.length > 0) {
intersectPt = intersect.features[0];
intersectPt.properties.dist = distance(pt, intersectPt, options);
intersectPt.properties.location = length + distance(start, intersectPt, options);
}
if (start.properties.dist < closestPt.properties.dist) {
closestPt = start;
closestPt.properties.index = i;
closestPt.properties.location = length;
}
if (stop.properties.dist < closestPt.properties.dist) {
if (splitterType === 'GeometryCollection') throw new Error('splitter cannot be a GeometryCollection');
// remove excessive decimals from splitter
// to avoid possible approximation issues in rbush
var truncatedSplitter = truncate(splitter, {precision: 7});
switch (splitterType) {
case 'Point':
return splitLineWithPoint(line, truncatedSplitter);
case 'MultiPoint':
return splitLineWithPoints(line, truncatedSplitter);
case 'LineString':
case 'MultiLineString':
case 'Polygon':
case 'MultiPolygon':
return splitLineWithPoints(line, lineIntersect(line, truncatedSplitter));
}
}
function doLineStringAndPolygonCross(lineString, polygon: Polygon) {
const line: any = polygonToLine(polygon);
const doLinesIntersect = lineIntersect(lineString, line);
if (doLinesIntersect.features.length > 0) {
return true;
}
return false;
}
function isLineInPoly(polygon: Polygon, lineString: LineString) {
for (const coord of lineString.coordinates) {
if (booleanPointInPolygon(coord, polygon)) {
return true;
}
}
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
if (doLinesIntersect.features.length > 0) {
return true;
}
return false;
}
}
if (olSlicer.getCoordinates().length > 2) {
throw new GeometrySliceLineStringError();
}
const olGeoJSON = new OlGeoJSON();
const slicer = olGeoJSON.writeGeometryObject(olSlicer);
const outerCoordinates = olPolygon.getLinearRing(0).getCoordinates();
const parts = [[], []];
let totalIntersectionCount = 0;
for (let i = 0, ii = outerCoordinates.length - 1; i < ii; i++) {
const segmentCoordinates = [outerCoordinates[i], outerCoordinates[i + 1]];
const segment = lineString(segmentCoordinates);
const intersections = lineIntersect(segment, slicer).features;
const intersectionCount = intersections.length;
totalIntersectionCount += intersectionCount;
if (intersectionCount > 1 || totalIntersectionCount > 2) {
throw new GeometrySliceTooManyIntersectionError();
}
parts[0].push(segmentCoordinates[0]);
if (intersectionCount === 1) {
const intersection = intersections[0].geometry.coordinates;
parts[0].push(intersection);
parts[1].push(intersection);
parts.reverse();
}
}
function isLineOnLine(lineString1: LineString, lineString2: LineString) {
const doLinesIntersect = lineIntersect(lineString1, lineString2);
if (doLinesIntersect.features.length > 0) {
return true;
}
return false;
}