Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Elm 0.19 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions elm-package.json

This file was deleted.

23 changes: 23 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
20 changes: 11 additions & 9 deletions examples/CustomMarkers.elm
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -30,8 +32,8 @@ type alias SportsGround =
, kind : String
}

main = program
{ init = init
main = Browser.element
{ init = (\() -> init)
, update = update
, subscriptions = subscriptions
, view = view
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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", "🏉")
Expand Down
7 changes: 3 additions & 4 deletions examples/Example.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module Example exposing (..)

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
Expand Down
23 changes: 13 additions & 10 deletions examples/Fullscreen.elm
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
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
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
}

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
Expand All @@ -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 =
Expand Down
9 changes: 5 additions & 4 deletions examples/Markers.elm
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions examples/elm-package.json

This file was deleted.

33 changes: 33 additions & 0 deletions examples/elm.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
4 changes: 2 additions & 2 deletions src/Maps.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
-}
Expand Down
4 changes: 2 additions & 2 deletions src/Maps/Geo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 12 additions & 12 deletions src/Maps/Internal/Bounds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ 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)
radX2 lat = (logBase e ((1 + latY lat) / (1 - latY lat))) / 2
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
Loading