From 60081233bad286507aaab9bc8c3bce09d69110b5 Mon Sep 17 00:00:00 2001 From: Matthew Dupree Date: Mon, 8 Oct 2018 21:02:46 +0200 Subject: [PATCH 1/2] Update code so all tests pass on Elm 0.19 --- elm-package.json | 22 ------------- elm.json | 23 +++++++++++++ examples/CustomMarkers.elm | 20 ++++++------ examples/Example.elm | 7 ++-- examples/Fullscreen.elm | 23 +++++++------ examples/Markers.elm | 9 +++--- examples/elm-package.json | 21 ------------ examples/elm.json | 33 +++++++++++++++++++ src/Maps.elm | 4 +-- src/Maps/Geo.elm | 4 +-- src/Maps/Internal/Bounds.elm | 24 +++++++------- src/Maps/Internal/Drag.elm | 38 +++++++++++----------- src/Maps/Internal/Map.elm | 18 +++++------ src/Maps/Internal/Maps.elm | 62 +++++++++++++++++------------------- src/Maps/Internal/Marker.elm | 24 ++++++-------- src/Maps/Internal/Pinch.elm | 12 +++---- src/Maps/Internal/Tile.elm | 29 ++++++++++------- src/Maps/Internal/Utils.elm | 6 ++++ src/Maps/Internal/Zoom.elm | 22 ++++++------- src/Maps/Map.elm | 2 +- tests/Expects.elm | 20 ++++++++---- tests/Fuzzers.elm | 21 ++++++------ tests/elm-package.json | 22 ------------- 23 files changed, 240 insertions(+), 226 deletions(-) delete mode 100644 elm-package.json create mode 100644 elm.json delete mode 100644 examples/elm-package.json create mode 100644 examples/elm.json delete mode 100644 tests/elm-package.json diff --git a/elm-package.json b/elm-package.json deleted file mode 100644 index f9824c0..0000000 --- a/elm-package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "4.2.2", - "summary": "An Elm library for interactive maps", - "repository": "https://github.com/kennib/elm-maps.git", - "license": "BSD3", - "source-directories": [ - "src" - ], - "exposed-modules": [ - "Maps", - "Maps.Geo", - "Maps.Map", - "Maps.Marker", - "Maps.Convert" - ], - "dependencies": { - "elm-community/list-extra": "6.1.0 <= v < 7.0.0", - "elm-lang/core": "5.1.1 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/elm.json b/elm.json new file mode 100644 index 0000000..f535131 --- /dev/null +++ b/elm.json @@ -0,0 +1,23 @@ +{ + "type": "package", + "name": "kennib/elm-maps", + "summary": "An Elm library for interactive maps", + "license": "BSD-3-Clause", + "version": "4.2.2", + "exposed-modules": [ + "Maps", + "Maps.Geo", + "Maps.Map", + "Maps.Marker", + "Maps.Convert" + ], + "elm-version": "0.19.0 <= v < 0.20.0", + "dependencies": { + "elm/browser": "1.0.0 <= v < 2.0.0", + "elm/core": "1.0.0 <= v < 2.0.0", + "elm/html": "1.0.0 <= v < 2.0.0", + "elm/regex": "1.0.0 <= v < 2.0.0", + "elm-explorations/test": "1.1.0 <= v < 2.0.0" + }, + "test-dependencies": {} +} \ No newline at end of file diff --git a/examples/CustomMarkers.elm b/examples/CustomMarkers.elm index 0ca0dc9..88a9066 100644 --- a/examples/CustomMarkers.elm +++ b/examples/CustomMarkers.elm @@ -1,6 +1,8 @@ module CustomMarkers exposing (..) -import Html exposing (program) +import Browser + +import Html import Html.Attributes as Attr import Html.Events exposing (onClick) @@ -30,8 +32,8 @@ type alias SportsGround = , kind : String } -main = program - { init = init +main = Browser.element + { init = (\() -> init) , update = update , subscriptions = subscriptions , view = view @@ -60,9 +62,9 @@ subscriptions model = update msg model = case msg of - MapsMsg msg -> + MapsMsg thismsg -> model.map - |> Maps.update msg + |> Maps.update thismsg |> Tuple.mapFirst (\map -> { model | map = map }) |> Tuple.mapSecond (Cmd.map MapsMsg) Select ground -> @@ -104,17 +106,17 @@ resultToSportsGrounds result = groundMarker : SportsGround -> Marker Msg groundMarker ground = let - view = + thisview = Html.span - [ onClick <| Select ground, Attr.style [("cursor", "pointer")] ] + [ onClick <| Select ground, Attr.style "cursor" "pointer" ] [ Html.text <| groundSymbol ground.kind ] in - Marker.createCustom view ground.latLng + Marker.createCustom thisview ground.latLng groundSymbol : String -> String groundSymbol kind = let - symbol (name, symbol) = if String.contains name kind then symbol else "" + symbol (name, thissymbol) = if String.contains name kind then thissymbol else "" default defaultString string = if String.isEmpty string then defaultString else string in [ ("Football", "🏉") diff --git a/examples/Example.elm b/examples/Example.elm index 1dd463e..506c72d 100644 --- a/examples/Example.elm +++ b/examples/Example.elm @@ -1,11 +1,12 @@ module Example exposing (..) -import Html exposing (program) +import Html +import Browser import Maps -main = program - { init = (Maps.defaultModel, Cmd.none) +main = Browser.element + { init = (\() -> (Maps.defaultModel, Cmd.none)) , subscriptions = Maps.subscriptions , update = Maps.update , view = Maps.view diff --git a/examples/Fullscreen.elm b/examples/Fullscreen.elm index 62a8bf6..58659fd 100644 --- a/examples/Fullscreen.elm +++ b/examples/Fullscreen.elm @@ -1,9 +1,12 @@ module FullScreen exposing (..) import Task -import Window +import Browser.Dom -import Html exposing (program) +import Browser +import Browser.Dom +import Browser.Events +import Html import Html.Events exposing (onInput) import Maps @@ -11,10 +14,10 @@ import Maps.Map as Map type Msg = MapMsg (Maps.Msg ()) - | Resize Window.Size + | Resize {width:Int,height:Int} -main = program - { init = init +main = Browser.element + { init = (\() -> init) , update = update , subscriptions = subscriptions , view = view @@ -22,16 +25,16 @@ main = program init = ( Maps.defaultModel - , Task.attempt (Result.withDefault defaultSize >> Resize) Window.size + , Task.attempt (Result.map .scene >> Result.map (\s -> {width=floor s.width,height=floor s.height}) >> Result.withDefault defaultSize >> Resize) Browser.Dom.getViewport ) defaultSize = - Window.Size 500 500 + {width=500,height=500} update msg model = case msg of - MapMsg msg -> - Maps.update msg model + MapMsg thismsg -> + Maps.update thismsg model |> Tuple.mapSecond (Cmd.map MapMsg) Resize size -> ( model @@ -43,7 +46,7 @@ update msg model = subscriptions model = Sub.batch [ Sub.map MapMsg <| Maps.subscriptions model - , Window.resizes Resize + , Browser.Events.onResize (\w h -> Resize {width=w,height=h}) ] view model = diff --git a/examples/Markers.elm b/examples/Markers.elm index 166c0d9..ff2bf7f 100644 --- a/examples/Markers.elm +++ b/examples/Markers.elm @@ -1,14 +1,15 @@ module Markers exposing (..) -import Html exposing (program) +import Html +import Browser import Maps import Maps.Geo import Maps.Map as Map import Maps.Marker as Marker -main = program - { init = init +main = Browser.element + { init = \() -> init , update = Maps.update , subscriptions = Maps.subscriptions , view = Maps.view @@ -25,7 +26,7 @@ init = sydney = Maps.Geo.latLng -33.865143 151.209900 attractions = - List.map (uncurry Maps.Geo.latLng) + List.map (\(lat,lng) -> Maps.Geo.latLng lat lng) [ (-33.852324, 151.210819) , (-33.856872, 151.215239) , (-33.870397, 151.208835) diff --git a/examples/elm-package.json b/examples/elm-package.json deleted file mode 100644 index 67233bb..0000000 --- a/examples/elm-package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Examples for the elm-maps library.", - "repository": "https://github.com/kennib/elm-maps.git", - "license": "BSD3", - "source-directories": [ - ".", - "../src" - ], - "exposed-modules": [], - "dependencies": { - "elm-community/list-extra": "6.1.0 <= v < 7.0.0", - "elm-lang/core": "5.1.1 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0", - "elm-lang/http": "1.0.0 <= v < 2.0.0", - "elm-lang/window": "1.0.1 <= v < 2.0.0", - "labzero/elm-google-geocoding": "4.0.1 <= v < 5.0.0", - "mgold/elm-geojson": "2.0.0 <= v < 3.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/examples/elm.json b/examples/elm.json new file mode 100644 index 0000000..b532c56 --- /dev/null +++ b/examples/elm.json @@ -0,0 +1,33 @@ +{ + "version": "1.0.0", + "summary": "Examples for the elm-maps library.", + "repository": "https://github.com/kennib/elm-maps.git", + "license": "BSD3", + "type": "application", + "source-directories": [ + ".", + "../src" + ], + "elm-version": "0.19.0", + "dependencies": { + "direct": { + "elm/browser": "1.0.0", + "elm/core": "1.0.0", + "elm/html": "1.0.0", + "elm/http": "1.0.0", + "elm/json": "1.0.0", + "elm/regex": "1.0.0", + "elm-community/list-extra": "8.0.0", + "mgold/elm-geojson": "2.0.1" + }, + "indirect": { + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} \ No newline at end of file diff --git a/src/Maps.elm b/src/Maps.elm index c7b3df8..3a03ea3 100644 --- a/src/Maps.elm +++ b/src/Maps.elm @@ -73,7 +73,7 @@ For example, set the width/height of a map and zoom into Seoul, South Korea: See [Maps.Map](./Maps-Map) for documentation of the Map functions. -} updateMap : (Map -> Map) -> Model msg -> Model msg -updateMap update = opaqueModel <| Maps.updateMap <| transparentMap update +updateMap thisupdate = opaqueModel <| Maps.updateMap <| transparentMap thisupdate {-| Change the markers inside of the model @@ -98,7 +98,7 @@ For example, add markers for some Sydney attractions and then another marker for See [Maps.Marker](./Maps-Marker) for documentation of the Marker functions. -} updateMarkers : (List (Marker msg) -> List (Marker msg)) -> Model msg -> Model msg -updateMarkers update = opaqueModel <| Maps.updateMarkers update +updateMarkers thisupdate = opaqueModel <| Maps.updateMarkers thisupdate {-| The default model is a map zoomed into Sydney, Australia with no markers. -} diff --git a/src/Maps/Geo.elm b/src/Maps/Geo.elm index 0b46fdd..c4bc2ee 100644 --- a/src/Maps/Geo.elm +++ b/src/Maps/Geo.elm @@ -73,8 +73,8 @@ For example, zoomed into the streets of Baku, Azerbaijan: (latLng 40.409264 49.867092) -} centeredBounds : Float -> LatLng -> Bounds -centeredBounds zoom latLng = +centeredBounds zoom thislatLng = Bounds.Centered { zoom = zoom - , center = latLng + , center = thislatLng } diff --git a/src/Maps/Internal/Bounds.elm b/src/Maps/Internal/Bounds.elm index 628e898..2f0226e 100644 --- a/src/Maps/Internal/Bounds.elm +++ b/src/Maps/Internal/Bounds.elm @@ -39,9 +39,9 @@ Note that the size of the tiles and map are needed to calculate the zoom level. zoom : Float -> Float -> Float -> Bounds -> ZoomLevel zoom tileSize mapWidth mapHeight bounds = case bounds of - Bounds bounds -> + Bounds thesebounds -> let - (ne, sw) = (bounds.northEast, bounds.southWest) + (ne, sw) = (thesebounds.northEast, thesebounds.southWest) -- The following assumes a Mercator projection -- See https://en.wikipedia.org/wiki/Mercator_projection#Alternative_expressions for details latY lat = sin (lat * pi / 180) @@ -49,22 +49,22 @@ zoom tileSize mapWidth mapHeight bounds = latRad lat = (max (-pi) <| min (radX2 lat) pi) / 2 latFraction = (latRad ne.lat) - (latRad sw.lat) lngFraction = ((ne.lng - sw.lng) |> wrap 0 360) / 360 - zoom mapSize tileSize frac = logBase 2 (mapSize / tileSize / frac) + thiszoom mapSize thistileSize frac = logBase 2 (mapSize / thistileSize / frac) in min - (zoom mapWidth tileSize lngFraction) - (zoom mapHeight tileSize latFraction) - Centered bounds -> - bounds.zoom + (thiszoom mapWidth tileSize lngFraction) + (thiszoom mapHeight tileSize latFraction) + Centered thesebounds -> + thesebounds.zoom {-| Calculates the center point of a given Bounds. -} center : Bounds -> LatLng center bounds = case bounds of - Bounds bounds -> - { lat = (bounds.northEast.lat + bounds.southWest.lat) / 2 - , lng = (bounds.northEast.lng + bounds.southWest.lng) / 2 + Bounds thesebounds -> + { lat = (thesebounds.northEast.lat + thesebounds.southWest.lat) / 2 + , lng = (thesebounds.northEast.lng + thesebounds.southWest.lng) / 2 } - Centered bounds -> - bounds.center + Centered thesebounds -> + thesebounds.center diff --git a/src/Maps/Internal/Drag.elm b/src/Maps/Internal/Drag.elm index ea30812..d0b52a1 100644 --- a/src/Maps/Internal/Drag.elm +++ b/src/Maps/Internal/Drag.elm @@ -10,7 +10,7 @@ module Maps.Internal.Drag exposing import Json.Decode as Json import Html -import Html.Events exposing (on, onWithOptions, defaultOptions, onMouseUp) +import Html.Events exposing (on, onMouseUp) import Maps.Internal.Screen as Screen @@ -28,25 +28,25 @@ start : Screen.Offset -> Drag start = StartDrag drag : Screen.Offset -> Drag -> Drag -drag offset state = +drag thisoffset state = case state of - StartDrag start -> Drag start offset - Drag start end -> Drag end offset + StartDrag thisstart -> Drag thisstart thisoffset + Drag thisstart thisend -> Drag thisend thisoffset offset : Drag -> Screen.Offset -offset drag = - case drag of +offset thisdrag = + case thisdrag of StartDrag _ -> { x = 0, y = 0 } - Drag start end -> - { x = end.x - start.x, y = end.y - start.y } + Drag thisstart thisend -> + { x = thisend.x - thisstart.x, y = thisend.y - thisstart.y } events : EventOptions msg -> Maybe Drag -> List (Html.Attribute msg) -events ({dragStart, dragTo, dragStop}) drag = +events ({dragStart, dragTo, dragStop}) thisdrag = [ -- Mouse - if drag == Nothing then - onWithOptions "mousedown" - { defaultOptions | preventDefault = True } + if thisdrag == Nothing then + Html.Events.preventDefaultOn "mousedown" + <| Json.map2 (\b a -> (a,b)) (Json.succeed True) <| Json.map dragStart <| Screen.decodeOffset else @@ -56,18 +56,18 @@ events ({dragStart, dragTo, dragStop}) drag = , -- Mouse onMouseUp dragStop , -- Mobile - if drag == Nothing then - onWithOptions "touchstart" - { defaultOptions | preventDefault = True } + if thisdrag == Nothing then + Html.Events.preventDefaultOn "touchstart" + <| Json.map2 (\b a -> (a,b)) (Json.succeed True) <| Json.map dragStart <| Screen.decodeOffset else - onWithOptions "touchmove" - { defaultOptions | preventDefault = True } + Html.Events.preventDefaultOn "touchmove" + <| Json.map2 (\b a -> (a,b)) (Json.succeed True) <| Json.map dragTo <| Screen.decodeOffset , -- Mobile - onWithOptions "touchend" - { defaultOptions | preventDefault = True } + Html.Events.preventDefaultOn "touchend" + <| Json.map2 (\b a -> (a,b)) (Json.succeed True) <| Json.succeed dragStop ] diff --git a/src/Maps/Internal/Map.elm b/src/Maps/Internal/Map.elm index bac5a81..15ee861 100644 --- a/src/Maps/Internal/Map.elm +++ b/src/Maps/Internal/Map.elm @@ -92,11 +92,11 @@ setTileSize tileSize map = { map | tileSize = tileSize } {-| Moves the map the number of pixels given by the offset. -} move : Screen.Offset -> Map -> Map -move offset map = +move thisoffset map = let - centerOffset offset = Screen.Offset (map.width/2 - offset.x) (map.height/2 - offset.y) + centerOffset otheroffset = Screen.Offset (map.width/2 - otheroffset.x) (map.height/2 - otheroffset.y) in - { map | center = Screen.offsetToLatLng map <| centerOffset offset } + { map | center = Screen.offsetToLatLng map <| centerOffset thisoffset } moveTo : LatLng -> Map -> Map moveTo latLng map = @@ -127,9 +127,9 @@ zoomTo zoomLevel offset map = viewBounds : Bounds -> Map -> Map viewBounds bounds map = let - zoom = Bounds.zoom map.tileSize map.width map.height bounds + thiszoom = Bounds.zoom map.tileSize map.width map.height bounds in - { map | zoom = zoom, center = Bounds.center bounds } + { map | zoom = thiszoom, center = Bounds.center bounds } {-| Applies a drag (like a mouse drag) to the map -} @@ -150,7 +150,7 @@ diff newMap oldMap = (Screen.offsetFromLatLng newMap oldMap.center) (Screen.offsetFromLatLng newMap newMap.center) , Scaled - <| (\zoom -> 2^zoom) + <| (\thiszoom -> 2^thiszoom) <| toFloat <| (-) (ceiling newMap.zoom) @@ -190,14 +190,14 @@ transformationStyle mapWidth mapHeight transforms = transformations transform = case transform of Moved offset -> - "translate("++toString offset.x++"px, "++toString offset.y++"px)" + "translate("++String.fromFloat offset.x++"px, "++String.fromFloat offset.y++"px)" Scaled scale -> - "scale("++toString scale++")" + "scale("++String.fromFloat scale++")" style = transforms |> List.map transformations |> String.join " " in - [ ("transform-origin", toString (mapWidth/2)++"px "++toString (mapHeight/2)++"px") + [ ("transform-origin", String.fromFloat (mapWidth/2)++"px "++String.fromFloat (mapHeight/2)++"px") , ("transform", style) ] diff --git a/src/Maps/Internal/Maps.elm b/src/Maps/Internal/Maps.elm index b47df79..1b832da 100644 --- a/src/Maps/Internal/Maps.elm +++ b/src/Maps/Internal/Maps.elm @@ -39,10 +39,10 @@ import List.Extra as List import Json.Decode as Json -import Html exposing (Html, program) +import Html exposing (Html) import Html.Keyed import Html.Attributes as Attr -import Html.Events exposing (onWithOptions) +import Html.Events import Maps.Internal.Map as Map exposing (Map) import Maps.Internal.Screen as Screen exposing (Offset, TwoFingers, ZoomLevel) @@ -52,6 +52,7 @@ import Maps.Internal.Marker as Marker exposing (Marker) import Maps.Internal.Tile as Tile exposing (Tile) import Maps.Internal.Drag as Drag exposing (Drag) import Maps.Internal.Pinch as Pinch exposing (Pinch) +import Maps.Internal.Utils exposing (flip) import Maps.Internal.Zoom as Zoom {-| The map has events for dragging, zooming and setting the bounds displayed by the map. @@ -79,16 +80,16 @@ type alias Model msg = } updateMap : (Map -> Map) -> Model msg -> Model msg -updateMap update model = +updateMap thisupdate model = { model - | map = update model.map + | map = thisupdate model.map , cache = model.map :: model.cache |> List.uniqueBy (.zoom >> ceiling) } updateMarkers : (List (Marker msg) -> List (Marker msg)) -> Model msg -> Model msg -updateMarkers update model = +updateMarkers thisupdate model = { model - | markers = update model.markers + | markers = thisupdate model.markers } {-| A default model that displays Open Street Map tiles looking at Sydney. @@ -149,13 +150,13 @@ update msg model = zoom = Maybe.map (Zoom.fromPinch model.map.width model.map.height) model.pinch pinchedMap map = case zoom of - Just (zoom, offset) -> Map.zoomTo zoom offset map + Just (thiszoom, offset) -> Map.zoomTo thiszoom offset map Nothing -> map in (updateMap pinchedMap { model | pinch = Nothing }, Cmd.none) Zoom offset zoom -> (updateMap (Map.zoomTo zoom offset) model, Cmd.none) - ExternalMsg msg -> + ExternalMsg othermsg -> (model, Cmd.none) {-| -} @@ -167,9 +168,9 @@ subscriptions map = view : Model msg -> Html (Msg msg) view ({map, cache, markers, pinch, drag} as model) = Html.div - ([ Attr.style - [ ("width", toString map.width ++ "px") - , ("height", toString map.height ++ "px") + (( List.map (\(p,v) -> Attr.style p v) + [ ("width", String.fromFloat map.width ++ "px") + , ("height", String.fromFloat map.height ++ "px") , ("-webkit-touch-callout", "none") , ("-webkit-user-select", "none") , ("-khtml-user-select", "none") @@ -178,49 +179,46 @@ view ({map, cache, markers, pinch, drag} as model) = , ("user-select", "none") , ("background-color", "#ddd") ] - ] - ++ zoomEvents map.zoom + ) ++ zoomEvents map.zoom ) <| let zoom = Maybe.map (Zoom.fromPinch map.width map.height) pinch - zoomedMap = Maybe.withDefault map <| Maybe.map (\(zoom, offset) -> Map.zoomTo zoom offset map) zoom + zoomedMap = Maybe.withDefault map <| Maybe.map (\(thiszoom, offset) -> Map.zoomTo thiszoom offset map) zoom transforms = Map.diff zoomedMap map in [ Html.div - [ Attr.style - [ ("position", "absolute") - , ("width", toString map.width ++ "px") - , ("height", toString map.height ++ "px") - , ("overflow", "hidden") - ] - , onWithOptions "mouseDown" - { preventDefault = True, stopPropagation = False } + [ Attr.style "position" "absolute" + , Attr.style "width" <| String.fromFloat map.width ++ "px" + , Attr.style "height" <| String.fromFloat map.height ++ "px" + , Attr.style "overflow" "hidden" + , Html.Events.custom "mouseDown" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.fail "No interaction" ] <| List.map (\cachedMap -> tilesView (Map.diff zoomedMap cachedMap) cachedMap) <| List.reverse <| cache , Html.div - ([ Attr.style + (( List.map (\(p,v) -> Attr.style p v) [ ("position", "absolute") - , ("width", toString map.width ++ "px") - , ("height", toString map.height ++ "px") + , ("width", String.fromFloat map.width ++ "px") + , ("height", String.fromFloat map.height ++ "px") , ("overflow", "hidden") ] - ] ++ dragEvents drag + ) ++ dragEvents drag ) [ tilesView transforms map ] , Html.div - [ Attr.style + ( List.map (\(p,v) -> Attr.style p v) [ ("position", "absolute") - , ("width", toString map.width ++ "px") - , ("height", toString map.height ++ "px") + , ("width", String.fromFloat map.width ++ "px") + , ("height", String.fromFloat map.height ++ "px") , ("overflow", "hidden") , ("pointer-events", "none") ] - ] + ) <| List.map (Html.map ExternalMsg) <| List.map (Marker.view zoomedMap) <| markers @@ -233,14 +231,14 @@ mapView wrapMsg html = mapMsg mapsMsg = case mapsMsg of ExternalMsg msg -> msg - mapsMsg -> wrapMsg mapsMsg + thismapsMsg -> wrapMsg thismapsMsg in Html.map mapMsg html tilesView : List Map.Transformation -> Map -> Html (Msg msg) tilesView transforms map = Html.Keyed.node "div" - [ Attr.style <| Map.transformationStyle map.width map.height <| transforms ] + ( List.map (\(p,v) -> Attr.style p v) <| Map.transformationStyle map.width map.height <| transforms ) <| List.map (\((url, offset) as tile) -> (url, Tile.view map.tileSize tile)) <| Map.tiles map diff --git a/src/Maps/Internal/Marker.elm b/src/Maps/Internal/Marker.elm index a0fc29a..3ff621a 100644 --- a/src/Maps/Internal/Marker.elm +++ b/src/Maps/Internal/Marker.elm @@ -23,28 +23,26 @@ view map marker = height = 36 in Html.span - [ Attr.style + ( List.map (\(p,v) -> Attr.style p v) [ ("position", "absolute") - , ("left", toString (offset.x - width/2) ++ "px") - , ("top", toString (offset.y - height) ++ "px") + , ("left", String.fromFloat (offset.x - width/2) ++ "px") + , ("top", String.fromFloat (offset.y - height) ++ "px") , ("display", "inline-block") - , ("width", toString width ++ "px") - , ("height", toString height ++ "px") + , ("width", String.fromFloat width ++ "px") + , ("height", String.fromFloat height ++ "px") , ("background-image", "url(\"data:image/svg+xml;utf-8,"++markerSvg++"\")") , ("background-size", "100% auto") ] - ] - [ - ] + ) [] CustomMarker html latLng -> let offset = Screen.offsetFromLatLng map latLng in Html.span - [ Attr.style + ( List.map (\(p,v) -> Attr.style p v) [ ("position", "absolute") - , ("left", toString offset.x ++ "px") - , ("top", toString offset.y ++ "px") + , ("left", String.fromFloat offset.x ++ "px") + , ("top", String.fromFloat offset.y ++ "px") , ("pointer-events", "initial") , ("display", "inline-block") , ("text-align", "center") @@ -52,9 +50,7 @@ view map marker = , ("-moz-transform", "translateX(-50%) translateY(-50%)") , ("transform", "translateX(-50%) translateY(-50%)") ] - ] - [ html - ] + ) [ html ] markerSvg = """""" diff --git a/src/Maps/Internal/Pinch.elm b/src/Maps/Internal/Pinch.elm index 8b0f78c..71e9cd0 100644 --- a/src/Maps/Internal/Pinch.elm +++ b/src/Maps/Internal/Pinch.elm @@ -17,11 +17,11 @@ start = StartPinch pinch : TwoFingers -> Pinch -> Pinch pinch twoFingers state = case state of - StartPinch start -> Pinch start twoFingers - Pinch start end -> Pinch start twoFingers + StartPinch thisstart -> Pinch thisstart twoFingers + Pinch thisstart end -> Pinch thisstart twoFingers startEnd : Pinch -> (TwoFingers, TwoFingers) -startEnd pinch = - case pinch of - StartPinch start -> (start, start) - Pinch start end -> (start, end) +startEnd thispinch = + case thispinch of + StartPinch thisstart -> (thisstart, thisstart) + Pinch thisstart end -> (thisstart, end) diff --git a/src/Maps/Internal/Tile.elm b/src/Maps/Internal/Tile.elm index 31330f4..26e823d 100644 --- a/src/Maps/Internal/Tile.elm +++ b/src/Maps/Internal/Tile.elm @@ -7,7 +7,7 @@ module Maps.Internal.Tile exposing , view ) -import Regex exposing (HowMany(..), regex) +import Regex import Html exposing (Html) import Html.Attributes as Attr @@ -52,19 +52,24 @@ toLatLng zoom tileX tileY = formatInt : String -> Int -> String -> String formatInt replace number = - Regex.replace All (regex replace) (\_ -> toString number) + let + attemptedRegex = Regex.fromString replace + in + case attemptedRegex of + Just regex -> + Regex.replace regex (\_ -> String.fromInt number) + Nothing -> + identity view : Float -> Tile -> Html msg -view tileSize (url, offset) = +view tileSize (thisUrl, offset) = Html.img - [ Attr.src url - , Attr.style - [ ("position", "absolute") - , ("left", toString offset.x ++ "px") - , ("top", toString offset.y ++ "px") - , ("width", toString tileSize ++ "px") - , ("height", toString tileSize ++ "px") - , ("background-color", "rgba(0,0,0, 0)") - ] + [ Attr.src thisUrl + , Attr.style "position" "absolute" + , Attr.style "left" <| String.fromFloat offset.x ++ "px" + , Attr.style "top" <| String.fromFloat offset.y ++ "px" + , Attr.style "width" <| String.fromFloat tileSize ++ "px" + , Attr.style "height" <| String.fromFloat tileSize ++ "px" + , Attr.style "background-color" <| "rgba(0,0,0, 0)" ] [] diff --git a/src/Maps/Internal/Utils.elm b/src/Maps/Internal/Utils.elm index 8b99196..a95ed17 100644 --- a/src/Maps/Internal/Utils.elm +++ b/src/Maps/Internal/Utils.elm @@ -2,6 +2,7 @@ module Maps.Internal.Utils exposing ( wrap , sinh , cartesianMap + , flip ) wrap min max n = @@ -15,6 +16,11 @@ wrap min max n = sinh x = ((e ^ x) - (e ^ -x)) / 2 +flip : (a -> b -> c) -> (b -> a -> c) +flip f b a = + f a b + + cartesianMap : (a -> b -> c) -> List a -> List b -> List (List c) cartesianMap function rows columns = (flip function) diff --git a/src/Maps/Internal/Zoom.elm b/src/Maps/Internal/Zoom.elm index 3db2d83..38232b9 100644 --- a/src/Maps/Internal/Zoom.elm +++ b/src/Maps/Internal/Zoom.elm @@ -7,7 +7,7 @@ module Maps.Internal.Zoom exposing import Json.Decode as Json import Html -import Html.Events exposing (on, onWithOptions) +import Html.Events exposing (on) import Maps.Internal.Screen as Screen exposing (ZoomLevel) import Maps.Internal.Pinch as Pinch exposing (Pinch) @@ -31,31 +31,31 @@ fromPinch mapWidth mapHeight pinch = events : EventOptions msg -> ZoomLevel -> List (Html.Attribute msg) events ({zoom, pinchStart, pinchTo, pinchStop}) mapZoom = [ -- Mouse - onWithOptions "dblclick" - { preventDefault = True, stopPropagation = False } + Html.Events.custom "dblclick" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.map (\offset -> zoom offset 1) <| Screen.decodeOffset , --Mouse - onWithOptions "wheel" - { preventDefault = True, stopPropagation = False } + Html.Events.custom "wheel" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.map2 zoom Screen.decodeOffset Screen.decodeZoom , -- Mobile - onWithOptions "touchstart" - { preventDefault = True, stopPropagation = False } + Html.Events.custom "touchstart" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.map (Maybe.withDefault pinchStop) <| Json.map (Maybe.map pinchStart) <| Screen.decodeTwoFingers , -- Mobile - onWithOptions "touchmove" - { preventDefault = True, stopPropagation = False } + Html.Events.custom "touchmove" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.map (Maybe.withDefault pinchStop) <| Json.map (Maybe.map pinchTo) <| Screen.decodeTwoFingers , -- Mobile - onWithOptions "touchend" - { preventDefault = True, stopPropagation = False } + Html.Events.custom "touchend" + <| Json.map (\v -> { message = v, preventDefault = True, stopPropagation = False }) <| Json.succeed pinchStop ] diff --git a/src/Maps/Map.elm b/src/Maps/Map.elm index 49f9da6..5c428e8 100644 --- a/src/Maps/Map.elm +++ b/src/Maps/Map.elm @@ -126,7 +126,7 @@ For example, zoom into the top left corner of the map: |> zoom 1 { x = 0, y = 0} -} zoomTo : Float -> Screen.Offset -> Map -> Map -zoomTo zoom offset = opaqueMap <| Map.zoomTo zoom offset +zoomTo thiszoom offset = opaqueMap <| Map.zoomTo thiszoom offset {-| Move and zoom the map to cover given the bounds. diff --git a/tests/Expects.elm b/tests/Expects.elm index 77bc6be..3e672f1 100644 --- a/tests/Expects.elm +++ b/tests/Expects.elm @@ -12,7 +12,7 @@ import Maps.Internal.LatLng exposing (LatLng) import Maps.Internal.Screen exposing (Offset) equalMap : Float -> Map -> Map -> Expectation -equalMap delta mapA mapB = +equalMap delta mapAs mapBs = Expect.all [ \(mapA, mapB) -> Expect.equal mapA.tileServer mapB.tileServer , \(mapA, mapB) -> Expect.equal mapA.zoom mapB.zoom @@ -21,7 +21,7 @@ equalMap delta mapA mapB = , \(mapA, mapB) -> Expect.equal mapA.height mapB.height , \(mapA, mapB) -> Expect.equal mapA.tileSize mapB.tileSize ] - (mapA, mapB) + (mapAs, mapBs) equalLatLng : Float -> LatLng -> LatLng -> Expectation equalLatLng delta latLngA latLngB = @@ -30,10 +30,14 @@ equalLatLng delta latLngA latLngB = lngDiff = abs <| (latLngA.lng |> wrap -180 180) - (latLngB.lng |> wrap -180 180) in Expect.true - ("Expected the two offsets to be within "++toString delta++"\n" - ++ toString latLngA ++ "\n" ++ toString latLngB) + ("Expected the two offsets to be within "++String.fromFloat delta++"\n" + ++ latLngToString latLngA ++ "\n" ++ latLngToString latLngB) <| latDiff < delta && lngDiff < delta +latLngToString : LatLng -> String +latLngToString {lat,lng} = + "{ lat = "++String.fromFloat lat++", lng = "++String.fromFloat lng++" }" + equalOffsets : Float -> Offset -> Offset -> Expectation equalOffsets delta offsetA offsetB = let @@ -41,6 +45,10 @@ equalOffsets delta offsetA offsetB = yDiff = abs <| offsetA.y - offsetB.y in Expect.true - ("Expected the two offsets to be within "++toString delta++"\n" - ++ toString offsetA ++ "\n" ++ toString offsetB) + ("Expected the two offsets to be within "++String.fromFloat delta++"\n" + ++ offsetToString offsetA ++ "\n" ++ offsetToString offsetB) <| xDiff < delta && yDiff < delta + +offsetToString : Offset -> String +offsetToString {x,y} = + "{ x = "++String.fromFloat x++", y = "++String.fromFloat y++" }" diff --git a/tests/Fuzzers.elm b/tests/Fuzzers.elm index 3ec34d8..d6ca615 100644 --- a/tests/Fuzzers.elm +++ b/tests/Fuzzers.elm @@ -9,8 +9,7 @@ module Fuzzers exposing import Fuzz exposing (..) import Shrink -import Random.Pcg as Random -import Lazy.List exposing ((:::), empty) +import Random import Maps.Internal.Screen as Screen exposing (ZoomLevel) import Maps.Internal.LatLng exposing (LatLng) @@ -59,20 +58,24 @@ lng = signedRange -180 180 signedRange min max = + Fuzz.floatRange min max +{-- +Old signedRange implementation Fuzz.custom (Random.float min max) (shrinkSignedRange min max) +--} shrinkSignedRange min max val = if val == min || val == max || val == 0 then - empty + [] else if val < min then - min ::: empty + min :: [] else if val > max then - max ::: empty - else if floor val /= val || ceiling val /= val then - (toFloat <| floor val) ::: 0 ::: empty + max :: [] + else if Basics.toFloat (floor val) /= val || Basics.toFloat (ceiling val) /= val then + (toFloat <| floor val) :: 0 :: [] else if val < 0 then - (toFloat <| floor val // 2) ::: empty + (toFloat <| floor val // 2) :: [] else - empty + [] diff --git a/tests/elm-package.json b/tests/elm-package.json deleted file mode 100644 index 1134091..0000000 --- a/tests/elm-package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Test Suites", - "repository": "https://github.com/kennib/elm-maps.git", - "license": "BSD3", - "source-directories": [ - "../src", - "." - ], - "exposed-modules": [], - "dependencies": { - "eeue56/elm-html-test": "4.1.0 <= v < 5.0.0", - "elm-community/elm-test": "4.0.0 <= v < 5.0.0", - "elm-community/lazy-list": "1.0.0 <= v < 2.0.0", - "elm-community/list-extra": "6.1.0 <= v < 7.0.0", - "elm-community/shrink": "2.0.0 <= v < 3.0.0", - "elm-lang/core": "5.1.1 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0", - "mgold/elm-random-pcg": "5.0.0 <= v < 6.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} From 1779c2d25a81189baef2b64b979450682b4261fe Mon Sep 17 00:00:00 2001 From: Matthew Dupree Date: Mon, 8 Oct 2018 21:06:06 +0200 Subject: [PATCH 2/2] Update Example to use Browser instead of HTML --- README.md | 8 ++++---- examples/Example.elm | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8319294..7cb19df 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ An elm library for interactive maps. It's very simple to get create a map with this library ```elm - import Maps - import Html exposing (program) + import Browser + import Maps - main = program - { init = (Maps.defaultModel, Cmd.none) + main = Browser.element + { init = (\() -> (Maps.defaultModel, Cmd.none)) , subscriptions = Maps.subscriptions , update = Maps.update , view = Maps.view diff --git a/examples/Example.elm b/examples/Example.elm index 506c72d..bf65ec9 100644 --- a/examples/Example.elm +++ b/examples/Example.elm @@ -1,8 +1,6 @@ module Example exposing (..) -import Html import Browser - import Maps main = Browser.element