Skip to content

Commit b65fe2c

Browse files
Add example
1 parent 342216b commit b65fe2c

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

example/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/.psci*
6+
/src/.webpack.js

example/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example
2+
## Download dependencies
3+
Install the dependencies listed in `bower.json` file.
4+
5+
```
6+
$ bower install dependencies
7+
```
8+
9+
Compile the project.
10+
11+
```
12+
pulp browserify --optimise --to dist/example.js
13+
```
14+
15+
Open `dist/index.html`.
16+

example/bower.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"moduleType": [
5+
"node"
6+
],
7+
"ignore": [
8+
"**/.*",
9+
"node_modules",
10+
"bower_components",
11+
"output"
12+
],
13+
"dependencies": {
14+
"purescript-console": "^0.1.0",
15+
"purescript-leaflet": "*"
16+
}
17+
}

example/dist/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>PureScript Leaflet example</title>
5+
<link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.css" />
6+
<script src="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.js"></script>
7+
<style>
8+
#mapid { height: 380px; width: 600px; }
9+
</style>
10+
</head>
11+
<body>
12+
<div id="mapid"></div>
13+
<script src="example.js"></script>
14+
</body>
15+
</html>

example/src/Main.purs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Main where
2+
3+
import Prelude (bind, negate)
4+
import Control.Monad.Eff (Eff)
5+
6+
import Leaflet.Map (createMap)
7+
import Leaflet.Types
8+
( URL
9+
, LatLng
10+
, LatLngBounds
11+
, MapOptions
12+
, TileLayer
13+
, TileLayerOptions)
14+
import Leaflet.LatLng (latLng)
15+
import Leaflet.LatLngBounds (latLngBounds)
16+
import Leaflet.TileLayer (tileLayer)
17+
import Leaflet.Layer (addTo)
18+
19+
defCenter :: LatLng
20+
defCenter = latLng (-0.09349) (-78.43276)
21+
22+
minBound :: LatLng
23+
minBound = latLng (-100.0) (-100.0)
24+
25+
maxBound :: LatLng
26+
maxBound = latLng 100000.0 10000000.0
27+
28+
defMaxBounds :: LatLngBounds
29+
defMaxBounds = latLngBounds minBound maxBound
30+
31+
defMapOps :: MapOptions
32+
defMapOps =
33+
{
34+
attributionControl : true,
35+
center : defCenter,
36+
layers : [],
37+
maxBounds : defMaxBounds,
38+
zoom : 16
39+
}
40+
41+
osmURL :: URL
42+
osmURL = "http://{s}.tile.osm.org/{z}/{x}/{y}.png"
43+
44+
osmSubdomains :: Array String
45+
osmSubdomains = [ "a", "b", "c" ]
46+
47+
defTileLayerOptions :: TileLayerOptions (attribution :: String)
48+
defTileLayerOptions =
49+
{ subdomains : osmSubdomains
50+
, attribution: "&copy; <a href=\"http://osm.org/copyright\">OpenStreetMap</a> contributors"
51+
}
52+
53+
main :: forall e. Eff e TileLayer
54+
main = do
55+
defTileLayer <- tileLayer osmURL defTileLayerOptions
56+
myMap <- createMap "mapid" defMapOps
57+
addTo defTileLayer myMap
58+

0 commit comments

Comments
 (0)