Skip to content

Instantly share code, notes, and snippets.

@odoe
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/7c95ac549f9cd9e13d3a to your computer and use it in GitHub Desktop.
Save odoe/7c95ac549f9cd9e13d3a to your computer and use it in GitHub Desktop.
PureScript demo of LeafletJS
module Main where
import Debug.Trace
import Data.Foreign
import Data.Foreign.EasyFFI
import Control.Monad.Eff
foreign import data LMap :: *
foreign import data TileLayer :: *
foreign import data Mutable :: ! --need a mutable type to work with
ffi = unsafeForeignFunction
map' :: forall eff. String -> Eff (m :: Mutable | eff) LMap
map' = ffi ["s", ""] "L.map(s)"
setView :: forall eff. LMap -> [Number] -> Number -> Eff (_ :: Mutable | eff) LMap
setView = ffi ["map", "coords", "z", ""] "map.setView(coords, z)"
tileLayer :: forall eff. String -> Eff (_ :: Mutable | eff) TileLayer
tileLayer = ffi ["url", ""] "L.tileLayer(url)"
addTo :: forall eff. LMap -> TileLayer -> Eff (_ :: Mutable | eff) LMap
addTo = ffi ["map", "tileLayer", ""] "tileLayer.addTo(map)"
main = do
tlayer <- tileLayer "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
lmap <- map' "map"
setView lmap [51.505 (negate 0.09)] 13
addTo lmap tlayer
trace $ "created leaflet map"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment