How to use the @turf/bearing.default function in @turf/bearing

To help you get started, we’ve selected a few @turf/bearing 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 noncomputable / AgentMaps / src / buildings.js View on Github external
//One sub-array of unit features for each side of the road.
	let unit_features = [[],[]],
	starting_id = proposed_unit_features.length,
	increment = 1;
	
	for (let anchor_pair of unit_anchors) {
		//Pair of unit_features opposite each other on a street.
		let unit_pair = [null, null];
		
		for (let i of [1, -1]) {
			let anchor_a = anchor_pair[0].geometry.coordinates,
			anchor_b = anchor_pair[1].geometry.coordinates,
			anchor_latLng_pair = [anchor_a, anchor_b],
			street_buffer = unit_options.front_buffer / 1000, //Distance between center of street and start of unit.
			house_depth = unit_options.depth / 1000,
			angle = bearing(anchor_a, anchor_b),
			new_angle = angle + i * 90, //Angle of line perpendicular to the anchor segment.
			unit_feature = { 
				type: "Feature",
				properties: {
					street: "none"
				},
				geometry: {
					type: "Polygon",
					coordinates: [[]]
				}
			};
			unit_feature.geometry.coordinates[0][0] = destination(anchor_a, street_buffer, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][1] = destination(anchor_b, street_buffer, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][2] = destination(anchor_b, street_buffer + house_depth, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][3] = destination(anchor_a, street_buffer + house_depth, new_angle).geometry.coordinates;
			unit_feature.geometry.coordinates[0][4] = unit_feature.geometry.coordinates[0][0];
github noncomputable / AgentMaps / src / agents.js View on Github external
Agent.travelTo = function(goal_point) {
	this.trip.current_point = this.getLatLng(),
	this.trip.goal_point = goal_point,
		
	//Negating so that neg result corresponds to the goal being rightward/above, pos result to it being leftward/below.
	this.trip.lat_dir = Math.sign(- (this.trip.current_point.lat - this.trip.goal_point.lat)),
	this.trip.lng_dir = Math.sign(- (this.trip.current_point.lng - this.trip.goal_point.lng)),
		
	this.trip.angle = bearing(L.A.pointToCoordinateArray(this.trip.current_point), L.A.pointToCoordinateArray(this.trip.goal_point));
	this.trip.slope = Math.abs((this.trip.current_point.lat - this.trip.goal_point.lat) / (this.trip.current_point.lng - this.trip.goal_point.lng));
	this.trip.speed = this.trip.goal_point.speed;
	
	//If the agent won't be at any particular place at least until it reaches its next goal, mark its place as unanchored.
	if (this.trip.path[0].new_place.type === "unanchored" || this.trip.path[0].move_directly === true) {
		this.place = {type: "unanchored"};	
	}
};
github noncomputable / AgentMaps / tool / browserlessbuildings.js View on Github external
//One sub-array of unit features for each side of the road.
	let unit_features = [[],[]],
	starting_id = proposed_unit_features.length,
	increment = 1;
	
	for (let anchor_pair of unit_anchors) {
		//Pair of unit_features opposite each other on a street.
		let unit_pair = [null, null];
		
		for (let i of [1, -1]) {
			let anchor_a = anchor_pair[0].geometry.coordinates,
			anchor_b = anchor_pair[1].geometry.coordinates,
			anchor_latLng_pair = [anchor_a, anchor_b],
			street_buffer = unit_options.front_buffer / 1000, //Distance between center of street and start of unit.
			house_depth = unit_options.depth / 1000,
			angle = bearing(anchor_a, anchor_b),
			new_angle = angle + i * 90, //Angle of line perpendicular to the anchor segment.
			unit_feature = { 
				type: "Feature",
				properties: {
					street: "none"
				},
				geometry: {
					type: "Polygon",
					coordinates: [[]]
				}
			};
			unit_feature.geometry.coordinates[0][0] = destination(anchor_a, street_buffer, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][1] = destination(anchor_b, street_buffer, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][2] = destination(anchor_b, street_buffer + house_depth, new_angle).geometry.coordinates,
			unit_feature.geometry.coordinates[0][3] = destination(anchor_a, street_buffer + house_depth, new_angle).geometry.coordinates;
			unit_feature.geometry.coordinates[0][4] = unit_feature.geometry.coordinates[0][0];
github mapstertech / mapbox-gl-draw-rotate-mode / index.js View on Github external
onDrag: function(state, e) {
      if(state.selectedFeature&&state.mode) {
        if(state.mode==='rotate') {
          state.lastMouseDownLngLat = {lng:e.lngLat.lng, lat: e.lngLat.lat};
          var draggedBearing = bearing(state.originalCenter, [e.lngLat.lng, e.lngLat.lat]);
          var rotatedCoords = [];
          switch (state.originalFeature.properties['meta:type']) {
            case 'Point':
              break;
            case 'LineString':
              state.originalFeature.geometry.coordinates.forEach(function(coords,index) {
                var distanceFromCenter = distance(state.originalCenter, coords);
                var bearingFromCenter = bearing(state.originalCenter, coords);
                var newPoint = destination(state.originalCenter, distanceFromCenter, bearingFromCenter+draggedBearing);
                rotatedCoords.push(newPoint.geometry.coordinates);
              })
              break;
            case 'Polygon':
              var polyCoords = [];
              state.originalFeature.geometry.coordinates[0].forEach(function(coords,index) {
                var distanceFromCenter = distance(state.originalCenter, coords);
github mapstertech / mapbox-gl-draw-rotate-mode / index.js View on Github external
state.originalFeature.geometry.coordinates[0].forEach(function(coords,index) {
                var distanceFromCenter = distance(state.originalCenter, coords);
                var bearingFromCenter = bearing(state.originalCenter, coords);
                var newPoint = destination(state.originalCenter, distanceFromCenter, bearingFromCenter+draggedBearing);
                polyCoords.push(newPoint.geometry.coordinates);
              })
              rotatedCoords.push(polyCoords);

@turf/bearing

turf bearing module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/bearing functions