Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
...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
}});
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 {
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,
}
});
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] });
};