PluginProbe
Leaflet Map / 2.16.2
Leaflet Map v2.16.2
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / README.md

README.md in Leaflet Map 2.16.2, at README.md

337 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 # Leaflet Map WordPress Plugin
2
3 ![Leaflet](https://img.shields.io/badge/leaflet-1.6.0-green.svg?style=flat)
4 ![WordPress](https://img.shields.io/badge/wordpress-5.3.2-green.svg?style=flat)
5
6 ![Header Image](https://ps.w.org/leaflet-map/assets/banner-1544x500.png?rev=1693083)
7
8 Add a map generated with [](http://leafletjs.com/LeafletJS](http://leafletjs.com/](http://leafletjs.com/): an open-source JavaScript library for mobile-friendly interactive maps. Map tiles are provided by default through [](http://www.openstreetmap.org/OpenStreetMap](http://www.openstreetmap.org/](http://www.openstreetmap.org/), or [](https://www.mapquest.ca/MapQuest](https://www.mapquest.ca/](https://www.mapquest.ca/) (with an app key). Can be set per map with shortcode attributes or through the dashboard settings.
9
10 ![Admin Screenshot](https://imgur.com/W4BGTif.jpg)
11
12 ## Table of Contents
13
14 - [](#leaflet-map-wordpress-pluginLeaflet Map WordPress Plugin](#leaflet-map-wordpress-plugin](#leaflet-map-wordpress-plugin)
15 - [](#table-of-contentsTable of Contents](#table-of-contents](#table-of-contents)
16 - [](#installationInstallation](#installation](#installation)
17 - [](#general-usageGeneral Usage](#general-usage](#general-usage)
18 - [](#developingDeveloping](#developing](#developing)
19 - [](#available-shortcodesAvailable Shortcodes](#available-shortcodes](#available-shortcodes)
20 - [](#leaflet-map[leaflet-map]](#leaflet-map](#leaflet-map)
21 - [](#leaflet-map-options[leaflet-map] Options:](#leaflet-map-options](#leaflet-map-options)
22 - [](#leaflet-image[leaflet-image]](#leaflet-image](#leaflet-image)
23 - [](#leaflet-image-options[leaflet-image] Options:](#leaflet-image-options](#leaflet-image-options)
24 - [](#leaflet-marker[leaflet-marker]](#leaflet-marker](#leaflet-marker)
25 - [](#leaflet-marker-options[leaflet-marker] Options:](#leaflet-marker-options](#leaflet-marker-options)
26 - [](#leaflet-line[leaflet-line]](#leaflet-line](#leaflet-line)
27 - [](#leaflet-line-options[leaflet-line] Options](#leaflet-line-options](#leaflet-line-options)
28 - [](#leaflet-polygon[leaflet-polygon]](#leaflet-polygon](#leaflet-polygon)
29 - [](#leaflet-circle[leaflet-circle]](#leaflet-circle](#leaflet-circle)
30 - [](#leaflet-circle-options[leaflet-circle] Options](#leaflet-circle-options](#leaflet-circle-options)
31 - [](#leaflet-geojson[leaflet-geojson]](#leaflet-geojson](#leaflet-geojson)
32 - [](#leaflet-geojson-options[leaflet-geojson] Options](#leaflet-geojson-options](#leaflet-geojson-options)
33 - [](#leaflet-kml[leaflet-kml]](#leaflet-kml](#leaflet-kml)
34 - [](#leaflet-gpx[leaflet-gpx]](#leaflet-gpx](#leaflet-gpx)
35 - [](#frequently-asked-questionsFrequently Asked Questions](#frequently-asked-questions](#frequently-asked-questions)
36 - [](#how-can-i-add-another-leaflet-pluginHow Can I Add another Leaflet Plugin?](#how-can-i-add-another-leaflet-plugin](#how-can-i-add-another-leaflet-plugin)
37 - [](#contributingContributing](#contributing](#contributing)
38 - [](#wish-listWish List](#wish-list](#wish-list)
39
40 ## Installation
41
42 - (simple) Install via the WordPress plugins page on your WordPress site: `/wp-admin/plugin-install.php` (search Leaflet)
43
44 - (needlessly complicated) Copy this repo (or download a release of it) into your WordPress plugins directory: `/wp-content/plugins/`. You might also need to name the directory 'leaflet-map', like so: `git clone https://github.com/bozdoz/wp-plugin-leaflet-map.git leaflet-map`
45
46 ## General Usage
47
48 ```
49 [leaflet-map address="Manhattan, New York"]
50 [leaflet-marker]
51 ```
52
53 The above shortcode will produce a map centered at Manhattan, New York (thanks to geocoding), and also drop a marker in the center.
54
55 It's also useful to add popups to the markers:
56
57 ```
58 [leaflet-map address="Las Vegas"]
59 [leaflet-marker]Hey! This is where I got married![/leaflet-marker]
60 ```
61
62 You can have SVG markers, add shapes, geojson, kml, images, and more! See available shortcodes below.
63
64 ## Developing
65
66 This plugin uses Docker for development. Simply:
67
68 1. [](https://www.docker.com/get-startedinstall Docker](https://www.docker.com/get-started](https://www.docker.com/get-started)
69 1. fork/clone the repo, and
70 1. execute this command from the repo's root directory in your terminal:
71
72 ```bash
73 docker-compose up
74 ```
75
76 You should also have node and NPM installed if you want to edit JavaScript files, and need to minify them:
77
78 ```bash
79 npm install
80 npm run minify
81 ```
82
83 You can also use these NPM scripts to interact with Docker, if you make changes to Docker-related files:
84
85 To start:
86
87 ```bash
88 npm start
89 ```
90
91 To completely remove:
92
93 ```bash
94 npm run destroy
95 ```
96
97 That's all for now! Thanks!
98
99 ## Available Shortcodes
100
101 ### [leaflet-map]
102
103 ![Alternate map tiles](https://imgur.com/oURcNiX.jpg)
104
105 Height, width, latitude, longitude and zoom are the basic attributes:
106
107 ```
108 [leaflet-map height=250 width=250 lat=44.67 lng=-63.61 zoom=5]
109 ```
110
111 However, you can also just give it an address, and the chosen geocoder (default: Nominatum) will look it up for you:
112
113 ```
114 [leaflet-map address="Oslo, Norway"]
115 ```
116
117 #### [leaflet-map] Options:
118
119 | Option | Default |
120 | ---------------------------- | ----------------------- |
121 | `lat` and `lng` or `address` | lat: 44.67, lng: -63.61 |
122 | `zoom` | 12 |
123 | `height` | 250 |
124 | `width` | 100% |
125 | `fitbounds` | 0 (false) |
126 | `zoomcontrol` | 0 (false) |
127 | `scrollwheel` | 0 (false) |
128 | `doubleclickzoom` | 0 (false) |
129 | `min_zoom` | 0 |
130 | `max_zoom` | 20 |
131 | `subdomains` | abc |
132 | `attribution` | ©Leaflet ©OpenStreetMap |
133 | `closepopuponclick` | false |
134 | `trackresize` | false |
135 | `boxZoom` | true |
136 | `dragging` | true |
137 | `keyboard` | true |
138 | `maxbounds` | null |
139
140 ---
141
142 ### [leaflet-image]
143
144 Much the same as leaflet-map above, but uses `src` for the source image.
145
146 TBH, it's a huge mess, and probably shouldn't be used. It might make a good image viewer with optional marker highlight points. It requires far too much manual work at the moment. Recommended usage:
147
148 ```
149 [leaflet-image src="path/to/img.jpg" zoom=1]
150 [leaflet-marker draggable]
151 ```
152
153 Then in the console, check the coordinates when you move the marker (should only work at that zoom level).
154
155 #### [leaflet-image] Options:
156
157 | Option | Default |
158 | ----------------- | -------------------------------- |
159 | `src` | https://picsum.photos/1000/1000/ |
160 | `zoom` | 12 |
161 | `height` | 250 |
162 | `width` | 100% |
163 | `fitbounds` | 0 (false) |
164 | `zoomcontrol` | 0 (false) |
165 | `scrollwheel` | 0 (false) |
166 | `doubleclickzoom` | 0 (false) |
167 | `min_zoom` | 0 |
168 | `max_zoom` | 20 |
169 | `attribution` | ©Leaflet ©OpenStreetMap |
170
171 ---
172
173 ### [leaflet-marker]
174
175 ![Markers with HTML within a popup](https://imgur.com/ap38lwe.jpg)
176
177 Add a marker to any map by adding `[leaflet-marker]` after any `[leaflet-map]` shortcode. You can adjust the lat/lng in the same way, as well as some other basic functionality (popup message, draggable, visible on load). Also, if you want to add a link to a marker popup, use `[leaflet-marker]Message here: click here[/leaflet-marker]` and add a link like you normally would with the WordPress editor.
178
179 #### [leaflet-marker] Options:
180
181 | Option | Usage |
182 | ---------------------------- | ------------------------------------------------------------------------------------------ |
183 | `lat` and `lng` or `address` | Location on the map; defaults to map center; `lat`/`lng` are floats, `address` is a string |
184 | `draggable` | Make a marker draggable (`boolean`); default `false` |
185 | `title` | Add a hover-over message to your marker (different than popup) |
186 | `alt` | Add an alt text to the marker image |
187 | `zindexoffset` | Define the z-index for the marker image |
188 | `opacity` | Define the css opacity for the marker image |
189 | `iconurl` | Give a url for the marker image file |
190 | `iconsize` | Set the size of the icon: e.g. "80,50" for 80px width 50px height |
191 | `iconanchor` | Set the anchor position of the icon: e.g. "40,60" for 40px left 60px top |
192 | `shadowurl` | Give a url for the marker shadow image file |
193 | `shadowsize` | Set the size of the shadow: e.g. "80,50" for 80px width 50px height |
194 | `shadowanchor` | Set the anchor position of the shadow: e.g. "40,60" for 40px left 60px top |
195 | `popupanchor` | Set the anchor position of the popup: e.g. "40,60" for 40px left 60px top |
196 | `svg` | Boolean for whether the marker should be created as an svg: default `false` |
197 | `background` | Background color for an SVG marker (above) |
198 | `color` | color of the SVG marker (above) |
199 | `iconclass` | className for the marker image |
200
201 ---
202
203 ### [leaflet-line]
204
205 ![Fitted Colored Line](https://imgur.com/dixNDtF.jpg)
206
207 Add a line to the map by adding `[leaflet-line]`. You can specify the postions with a list separated by semi-colon `;` or bar `|` using lat/lng: `[leaflet-line latlngs="41, 29; 44, 18"]` or addresses: `[leaflet-line addresses="Istanbul; Sarajevo"]`, or x/y coordinates for image maps.
208
209 Add a popup to the line by adding text to the content of the shortcode:
210
211 `[leaflet-line addresses="new york; chicago"]New York to Chicago[/leaflet-line]`
212
213 #### [leaflet-line] Options
214
215 | Option | Usage |
216 | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
217 | `addresses`, `latlngs`, or `coordinates` | For geocoded addresses, latitude/longitude, or x/y coordinates for Image Maps; ex: `[leaflet-line latlngs="41, 29; 44, 18"]` or addresses: `[leaflet-line addresses="Istanbul; Sarajevo"]` |
218 | `fitbounds` | Fit the map to the bounds of the line (instead of whatever center you gave the map originally) |
219
220 And the following Shape Options. See https://leafletjs.com/reference-1.3.4.html#path for details.
221 'stroke', 'color', 'weight', 'opacity',
222 'lineCap', 'lineJoin', 'dashArray', 'dashOffset'
223 'fill', 'fillColor', 'fillOpacity', 'fillRule', 'className'
224
225 ---
226
227 ### [leaflet-polygon]
228
229 Virtually the same as [](aboveleaflet-line](above](above)
230
231 ---
232
233 ### [leaflet-circle]
234
235 ![Circle](https://i.imgur.com/rVHH6Zm.png?1234)
236
237 Add a circle to the map by adding `[leaflet-circle]`. You can specify the position using `lat` and `lng` and the radius in meters using `radius`. You can also customize the style using [](https://leafletjs.com/reference-1.3.4.html#path-optionLeaflet's Path options](https://leafletjs.com/reference-1.3.4.html#path-option](https://leafletjs.com/reference-1.3.4.html#path-option). Example: `[leaflet-circle message="max distance" lng=5.1179 lat=52.0979 radius=17500 color="#0DC143" fillOpacity=0.1]`.
238
239 #### [leaflet-circle] Options
240
241 | Options | Usage |
242 | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
243 | `address`, `lat/lng`, or `x/y` | For geocoded addresses, latitude/longitude, or x/y coordinates for Image Maps (see [leaflet-image]); ex: `[leaflet-circle lat=52 lng=5]` or addresses: `[leaflet-circle address="Amsterdam"]` |
244 | `fitbounds` | Fit the map to the bounds of the circle (instead of whatever center you gave the map originally) |
245 | radius | Radius of the circle in meters |
246
247 Includes all style options: See https://leafletjs.com/reference-1.3.4.html#path
248
249 ---
250
251 ### [leaflet-geojson]
252
253 [](https://gist.github.com/bozdoz/064a7101b95a324e8852fe9381ab9a18![Random GeoJSON created by me](https://imgur.com/fJktgtI.jpg)](https://gist.github.com/bozdoz/064a7101b95a324e8852fe9381ab9a18](https://gist.github.com/bozdoz/064a7101b95a324e8852fe9381ab9a18)
254
255 Or you can add a geojson shape via a url:
256
257 ```
258 [leaflet-geojson src="https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/03f4f54b13a3a7e256732760a8b679818d9d36fc/map.geojson"]
259 ```
260
261 #### [leaflet-geojson] Options
262
263 | Option | Usage |
264 | ---------------- | ------------------------------------------------------------------------------------------------ |
265 | `src` | Source of the geojson file |
266 | `popup_text` | Text for any popups when shapes are clicked |
267 | `popup_property` | Name of the geojson property that contains popup content |
268 | `fitbounds` | Fit the map to the bounds of all shapes (instead of whatever center you gave the map originally) |
269 | `circleMarker` | Display circles instead of markers. Vastly improves performance on maps with a lot of points. |
270 | `radius` | Radius of the circles, when `circleMarkers` is set |
271
272 Includes all style options: See https://leafletjs.com/reference-1.3.4.html#path. Also, if you want to add feature
273 properties to the popups, use the inner content and curly brackets to substitute the values:
274 `[leaflet-geojson]Field A = {field_a}[/leaflet-geojson]`.
275
276 ### [leaflet-kml]
277
278 Same idea as geojson (above), but takes KML files and loads [](https://github.com/mapbox/togeojsonMapbox's togeojson library](https://github.com/mapbox/togeojson](https://github.com/mapbox/togeojson)
279
280 ### [leaflet-gpx]
281
282 Same idea as geojson and KML (above), but takes GPX files and also loads [](https://github.com/mapbox/togeojsonMapbox's togeojson library](https://github.com/mapbox/togeojson](https://github.com/mapbox/togeojson)
283
284 ## Frequently Asked Questions
285
286 ### How Can I Add another Leaflet Plugin?
287
288 There are some steps you can take, currently, to add another Leaflet Plugin to enhance this WordPress plugin. In general, you can add an action to trigger when Leaflet is loaded, and add custom JavaScript and any dependencies your plugin needs:
289
290 Here's an example with MapBox Fullscreen plugin:
291
292 functions.php
293
294 ```php
295 add_action('leaflet_map_loaded', 'fs_leaflet_loaded');
296 function fs_leaflet_loaded() {
297 wp_enqueue_script('full_screen_leaflet', 'https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js', Array('wp_leaflet_map'), '1.0', true);
298 wp_enqueue_style('full_screen_leaflet_styles', 'https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css');
299
300 // custom js
301 wp_enqueue_script('full_screen_custom', get_theme_file_uri( '/js/full-screen.js' ), Array('full_screen_leaflet'), '1.0', true);
302 }
303 ```
304
305 /js/full-screen.js
306
307 ```js
308 (function() {
309 function main() {
310 if (!window.WPLeafletMapPlugin) {
311 console.log("no plugin found!");
312 return;
313 }
314
315 // iterate any of these: `maps`, `markers`, `markergroups`, `lines`, `circles`, `geojsons`
316 var maps = window.WPLeafletMapPlugin.maps;
317
318 for (var i = 0, len = maps.length; i < len; i++) {
319 var map = maps[i];
320 map.whenReady(function() {
321 this.addControl(new L.Control.Fullscreen());
322 });
323 }
324 }
325
326 window.addEventListener("load", main);
327 })();
328 ```
329
330 ## Contributing
331
332 [](https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/CONTRIBUTING.mdView Contribution guidelines](https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/CONTRIBUTING.md](https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/CONTRIBUTING.md)
333
334 ## Wish List
335
336 - A map editor/shortcode generator (so users can see what they're adding to the page)
337