{-|
Module      :  OpenLayers Wrapper mothership
Description :  combine OpenLayers with Fay
-}
module OpenLayers where

import           Prelude hiding (void)
import           OpenLayers.Func (setDefaultView, setTarget)
import           OpenLayers.Internal
import           Fay.Text
import           OlApp (targetId, designMap)
import           Fay.FFI

-- | Adds an default naked OpenLayers Map Object
addDefaultMap :: Fay ()
addDefaultMap = ffi "olmap = new ol.Map({renderer: 'canvas'})"
{-|
  Initialises an object of the OpenLayers Map as HTML object.
  The variable name \"olc\" must be reserved for the whole website!
-}
defineCode :: Fay ()
defineCode = ffi "olc = $(olmap)[0]"
-- | Initialises an OpenLayers View and load the definitions from the OpenLayers Webapplication defined in "OlApp"
olwrapperLoad :: Fay ()
olwrapperLoad = void $ do
    addDefaultMap
    defineCode
    setTarget targetId
    setDefaultView
    designMap