Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
calculateGroundCoords(clickSequence: any, groundCoords: any) {
const modeConfig = this.getModeConfig();
if (!modeConfig || !modeConfig.lock90Degree || !clickSequence.length) {
return groundCoords;
}
if (clickSequence.length === 1) {
// if first point is clicked, then find closest polygon point and build ~90deg vector
const firstPoint = clickSequence[0];
const selectedGeometry = this.getSelectedGeometry();
const feature = turfPolygonToLine(selectedGeometry);
const lines = feature.type === 'FeatureCollection' ? feature.features : [feature];
let minDistance = Number.MAX_SAFE_INTEGER;
let closestPoint = null;
// If Multipolygon, then we should find nearest polygon line and stick split to it.
lines.forEach(line => {
const snapPoint = nearestPointOnLine(line, firstPoint);
const distanceFromOrigin = turfDistance(snapPoint, firstPoint);
if (minDistance > distanceFromOrigin) {
minDistance = distanceFromOrigin;
closestPoint = snapPoint;
}
});
if (closestPoint) {
// closest point is used as 90degree entry to the polygon
var distance = pointToLineDistance(centerPoint, geometry);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'Polygon') {
if (booleanPointInPolygon(centerPoint, geometry)) {
if (closestDistance != 0) {
closest = row;
closestDistance = 0;
}
} else {
var line = polygonToLine(geometry);
var distance = pointToLineDistance(centerPoint, line);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
}
}
}
}
closest.values.name.should.be.equal('point');
foundFeatures.should.be.deep.equal(['box1', 'box2', 'line', 'point']);
});
var distance = pointToLineDistance(centerPoint, geometry);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'Polygon') {
if (booleanPointInPolygon(centerPoint, geometry)) {
if (closestDistance != 0) {
closest = row;
closestDistance = 0;
}
} else {
var line = polygonToLine(geometry);
var distance = pointToLineDistance(centerPoint, line);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
}
}
}
}
closest.properties.Name.should.be.equal('Rio Grande');
});
});
function isPolyInPoly(feature1: Polygon, feature2: Polygon) {
for (const coord1 of feature1.coordinates[0]) {
if (booleanPointInPolygon(coord1, feature2)) {
return true;
}
}
for (const coord2 of feature2.coordinates[0]) {
if (booleanPointInPolygon(coord2, feature1)) {
return true;
}
}
const doLinesIntersect = lineIntersect(polygonToLine(feature1), polygonToLine(feature2));
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;
}
FeatureTiles.prototype.drawPolygon = function(path, geoJson, context, featureStyle) {
context.save();
context.beginPath();
path(PolyToLine(geoJson).geometry);
context.closePath();
var fillPaint = this.getPolygonFillPaint(featureStyle);
if (fillPaint !== undefined && fillPaint !== null) {
context.fillStyle = fillPaint.getColorRGBA();
context.fill();
}
var paint = this.getPolygonPaint(featureStyle);
context.strokeStyle = paint.getColorRGBA();
context.lineWidth = paint.getStrokeWidth();
context.stroke();
context.restore();
};
function doLineStringAndPolygonCross(lineString, polygon: Polygon) {
const line: any = polygonToLine(polygon);
const doLinesIntersect = lineIntersect(lineString, line);
if (doLinesIntersect.features.length > 0) {
return true;
}
return false;
}