Commit 4b14c990 authored by Steffen Michels's avatar Steffen Michels

Merge branch '284-leaflet-maps-svg-markers' into 'master'

Resolve "Leaflet maps: SVG markers"

Closes #286 and #284

See merge request !248
parents 37fc7f35 da82597d
Pipeline #22614 passed with stage
in 9 minutes and 48 seconds
definition module iTasks.Extensions.GIS.Leaflet
import iTasks
from Text.HTML import :: SVGElt
leafletEditor :: Editor LeafletMap
......@@ -113,6 +114,9 @@ leafletObjectIdOf :: !LeafletObject -> LeafletObjectID
:: LeafletWindowPos = { x :: !Int, y :: !Int }
//Inline SVG based icons can be encoded as 'data uri's' which can be used instead of a url to an external icon image
svgIconURL :: !SVGElt !(!Int,!Int) -> String
//Public tileserver of openstreetmaps
openStreetMapTiles :: String
......
......@@ -4,7 +4,8 @@ import iTasks
import iTasks.UI.Definition, iTasks.UI.Editor, iTasks.UI.JavaScript
import StdMisc, Data.Tuple, Data.Error, Data.Func, Text, Data.Functor
import qualified Data.Map as DM
from Text.HTML import instance toString HtmlTag
from Text.HTML import instance toString HtmlTag, instance toString SVGElt
from Text.Encodings.Base64 import base64Encode
from iTasks.UI.Editor.Common import diffChildren, :: ChildUpdate (..)
import StdArray
......@@ -63,6 +64,12 @@ leafletObjectIdOf (Window w) = w.windowId
| UpdateCircle !LeafletLatLng !Real
| UpdateRectangle !LeafletBounds
svgIconURL :: !SVGElt !(!Int,!Int) -> String
svgIconURL svgelt (width,height) = "data:image/svg+xml;base64," +++ base64Encode svg
where
svg = concat ["<svg xmlns=\"http://www.w3.org/2000/svg\" width=\""
, toString width, "\" height=\"", toString height, "\">", toString svgelt, "</svg>"]
openStreetMapTiles :: String
openStreetMapTiles = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
......
......@@ -2,12 +2,9 @@ implementation module iTasks.Extensions.GIS.LeafletNavalIcons
/**
* This module provides a set of naval icons to use with leaflet maps
*/
from iTasks.Extensions.GIS.Leaflet import :: LeafletIcon(..), :: LeafletIconID(..)
from iTasks.Extensions.GIS.Leaflet import :: LeafletIcon(..), :: LeafletIconID(..), svgIconURL
from StdFunc import o
import StdString, StdInt, StdList, Data.Maybe, Text
URL (LeafletIconID iconId) :== concat ["/leaflet-naval-icons/", iconId, ".png"]
SIZE :== (24,24)
import StdString, StdInt, StdList, Data.Maybe, Text, Text.HTML
instance toString ShipIconColor
where
......@@ -19,12 +16,31 @@ where
//Add this list to your leaflet map
shipIcons :: [LeafletIcon]
shipIcons = [let iconId = shipIconId heading color sel in {LeafletIcon|iconId=iconId, iconUrl=URL iconId,iconSize = SIZE}
\\ color <- colors, heading <- headings, sel <- selected]
shipIcons =
[let iconId = shipIconId heading color sel in
{LeafletIcon|iconId=iconId, iconUrl= svgIconURL (shipIconSVG color heading sel) (24,24), iconSize = (24,24)}
\\ color <- colors, heading <- headings, sel <- selected]
where
selected = [True,False]
colors = [GrayShip,BlueShip,OrangeShip,GreenShip,RedShip]
headings = [Nothing: map Just [0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345]]
shipIconSVG color mbHeading sel = GElt [WidthAttr "24",HeightAttr "24"] [] [maybe moored ship mbHeading: if sel [selection] []]
where
ship heading = PolygonElt
[WidthAttr "24",HeightAttr "24",StyleAttr ("fill:" +++ toString color +++ ";stroke:black;stroke-width:1")]
[PointsAttr [(toString x, toString y) \\ (x,y) <- [(8,11),(11,3),(14,3),(17,11),(17,19),(8,19)]]
,TransformAttr [RotateTransform (toString heading) (Just ("12","12"))]
]
moored = PolygonElt
[WidthAttr "24",HeightAttr "24",StyleAttr ("fill:" +++ toString color +++ ";stroke:black;stroke-width:1")]
[PointsAttr [(toString x, toString y) \\ (x,y) <- [(7,7),(17,7),(17,17),(7,17)]]
]
selection = PolygonElt
[WidthAttr "24",HeightAttr "24",StyleAttr "fill:none;stroke:black;stroke-width:2"]
[PointsAttr [(toString x,toString y) \\ (x,y) <- [(1,1),(1,23),(23,23),(23,1)]]
]
/**
* Find the right icon based on a heading and color
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment