def get_map_for_geojson_trip(geojson_trip): m = folium.Map() location_points = [] for f in geojson_trip["features"]: if f["type"] == "Feature": print(f["properties"]["feature_type"], f["id"]) if f["properties"]["feature_type"] == 'start_place': place_marker = get_place_ui(f) ic = folium.features.Icon(color='green', icon="flag") place_marker.add_child(ic) place_marker.add_to(m) if f["properties"]["feature_type"] == 'end_place': place_marker = get_place_ui(f) ic = folium.features.Icon(color='red', icon="flag") place_marker.add_child(ic) place_marker.add_to(m) if f["properties"]["feature_type"] == 'stop': (start_marker, end_marker) = get_stop_ui(f) start_marker.add_to(m) end_marker.add_to(m) if f["type"] == "FeatureCollection": for section in f["features"]: print(section["properties"]["feature_type"], section["id"]) if (section["properties"]["feature_type"] == "section"): section_line = get_section_ui(section) location_points.extend(section_line.location) section_line.add_to(m) else: raise NotImplementedException() temp_polyline = folium.PolyLine(location_points) m.fit_bounds(temp_polyline.get_bounds()) return m
def get_map_for_geojson_unsectioned(geojson): div_icon = folium.DivIcon() all_div_markers = [folium.CircleMarker(p["geometry"]["coordinates"][::-1], popup=bju.dumps(p["properties"]), radius=5) for p in geojson["features"][0]["features"]] # all_div_markers = [folium.Marker(p["geometry"]["coordinates"][::-1], # popup=json.dumps(p["properties"]), # icon=div_icon) # for p in all_geojson["features"][0]["features"]] print("Points are ", [m.location for m in all_div_markers[:5]], "...") geojson_line_string = geojson["features"][1]["geometry"] polyline_coords = [c[::-1] for c in geojson_line_string["coordinates"]] print("Linestring is", polyline_coords[:5], "...") polyline = folium.PolyLine(polyline_coords) bounds = polyline.get_bounds() m = folium.Map(tiles='Stamen Terrain') m.fit_bounds(bounds) for marker in all_div_markers: marker.add_to(m) polyline.add_to(m) return m
def get_section_ui(section): lat_lng_points = list( (p[::-1] for p in section["geometry"]["coordinates"])) return folium.PolyLine(lat_lng_points, popup=bju.dumps(section["properties"]))