How to use the @turf/nearest-point-on-line.default function in @turf/nearest-point-on-line

To help you get started, we’ve selected a few @turf/nearest-point-on-line examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PieceMaker / max-inscribed-circle / max-inscribed-circle.js View on Github external
//define borders of polygon and holes as LineStrings
    for(let j = 0; j < polygon.geometry.coordinates.length; j++) {
        polygonBoundaries.features.push({
            type: "Feature",
            properties: {},
            geometry: {
                type: "LineString",
                coordinates: polygon.geometry.coordinates[j]
            }
        })
    }

    for(let k = 0; k < ptsWithin.features.length; k++) {
        for(let l = 0; l < polygonBoundaries.features.length; l++) {
            if(l === 0) {
                vertexDistance = nearestPointOnLine(polygonBoundaries.features[l], ptsWithin.features[k], {units: units}).properties.dist;
            } else {
                vertexDistance = Math.min(vertexDistance,
                    nearestPointOnLine(polygonBoundaries.features[l], ptsWithin.features[k], {units: units}).properties.dist);
            }
        }
        if(vertexDistance > labelLocation.maxDist) {
            labelLocation.coordinates = ptsWithin.features[k].geometry.coordinates;
            labelLocation.maxDist = vertexDistance;
        }
    }

    return point(labelLocation.coordinates, {radius: labelLocation.maxDist, units: units});
};
github noncomputable / AgentMaps / src / agents.js View on Github external
start_place = this.newTripStartPlace(),
	start_street_id,
	start_street_point,
	start_street_feature;
	
	if (start_place.type === "street" && goal_place.type === "street") {
		start_street_id = start_place.id,
		start_street_point = this.trip.path.length !== 0 ? 
			this.trip.path[this.trip.path.length - 1] :
			this.getLatLng();
		start_street_point.new_place = {type: "street", id: start_street_id};

		goal_street_id = goal_place.id,
		goal_street_feature = this.agentmap.streets.getLayer(goal_street_id).feature,
		goal_coords = L.A.pointToCoordinateArray(goal_lat_lng),
		goal_street_point = L.latLng(nearestPointOnLine(goal_street_feature, goal_coords).geometry.coordinates.reverse());
		goal_street_point.new_place = goal_place;
	}
	else {
		throw new Error("Both the start and end places must be streets!");
	}
	
	if (start_street_id === goal_street_id) {
		this.setTravelOnSameStreet(start_street_point, goal_street_point, goal_street_feature, goal_street_id, speed);
	}
	//If the start and end points are on different streets, move from the start to its nearest intersection, then from there
	//to the intersection nearest to the end, and finally to the end.
	else {
		let start_nearest_intersection = this.agentmap.getNearestIntersection(start_street_point, start_place),
		goal_nearest_intersection = this.agentmap.getNearestIntersection(goal_street_point, goal_place);
		
		start_street_feature = this.agentmap.streets.getLayer(start_street_id).feature;

@turf/nearest-point-on-line

turf nearest-point-on-line module

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis

Popular @turf/nearest-point-on-line functions

Similar packages