Skip to content

Commit

Permalink
Use refactored Feature method
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Nov 23, 2024
1 parent f0ef919 commit a0b1892
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
3 changes: 2 additions & 1 deletion backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions backend/src/map_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use geo::{
Closest, ClosestPoint, Coord, Euclidean, Length, Line, LineInterpolatePoint, LineLocatePoint,
LineString, Point, Polygon,
};
use geojson::{Feature, FeatureCollection, GeoJson, Geometry};
use geojson::{Feature, FeatureCollection, GeoJson};
use serde::Serialize;
use utils::{Mercator, Tags};

Expand Down Expand Up @@ -284,7 +284,7 @@ impl MapModel {
.linestring
.line_interpolate_point(filter.percent_along)
.unwrap();
let mut f = Feature::from(Geometry::from(&self.mercator.to_wgs84(&pt)));
let mut f = self.mercator.to_wgs84_gj(&pt);
f.set_property("filter_kind", filter.kind.to_string());
f.set_property("road", r.0);
f.set_property("edited", Some(filter) != self.original_modal_filters.get(r));
Expand Down Expand Up @@ -317,15 +317,15 @@ impl MapModel {
.linestring
.line_interpolate_point(filter.percent_along)
.unwrap();
let mut f = Feature::from(Geometry::from(&self.mercator.to_wgs84(&pt)));
let mut f = self.mercator.to_wgs84_gj(&pt);
f.set_property("kind", "deleted_existing_modal_filter");
gj.features.push(f);
}

// Any direction edits
for r in &self.roads {
if self.directions[&r.id] != Direction::from_osm(&r.tags) {
let mut f = Feature::from(Geometry::from(&self.mercator.to_wgs84(&r.linestring)));
let mut f = self.mercator.to_wgs84_gj(&r.linestring);
f.set_property("kind", "direction");
f.set_property("direction", self.directions[&r.id].to_string());
gj.features.push(f);
Expand All @@ -334,9 +334,7 @@ impl MapModel {

gj.features.extend(self.boundaries.values().cloned());

let mut f = Feature::from(Geometry::from(
&self.mercator.to_wgs84(&self.boundary_polygon),
));
let mut f = self.mercator.to_wgs84_gj(&self.boundary_polygon);
f.set_property("kind", "study_area_boundary");
gj.features.push(f);

Expand Down Expand Up @@ -454,12 +452,12 @@ impl MapModel {
.unwrap()
.route(self, pt1, pt2)
{
let mut f = Feature::from(Geometry::from(&self.mercator.to_wgs84(&linestring)));
let mut f = self.mercator.to_wgs84_gj(&linestring);
f.set_property("kind", "before");
features.push(f);
}
if let Some(linestring) = self.router_current.as_ref().unwrap().route(self, pt1, pt2) {
let mut f = Feature::from(Geometry::from(&self.mercator.to_wgs84(&linestring)));
let mut f = self.mercator.to_wgs84_gj(&linestring);
f.set_property("kind", "after");
features.push(f);
}
Expand Down Expand Up @@ -496,7 +494,7 @@ impl Road {
}

pub fn to_gj(&self, mercator: &Mercator) -> Feature {
let mut f = Feature::from(Geometry::from(&mercator.to_wgs84(&self.linestring)));
let mut f = mercator.to_wgs84_gj(&self.linestring);
f.set_property("id", self.id.0);
f.set_property("way", self.way.to_string());
f.set_property("node1", self.node1.to_string());
Expand Down
6 changes: 3 additions & 3 deletions backend/src/neighbourhood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use geo::{
Area, Contains, Distance, Euclidean, Intersects, Length, LineInterpolatePoint, LineLocatePoint,
LineString, Point, Polygon,
};
use geojson::{Feature, FeatureCollection, Geometry};
use geojson::FeatureCollection;
use web_time::Instant;

use crate::geo_helpers::clip_linestring_to_polygon;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Neighbourhood {
features.push(f);
}
for i in &self.border_intersections {
let mut f = Feature::from(Geometry::from(&map.mercator.to_wgs84(&map.get_i(*i).point)));
let mut f = map.mercator.to_wgs84_gj(&map.get_i(*i).point);
f.set_property("kind", "border_intersection");
features.push(f);
}
Expand All @@ -148,7 +148,7 @@ impl Neighbourhood {
.iter()
.zip(derived.render_cells.colors.iter())
{
let mut f = Feature::from(Geometry::from(&map.mercator.to_wgs84(polygons)));
let mut f = map.mercator.to_wgs84_gj(polygons);
f.set_property("kind", "cell");
match color {
Color::Disconnected => f.set_property("cell_color", "disconnected"),
Expand Down
4 changes: 2 additions & 2 deletions backend/src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use fast_paths::InputGraph;
use geo::{Euclidean, Length, LineString};
use geojson::{Feature, Geometry};
use geojson::Feature;
use utils::NodeMap;

use crate::{Direction, IntersectionID, MapModel, Neighbourhood, RoadID};
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Path {
let linestring = LineString::new(pts);

let length = linestring.length::<Euclidean>();
let mut f = Feature::from(Geometry::from(&map.mercator.to_wgs84(&linestring)));
let mut f = map.mercator.to_wgs84_gj(&linestring);
f.set_property("directness", self.directness);
f.set_property("length_meters", length);
f
Expand Down

0 comments on commit a0b1892

Please sign in to comment.