Take a unique ID for maps.
I want to be able to share this without giving away my data. The page takes a query parameter map=<ID>, which says which data file to load. If you load the page without a map ID, it makes up a random 8-digit hex string and uses that. The no-selection view shows a link to the map.
This commit is contained in:
parent
5d69d2cad7
commit
fe963ec2db
6 changed files with 67 additions and 28 deletions
16
src/App.elm
16
src/App.elm
|
@ -50,6 +50,7 @@ type MapCentre
|
|||
type alias Model =
|
||||
{ markers : List Marker
|
||||
, emoji : List Emoji
|
||||
, map_id : String
|
||||
, current_position : LatLon
|
||||
, selection : Selection
|
||||
, new_marker : Marker
|
||||
|
@ -60,7 +61,8 @@ type alias Model =
|
|||
init_model =
|
||||
{ markers = []
|
||||
, emoji = []
|
||||
, current_position = {lat = 55.05155870729228, lon = -1.4652193740914812}
|
||||
, map_id = ""
|
||||
, current_position = {lat = 55.04, lon = -1.46}
|
||||
, selection = NoSelection
|
||||
, new_marker = blank_marker
|
||||
, accuracy = 0
|
||||
|
@ -91,18 +93,20 @@ decode_emoji =
|
|||
type alias Flags =
|
||||
{ emoji : List Emoji
|
||||
, markers : List Marker
|
||||
, map_id : String
|
||||
}
|
||||
|
||||
decode_flags =
|
||||
JD.map2 Flags
|
||||
JD.map3 Flags
|
||||
(JD.field "emoji" (JD.list decode_emoji))
|
||||
(JD.field "markers" (JD.list decode_marker))
|
||||
(JD.field "map_id" JD.string)
|
||||
|
||||
init : (JD.Value) -> (Model, Cmd msg)
|
||||
init vflags =
|
||||
(case JD.decodeValue decode_flags vflags of
|
||||
Err _ -> init_model
|
||||
Ok flags -> { init_model | emoji = flags.emoji, markers = flags.markers }
|
||||
Ok flags -> { init_model | emoji = flags.emoji, markers = flags.markers, map_id = flags.map_id }
|
||||
) |> nocmd
|
||||
|
||||
nocmd m = (m, Cmd.none)
|
||||
|
@ -387,6 +391,12 @@ view model =
|
|||
)
|
||||
(closest_markers |> List.take 3)
|
||||
)
|
||||
, H.p
|
||||
[]
|
||||
[ H.a
|
||||
[ HA.href <| "?map=" ++ model.map_id ]
|
||||
[ H.text "🔗 Link to this map" ]
|
||||
]
|
||||
]
|
||||
|
||||
closest_markers =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue