Skip to content

Commit

Permalink
Add streetview url property to geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrik committed Feb 18, 2024
1 parent d3961b2 commit cc90feb
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.math.RoundingMode;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
Expand Down Expand Up @@ -55,20 +56,31 @@ public final class VerkeersDrukteResource {
@Path(STATIC_PATH)
public FeatureCollection getStatic() {
FeatureCollection featureCollection = new FeatureCollection();
for (FeatureCollection.Feature f : handler.getStaticData().getFeatures()) {
FeatureCollection.Feature feature = new FeatureCollection.Feature(f);
String location = (String) f.getProperties().getOrDefault("dgl_loc", "");
if (!location.isEmpty()) {
String staticDataUrl = config.getBaseUrl() + TRAFFIC_PATH + STATIC_PATH + "/" + location;
feature.addProperty("staticDataUrl", staticDataUrl);
String dynamicDataUrl = config.getBaseUrl() + TRAFFIC_PATH + DYNAMIC_PATH + "/" + location;
feature.addProperty("dynamicDataUrl", dynamicDataUrl);
}
featureCollection.add(feature);
for (FeatureCollection.Feature feature : handler.getStaticData().getFeatures()) {
FeatureCollection.Feature updated = addUrlProperties(feature);
featureCollection.add(updated);
}
return featureCollection;
}

private FeatureCollection.Feature addUrlProperties(FeatureCollection.Feature f) {
FeatureCollection.Feature feature = new FeatureCollection.Feature(f);
String location = (String) f.getProperties().getOrDefault("dgl_loc", "");
if (!location.isEmpty()) {
String staticDataUrl = config.getBaseUrl() + TRAFFIC_PATH + STATIC_PATH + "/" + location;
feature.addProperty("staticDataUrl", staticDataUrl);
String dynamicDataUrl = config.getBaseUrl() + TRAFFIC_PATH + DYNAMIC_PATH + "/" + location;
feature.addProperty("dynamicDataUrl", dynamicDataUrl);
// streetview, see https://stackoverflow.com/questions/387942/google-street-view-url
FeatureCollection.PointGeometry geometry = (FeatureCollection.PointGeometry) feature.getGeometry();
int angle = Integer.parseInt((String) f.getProperties().getOrDefault("meetricht", 0));
String streetviewUrl = String.format(Locale.ROOT, "https://maps.google.com/maps?layer=c&cbll=%.6f,%.6f&cbp=12,%d,0,0,0",
geometry.getLatitude(), geometry.getLongitude(), angle);
feature.addProperty("streetviewUrl", streetviewUrl);
}
return feature;
}

@GET
@Path(STATIC_PATH + "/{location}")
public Optional<FeatureCollection.Feature> getStatic(@PathParam("location") String location) {
Expand Down

0 comments on commit cc90feb

Please sign in to comment.