This post is the start of a series about Elm and Google Maps, but the key learning from my initial ‘quick and dirty’ approach was how to use ports with the ubiquitous Elm Architecture.
To start with I’m going to use Javascript externally from Elm to load a map, and just leave Elm to handle the modeling of the map position. In practise, we’ll build a way to pan from the South to the North of France.
Elm land
Javascript land
The button simply causes the model to increment.
The magic - such as it is - comes from pushing the updated model back out to Javascript land. I have Peter Damoc to thank on the forums for help, but in Main.Elm I have added a new port.
When the code is run, StartApp.start is called, but so too, in parallel, is port lat. This ‘subscribes’ to the Signal of my model, and extracts the latitude value each time the model changes.
In Javascript land it is then a simple matter of subscribing to the port, and updating the map.