-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapbox integration #89
Comments
The solution we have for D3 is really hacky and not something I'd recommend to anyone. |
Thanks @et1975! In all cases thanks for your help! |
@whitetigle I'm not sure, but I think the Ref( fun x ->
if x <> null then
printfn ("init map")
Mapbox.AccessToken <- "my.access.token"
Mapbox.Map("mapid","mapbox.streets") |> ignore
else
printfn "remove map"
// Remove map
) Reference: https://facebook.github.io/react/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element
|
Thanks @alfonsogarciacaro However, I still miss a proper strategy to store the current state, aka my map object. let root model dispatch =
div
[
Id "mapid"
Ref( fun x ->
if x <> null then
printfn "init map"
Mapbox.AccessToken <- "my.access.token"
let map = Mapbox.Map("mapid","mapbox.streets")
// update model
MountMap map |> dispatch
else
printfn "remove map"
match model with
| Some (ma : MapboxMap) ->
ma.off()
ma.remove()
| None ->
printfn ("no map") )
] [] If I use dispatch to update my model, it updates the view with |
Ah no excuse me! |
Ok here is the flow:
which gives us: let root model dispatch =
div
[
Id "mapid"
Ref( fun x ->
if x <> null then
printfn "mount"
match model with
| None ->
Mapbox.AccessToken <- "my.access.token"
let map = Mapbox.Map("mapid","mapbox.streets")
MountMap map |> dispatch
| _ ->
printfn "Map object already initialied. Nothing to do"
else
printfn "unmount"
match model with
| Some (ma : MapboxMap) ->
ma.remove()
| None ->
printfn ("no map") ][] And so it works on mount. 👍 However on unmount, it fails because, if I understand well, the container has already been destroyed when Ref is called, so before I even make my call to map.remove() which leads to this error:
At this point, I thinks it's time for me to drink a 🍺 |
Since you have the reference to the map in your model, you could call |
I put my call to remove the map when on urlUpdate and it works! code used in let urlUpdate (result: Option<Page>) model =
let model =
match model.map with
| Some map ->
map.off()
map.remove()
{ model with map = None }
| None -> model
... And just for sharing here's my current Mapbox integration Thanks again for your help guys! 👍 |
Hi,
I'm trying to make my mind around the integration of a mapbox component into the elmish architecture.
So currently, a mapbox component is rendered to a known HtmlElement. Following our discussion of yesterday, I've tried to initialize my map when the View is ready by using
Ref
. Therefore the mapbox map is correctly appended.Now my problem arises on unmount since I would like to destroy the mapbox component (= calling
map.remove()
, not removing the actual Html element) when I render a new view.The leaflet component exists in the DOM and has it's own lifecycle independant on the VDom.
So my question is: where should I store a reference to my map component so that I can call map.remove()? In a more generic fashion, what would be the best architecture for this kind of problem?
Thanks!
The text was updated successfully, but these errors were encountered: