Created
September 22, 2014 20:06
-
-
Save runarorama/e2c3a206c94c00e12ed7 to your computer and use it in GitHub Desktop.
Interactive location plot of busses in Iceland
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Block[{}, | |
BusData[bus_] := | |
"results" /. First[Import[StringJoin["http://apis.is/bus/realtime?busses=", bus], "JSON"]]; | |
AllBusData := "results" /. First[Import["http://apis.is/bus/realtime?busses=", "JSON"]]; | |
Dist[{x_ -> y_, a_ -> b_}] := (Flatten[{#1, a -> b}] & ) /@ y; | |
CommaSep[xs_] := StringTemplate["<*Row[`1`,\",\"]*>"][xs]; | |
Busses[bus_] := Cases[Flatten[Dist /@ BusData[CommaSep[bus]], 1], | |
{__, "to" -> to_, __, "x" -> x_, "y" -> y_, "busNr" -> n_} -> | |
Tooltip[GeoPosition[{x, y}], n*to], Infinity]; | |
AllBusses := "busNr" /. AllBusData; | |
Manipulate[ | |
GeoListPlot[ | |
Busses[{Bus}], | |
GeoBackground -> GeoStyling["StreetMap"], | |
ImageSize -> Large, | |
GeoRange -> City, | |
GeoRangePadding -> Quantity[4, "Kilometers"]], | |
{Bus, AllBusses}, | |
{City, { | |
Entity["City", {"Reykjavik", "Hofudhborgarsvaedhi", "Iceland"}], | |
Entity["City", {"Kopavogur", "Hofudhborgarsvaedhi", "Iceland"}], | |
Entity["City", {"Hafnarfjordhur", "Hofudhborgarsvaedhi", "Iceland"}], | |
Entity["City", {"Mosfellsbaer", "Hofudhborgarsvaedhi", "Iceland"}], | |
Entity["City", {"Akureyri", "NordhurlandEystra", "Iceland"}], | |
Entity["Airport", "BIKF"]}}]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment