├── LICENSE.txt
├── README.md
├── example
├── index.html
├── layerconfig.js
└── sample.geojson
├── package.json
├── sample.json
└── src
└── leaflet-layerconfig.js
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, NORKART AS
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Leaflet-LayerConfig
2 | ===================
3 |
4 | Library that communicates with a web service/reads a stored JavaScript object and adds layers to a leaflet map.
5 |
6 |
7 |
8 | ##Usage
9 | L.LayerConfig takes two arguments, the first one is either a URL or a object containing the information about the layers to add. A sample.json file is provided that shows some of the options available.
10 | The second argument is the map container or LayerGroup/FeatureGroup on which we add layers to.
11 |
12 | ```
13 | var layerConfig = L.layerConfig(object or url to json file, map);
14 | ```
15 |
16 | ##JSON notation
17 | The object containing the information is pretty basic, here is a sample file adding only a marker and setting the map view to a coordinate and a zoomlevel. You can also set bounds if you want to fit the map view to always show some objects.
18 | ```
19 | {
20 | "center": [63.43048, 10.39508],
21 | "zoom": 14,
22 | "layers": [
23 | {
24 | "type": "marker",
25 | "latLng": [63.43048, 10.39508],
26 | "popupContent": "Olavs statuen"
27 | }
28 | ]
29 | }
30 | ```
31 |
32 | To pass options to the layer simply add a options key to the layer. The options passed to the layer is in the same format as the Leaflet options found in the reference.
33 | Some option keys support functions if you want to pass a function to Leaflet through a web service you need to put it in a single line string. A minifier can help with that. This is because JSON does not support functions or multiline strings.
34 |
35 | ###Other supported layer types:
36 |
37 | ####GeoJSON
38 | This can either take an URL or a GeoJSON object
39 |
40 | ```
41 | {
42 | "type": "geojson",
43 | "url": "http://example.com/geojson-example.geojson",
44 | "options": {
45 | "style": "function () { return { color: \"red\" }; };"
46 | }
47 |
48 | }
49 | ```
50 |
51 | ```
52 | {
53 | "type": "geojson",
54 | "geojson": {
55 | "type": "FeatureCollection",
56 | "features": [
57 | {
58 | "type": "Feature",
59 | "geometry": {
60 | "type": "Point",
61 | "coordinates": [102.0, 0.6]
62 | },
63 | "properties": {
64 | "prop0": "value0"
65 | }
66 | }
67 | ]
68 | }
69 |
70 | }
71 | ```
72 | ####TileLayer
73 | ```
74 | {
75 | "type": "tilelayer",
76 | "url": "http://b.tiles.mapbox.com/v3/torbjornav.hhni5j5f/{z}/{x}/{y}.png",
77 | "options": {
78 | "attribution": "Mapbox"
79 | }
80 | }
81 | ```
82 | ####WMS
83 | ```
84 | {
85 | "type": "wms",
86 | "url": "URL-TO-WMS",
87 | "options": {
88 | //WMS OPTIONS GO HERE
89 | }
90 | }
91 | ```
92 | ####PolyLine
93 | ```
94 | {
95 | "type": "line",
96 | "path": [[63.43182, 10.39195],[63.42526, 10.3937]],
97 | "popupContent": "Prinsens gate"
98 | }
99 | ```
100 | ####Polygon
101 | ```
102 | {
103 | "type": "polygon",
104 | "path": [[[63.42639, 10.38975],[63.42564, 10.39006],
105 | [63.42570, 10.39194],[63.42643, 10.39183],
106 | [63.42639, 10.38975]]]
107 | }
108 | ```
109 | ####Rectangle
110 | ```
111 | {
112 | "type": "rectangle",
113 | "path": [[63.42647, 10.39694],[63.42554, 10.39508]],
114 | "options": {
115 |
116 | "color": "red"
117 |
118 | }
119 | }
120 | ```
121 | ####Circle
122 | ```
123 | {
124 | "type": "circle",
125 | "latLng": [63.43055, 10.39273],
126 | "radius": 10
127 | }
128 | ```
129 | ####CircleMarker
130 | ```
131 | {
132 | "type": "circlemarker",
133 | "latLng": [63.43034, 10.38647]
134 | }
135 | ```
136 |
137 | ####FeatureGroup
138 | FeatureGroup has a "layer" key containing the layers to be added to it. This is in the same format as the top-level layer key.
139 | ```
140 | {
141 | "type": "featuregroup",
142 | "layers": [
143 | {
144 | "type": "marker",
145 | "latLng": [63.43027, 10.40094]
146 | },
147 | {
148 | "type": "circle",
149 | "latLng": [63.43055, 10.39273],
150 | "radius": 10
151 | },
152 | {
153 | "type": "circlemarker",
154 | "latLng": [63.43034, 10.38647]
155 | }
156 |
157 | ],
158 | "popupContent": "Kongens gate"
159 | }
160 | ```
161 | ####LayerGroup
162 | LayerGroup has a "layer" key containing the layers to be added to it. This is in the same format as the top-level layer key.
163 | ```
164 | {
165 | "type": "layergroup",
166 | "layers": [
167 | {
168 | "type": "marker",
169 | "latLng": [63.43027, 10.40094]
170 | },
171 | {
172 | "type": "circle",
173 | "latLng": [63.43055, 10.39273],
174 | "radius": 10
175 | },
176 | {
177 | "type": "circlemarker",
178 | "latLng": [63.43034, 10.38647]
179 | }
180 |
181 | ]
182 | }
183 | ```
184 | ###Events
185 | Leaflet-LayerConfig fires various events.
186 |
187 | | Name | Description |
188 | | ---- | ----------- |
189 | | startLayerLoading |Fired when the JSON object is read and we're ready to start loading layers |
190 | | stopLayerLoading | Fired when all layers has been loaded |
191 | | LayerLoaded | Fired when a layer has been added. Passes the Leaflet layer, type of layer and the name of the layer with the event object |
192 | | GroupLoadingStart | Fired when we start loading layers to a group. Passes the group to the layer |
193 | | GroupLoadingEnd | Fired when we have loaded all sub-layers to a group |
194 |
195 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |