# OpenStreetMapX, folium

**URL:** <https://discourse.julialang.org/t/openstreetmapx-folium/88563>\
**Category:** Visualization\
**Created:** [October 11, 2022, 8:59am UTC](https://discourse.julialang.org/t/openstreetmapx-folium/88563 "2022-10-11T08:59:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [October 11, 2022, 8:59am UTC](https://discourse.julialang.org/t/openstreetmapx-folium/88563/1 "2022-10-11T08:59:47Z")

</div>

I’m not sure this is the right place to post this but I’m trying to accomplish something like this: [OpenStreetMapX\_tutorial](https://pszufe.github.io/OpenStreetMapX_Tutorial/) but with real coordinates.

Anyways, my problems is that the end result of the loop

```julia
map = flm.Map()
for k ∈ length(routes)
    path_coords = [LLA(m.nodes[n], m.bounds) for n in routes[k]]
    
    info = "Route number $k\n<BR>" *
            "Length: $(length(routes[k])) nodes\n<br>" *
            "From $(routes[k][1]) $(round.((path_coords[1].lat, path_coords[1].lon), digits=4))<br>" *
            "To $(routes[k][end]) $(round.((path_coords[end].lat, path_coords[end].lon), digits=4))"
            
    flm.PolyLine(
        [(loc.lat, loc.lon) for loc in path_coords],
        popup=info,
        tooltip=info,
        color=matplotlib_colors.to_hex(cmap(k/SHOW_PATHS))
    ).add_to(map)
end

```

is to draw just the last path. It’s as if it doesn’t mutate the map instantiated outside the loop, but rather creates a new one with every `path_coords`. Here is a picture where the tooltip confirms to me that it is the last set of points

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/5/55a436eaaa563a593e18fc377253edcfae55244f.jpeg)

If step through them manually, like so

```julia
path_coords = [LLA(m.nodes[n], m.bounds) for n in routes[1]]
info = "Route number $(1)\n<BR>" *
        "Length: $(length(routes[1])) nodes\n<br>" *
        ...
flm.PolyLine(
    [(loc.lat, loc.lon) for loc in path_coords],
    popup=info,
        ...
).add_to(map)

```

I can draw them individually on a different map each. This is the first one, for instance:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/8/081bb5c452961582b90a4107dea692fc14d7d24b.jpeg)  
And here’s the fifth for completeness  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c49dcf2482c7cc6d6a12f91d0db8fbe440e25d1.jpeg)

Please let me know if this a sufficient working example…  
Here’s the map [Geofabrik Download Server](http://download.geofabrik.de/europe/spain/madrid.html)  
Here’s 10 coordinates

```julia
ptsOrig = [(40.40035, -3.70306), (40.47780807, -3.69849334), (40.4377299, -3.6800531), (40.4211153, -3.6879227), (40.41384654, -3.69493838), (40.471597, -3.682403), (40.48230943, -3.67061352), (40.4239884, -3.6864495), (40.406806, -3.691947), (40.44236981, -3.65546398)]

```

```julia
ptsDest = [(40.40647374, -3.68861037), (40.4766087, -3.6876792), (40.423677, -3.6848885), (40.4429993, -3.67984459), (40.42625779, -3.69331498), (40.4170684, -3.6756673), (40.40042329, -3.61914136), (40.43208461, -3.68719853), (40.4431324, -3.6743115), (40.43723621, -3.66986241)]

```

And the code I’ve used to make them conformable to OpenStreetMap

```julia
startEndNodes = collect(zip(
    [point_to_nodes(pt, mad) for pt in ptsOrig if inbounds(LLA(pt[1], pt[2]), mad.bounds) ],
    [point_to_nodes(pt, mad) for pt in ptsDest if inbounds(LLA(pt[1], pt[2]) , mad.bounds) ]
    ))

routes = Vector{Vector{Int}}()

for (s,e) in startEndNodes
    if s != e
        route, route_time = OpenStreetMapX.shortest_route(mad, s, e)
        if route_time < Inf
            push!(routes, route)
        end
    end
end

```

Please let me know if you need anything else, thanks!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 11, 2022, 11:12am UTC](https://discourse.julialang.org/t/openstreetmapx-folium/88563/2 "2022-10-11T11:12:37Z")

</div>

`for k ∈ length(routes)`

This iterates only the single number `routes`, classic Julia footgun 🙂 (numbers can be iterated as single-element collections)

You need `for k ∈ 1:length(routes)` or `for k ∈ eachindex(routes)`, for example.

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [October 11, 2022, 11:24am UTC](https://discourse.julialang.org/t/openstreetmapx-folium/88563/3 "2022-10-11T11:24:06Z")

</div>

Thank you!
