HSlippyMap 1.8 → 2.0
raw patch · 4 files changed
+79/−20 lines, 4 files
Files
- HSlippyMap.cabal +1/−1
- HSlippyMap.hs +37/−11
- README.md +22/−0
- hsl.hs +19/−8
HSlippyMap.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: HSlippyMap-version: 1.8+version: 2.0 synopsis: OpenStreetMap Slippy Map -- description: homepage: https://github.com/j4/HSlippyMap
HSlippyMap.hs view
@@ -1,5 +1,21 @@+{--+let tl=tileFromLatLong 48.90 1.80 10+let tr=tileFromLatLong 48.90 2.62 10+let br=tileFromLatLong 48.70 2.70 10+let bl=tileFromLatLong 48.70 2.80 10++let max = tileFromLatLong 48.9031 2.5214 10+let min = tileFromLatLong 48.8146 2.1732 10++ [(x,[11266..11278]) | x <- [16581..16613]]++map (\(x,y) -> map (\y'-> "/15/" ++ show x ++ "/" ++ show y' ++ ".png") y) [(x,[11266..11278]) | x <- [16581..16613]]+map (\(x,y) -> map (\y'-> "http//http://tile.openstreetmap.org/" ++ show zlevel ++ "/" ++ show x ++ "/" ++ show y' ++ ".png") y) [(x,[11266..11278]) | x <- [16581..16613]]++--}+ module HSlippyMap (- Tile,+ Tile, tlat, tlong, tx, ty, tz, tileFromLatLong, tileFromXY ) where@@ -11,15 +27,25 @@ type ZLevel = Integer data Tile = Tile {- lat :: Lat,- long :: Long,- x :: X,- y :: Y,- z :: ZLevel }+ tlat :: Lat,+ tlong :: Long,+ tx :: X,+ ty :: Y,+ tz :: ZLevel } deriving (Read, Eq) instance Show Tile where show (Tile lat long x y z) = "http://tile.openstreetmap.org/" ++ show z ++ "/" ++ show x ++ "/" ++ show y ++ ".png" +-- ajouter un test si z1 == z2 puis maybe+tilesFromBBox :: Tile -> Tile -> [Tile]+tilesFromBBox min max = concat $ map (\(x,y) -> map (\y'-> Tile (tlat min) (tlong min) x y' z) y) [(x,[(minimum [tymin, tymax])..(maximum [tymin,tymax])]) | x <- [(minimum [txmin, txmax])..(maximum [txmin, txmax])]]+ where+ txmax = tx max+ txmin = tx min+ tymax = ty min+ tymin = ty min + z = tz min+ tileFromLatLong :: Lat -> Long -> ZLevel -> Tile tileFromLatLong lat lon z = Tile lat lon x y z where@@ -32,12 +58,12 @@ lat = tilex2long x z lon = tiley2lat y z -long2tilex lon z = floor((lon + 180) / 360 * (2** fromInteger(z)::Long))+long2tilex lon z = floor((lon + 180) / 360 * (2** fromInteger z::Long)) -lat2tiley lat z = floor((1.0 - log( tan(lat * pi/180.0) + 1.0 / cos(lat * pi/180.0)) / pi) / 2.0 * (2 ** fromInteger(z)::Long))+lat2tiley lat z = floor((1.0 - log( tan(lat * pi/180.0) + 1.0 / cos(lat * pi/180.0)) / pi) / 2.0 * (2 ** fromInteger z::Long)) -tilex2long x z = (fromInteger(x)::Long) / (2.0 ** fromInteger(z)::Long) * 360.0 - 180+tilex2long x z = (fromInteger x::Long) / (2.0 ** fromInteger z::Long) * 360.0 - 180 -tiley2lat y z = 180.0 / pi * atan(0.5 * (exp(n) - exp(-n)))+tiley2lat y z = 180.0 / pi * atan(0.5 * (exp n - exp(-n))) where- n = pi - 2.0 * pi * (fromInteger(y)::Long) / (2.0 ** fromInteger(z)::Long)+ n = pi - 2.0 * pi * (fromInteger y::Long) / (2.0 ** fromInteger z::Long)
README.md view
@@ -4,6 +4,28 @@ mapM (\z-> putStrLn $ show $ tileFromLatLong 12.3 3.3 z) [0..18] ``` +```+http://tile.openstreetmap.org/0/0/0.png+http://tile.openstreetmap.org/1/1/0.png+http://tile.openstreetmap.org/2/2/1.png+http://tile.openstreetmap.org/3/4/2.png+http://tile.openstreetmap.org/4/8/5.png+http://tile.openstreetmap.org/5/16/11.png+http://tile.openstreetmap.org/6/32/22.png+http://tile.openstreetmap.org/7/64/44.png+http://tile.openstreetmap.org/8/129/88.png+http://tile.openstreetmap.org/9/259/176.png+http://tile.openstreetmap.org/10/518/352.png+http://tile.openstreetmap.org/11/1036/704.png+http://tile.openstreetmap.org/12/2073/1409.png+http://tile.openstreetmap.org/13/4147/2819.png+http://tile.openstreetmap.org/14/8295/5639.png+http://tile.openstreetmap.org/15/16590/11278.png+http://tile.openstreetmap.org/16/33181/22557.png+http://tile.openstreetmap.org/17/66362/45115.png+http://tile.openstreetmap.org/18/132725/90230.png+```+ ```haskell long2tilex lon z = floor((lon + 180.0) / 360.0 * (2.0 ** z))
hsl.hs view
@@ -1,11 +1,22 @@+-- HSlippyMap Exemple import HSlippyMap -main = do- putStrLn $ show $ tileFromLatLong lat long z- putStrLn $ show $ tileFromXY x y z+{--+let max = tileFromLatLong 48.9031 2.5214 10+let min = tileFromLatLong 48.8146 2.1732 10+mapM (\(x,y) -> mapM (\y'-> print $ "http://tile.openstreetmap.org/" ++ show z ++ "/" \+++ show x ++ "/" ++ show y' ++ ".png") y) [(x,[(minimum [tymin, tymax])..(maximum [tymin\+,tymax])]) | x <- [(minimum [txmin, txmax])..(maximum [txmin, txmax])]]+--}++main = do + --mapM (print . show . tileFromLatLong lat long) [0..18]+ mapM (\(x,y) -> mapM (\y'-> print $ "http://tile.openstreetmap.org/" ++ show z ++ "/" ++ show x ++ "/" ++ show y' ++ ".png") y) [(x,[(minimum [tymin, tymax])..(maximum [tymin,tymax])]) | x <- [(minimum [txmin, txmax])..(maximum [txmin, txmax])]] where- lat = 48.8152- long = 2.2712- x = 66362- y = 45115- z = 19+ min = tileFromLatLong 49.13 3.05 8+ max = tileFromLatLong 48.57 1.66 8+ txmin = tx min+ txmax = tx max+ tymax = ty min+ tymin = ty max+ z = tz min