How to use @turf/circle - 10 common examples

To help you get started, we’ve selected a few @turf/circle 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 uber / nebula.gl / modules / layers / src / mode-handlers / draw-circle-from-center-handler.js View on Github external
return result;
    }

    const modeConfig = this.getModeConfig() || {};
    // Default turf value for circle is 64
    const { steps = 64 } = modeConfig;
    const options = { steps };

    if (steps < 4) {
      console.warn(`Minimum steps to draw a circle is 4 `); // eslint-disable-line no-console,no-undef
      options.steps = 4;
    }

    const centerCoordinates = clickSequence[0];
    const radius = Math.max(distance(centerCoordinates, event.groundCoords), 0.001);
    this._setTentativeFeature(circle(centerCoordinates, radius, options));

    return result;
  }
}
github w3reality / three-geo / examples / geo-viewer / src / map-helper.js View on Github external
const { projInv, unitsPerMeter } = this.projection;

        // add orbitMarker
        const target = orbit.userData.target;
        const llTarget = projInv(target.x, target.y);
        console.log('llTarget:', llTarget);

        this.orbitMarker =
            L.marker(llTarget)
                .bindTooltip("Orbit Axis", {
                    permanent: true,
                    direction: 'right',
                }).addTo(this.map);

        // add orbitCircle
        const circle = turfCircle(
            MapHelper.swap(llTarget),
            orbit.userData.radius / unitsPerMeter, {
                units: 'meters',
            });
        this.orbitCircle =
            L.geoJson(circle, {
                style: feature => {
                    return {
                        dashArray: '3, 5',
                        color: '#ff00ff',
                        fillOpacity: 0.0,
                    };
                },
            }).addTo(this.map);
    }
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
_handlePointerMoveForDrawCircleByBoundingBox(groundCoords: Position) {
    if (this._clickSequence.length === 0) {
      // nothing to do yet
      return;
    }

    const firstClickedPoint = this._clickSequence[0];
    const centerCoordinates = getIntermediatePosition(firstClickedPoint, groundCoords);
    const radius = Math.max(distance(firstClickedPoint, centerCoordinates), 0.001);
    this._setTentativeFeature(circle(centerCoordinates, radius));
  }
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
_handlePointerMoveForDrawCircleFromCenter(groundCoords: Position) {
    if (this._clickSequence.length === 0) {
      // nothing to do yet
      return;
    }

    const centerCoordinates = this._clickSequence[0];
    const radius = Math.max(distance(centerCoordinates, groundCoords), 0.001);
    this._setTentativeFeature(circle(centerCoordinates, radius));
  }
github terascope / teraslice / packages / xlucene-evaluator / src / document-matcher / logic-builder / geo.ts View on Github external
export function geoDistance(node: GeoDistance) {
    const {
        distance, unit, lat, lon
    } = node;
    const geoPoint = [lon, lat];
    const config = { units: unit };
    let polygon: createCircle;

    if (lat != null && lon != null) {
        polygon = createCircle(
            geoPoint,
            distance,
            config
        );
    }

    // Nothing matches so return false
    if (polygon == null) return () => false;
    return testGeoPolygon(polygon);
}
github Turfjs / turf / packages / turf-sector / index.js View on Github external
function sector(center, radius, bearing1, bearing2, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');

    // validation
    if (!center) throw new Error('center is required');
    if (bearing1 === undefined || bearing1 === null) throw new Error('bearing1 is required');
    if (bearing2 === undefined || bearing2 === null) throw new Error('bearing2 is required');
    if (!radius) throw new Error('radius is required');
    if (typeof options !== 'object') throw new Error('options must be an object');

    if (convertAngleTo360(bearing1) === convertAngleTo360(bearing2)) {
        return circle(center, radius, options);
    }
    var coords = getCoords(center);
    var arc = lineArc(center, radius, bearing1, bearing2, options);
    var sliceCoords = [[coords]];
    coordEach(arc, function (currentCoords) {
        sliceCoords[0].push(currentCoords);
    });
    sliceCoords[0].push(coords);

    return polygon(sliceCoords);
}
github terascope / teraslice / packages / xlucene-evaluator / src / document-matcher / type-manager / types / geo.ts View on Github external
pointTopLeft,
                        pointBottomRight,
                    ]);

                    const box = bbox(line);
                    polygon = bboxPolygon(box);
                }
            }

            if (geoPoint && geoDistance) {
                const { distance, unit } = parseGeoDistance(geoDistance);
                const config = { units: unit };

                const parsedGeoPoint = parseGeoPoint(geoPoint);
                if (parsedGeoPoint != null) {
                    polygon = createCircle(
                        parsedGeoPoint,
                        distance,
                        config
                    );
                }
            }

            // Nothing matches so return false
            if (polygon == null) return () => false;
            return (fieldData: string): boolean => {
                const point = parseGeoPoint(fieldData, false);
                if (!point) return false;
                return pointInPolygon(point, polygon);
            };
        }
github geosolutions-it / MapStore2 / web / client / reducers / annotations.js View on Github external
...state.selected.properties, center: centerCoords, radius: !isNil(radius) ? radius : selected.properties.radius
            }});
            features = state.editing.features.map(f => {
                return f.properties.id === state.selected.properties.id ? selected : f;
            });
            selected = { ...selected, geometry: { coordinates: centerCoords, type: "Circle"}};
            let center;
            let c = {
                type: 'Polygon',
                coordinates: [[[]]]
            };
                // polygonGeom setting
            if (validateCoordsArray(selected.properties.center)) {
                center = selected.properties.center;
                // turf/circle by default use km unit hence we divide by 1000 the radius(in meters)
                c = circle(
                    center,
                    action.crs === "EPSG:4326" ? action.radius : action.radius / 1000,
                    { steps: 100, units: action.crs === "EPSG:4326" ? "degrees" : "kilometers" }
                ).geometry;
            } else {
                selected = set("properties.center", [], selected);
            }

            selected = set("properties.polygonGeom", c, selected);
        } else if (selected.properties.isText) {
            let c = !isNil(coordinates) ? validCoordinates[0] : state.selected.geometry.coordinates;
            selected = assign({}, {...selected,
                properties: {
                    ...state.selected.properties,
                    valueText: !isNil(text) ? text : state.selected.properties.valueText
                }});
github geosolutions-it / MapStore2 / web / client / reducers / annotations.js View on Github external
selected,
                unsavedChanges: true
            });
        }
        selected = set("properties.isValidFeature", validateFeature({
            properties: selected.properties,
            components: getComponents({coordinates: action.components[0] || [], type: "Circle"}),
            type: "Circle"
        }), selected);
        selected = set("properties.center", action.components[0], selected);
        selected = set("geometry.coordinates", action.components[0], selected);

        // need to change the polygon coords after radius changes
        // but this implementation is ugly. is using openlayers to do that and maybe we need to refactor this

        let feature = circle(
            selected.properties.center,
            action.crs === "EPSG:4326" ? action.radius : action.radius / 1000,
            { steps: 100, units: action.crs === "EPSG:4326" ? "degrees" : "kilometers" }
        );
        selected = set("properties.polygonGeom", feature.geometry, selected);

        let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
        const selectedGeoJSON = set("geometry", selected.properties.polygonGeom, selected);
        newState = set(`editing.features`, state.editing.features.map(f => {
            return set("properties.canEdit", false, f);
        }), state);

        newState = set(`unsavedGeometry`, true, newState);
        if (ftChangedIndex === -1) {
            newState = set("editing.features", newState.editing.features.concat([selectedGeoJSON]), newState);
        } else {
github uber / nebula.gl / examples / advanced / example.js View on Github external
_loadSample = (type: string) => {
    if (type === 'mixed') {
      this.setState({
        testFeatures: sampleGeoJson,
        selectedFeatureIndexes: []
      });
    } else if (type === 'complex') {
      this.setState({
        testFeatures: {
          type: 'FeatureCollection',
          features: [
            circle([-122.45, 37.81], 4, { steps: 5000 }),
            circle([-122.33, 37.81], 4, { steps: 5000 }),
            circle([-122.45, 37.73], 4, { steps: 5000 }),
            circle([-122.33, 37.73], 4, { steps: 5000 })
          ]
        },
        selectedFeatureIndexes: []
      });
    } else if (type === 'blank') {
      this.setState({
        testFeatures: EMPTY_FEATURE_COLLECTION,
        selectedFeatureIndexes: []
      });
    } else if (type === 'file') {
      const el = document.createElement('input');
      el.type = 'file';
      el.onchange = e => {
        if (e.target.files && e.target.files[0]) {
          const reader = new FileReader();
          reader.onload = ({ target }) => {

@turf/circle

turf circle module

MIT
Latest version published 3 months ago

Package Health Score

96 / 100
Full package analysis