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

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 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 cheeaun / busrouter-sg / visualization / build-stops.js View on Github external
const data = stops.features.map(f => {
  f.geometry.coordinates.forEach(c => round(c, 5));
  const feature = circle(f, .015, { steps: 3 });
  return {
    ...f.properties,
    name: toTitleCase(f.properties.name),
    level: levels[f.properties.number],
    contour: feature.geometry.coordinates,
  }
});
github iamanvesh / mapbox-gl-draw-circle / lib / modes / CircleMode.js View on Github external
CircleMode.clickAnywhere = function(state, e) {
  if (state.currentVertexPosition === 0) {
    state.currentVertexPosition++;
    const center = [e.lngLat.lng, e.lngLat.lat];
    const circleFeature = circle(center, state.initialRadiusInKm);
    state.polygon.incomingCoords(circleFeature.geometry.coordinates);
    state.polygon.properties.center = center;
    state.polygon.properties.radiusInKm = state.initialRadiusInKm;
  }
  return this.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [state.polygon.id] });
};

@turf/circle

turf circle module

MIT
Latest version published 3 years ago

Package Health Score

89 / 100
Full package analysis