├── .eslintrc.js
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── circle.yml
├── index.html
├── index.js
├── leaflet-image.js
├── package.json
├── site.js
└── test
├── out
├── circle-marker.png
├── no-tiles.png
├── one-point-oh.png
├── osm.png
├── simple.png
├── style-layer.png
└── wms.png
├── pages
├── circle-marker.html
├── no-tiles.html
├── one-point-oh.html
├── osm.html
├── shared
│ └── style.css
├── simple.html
├── style-layer.html
└── wms.html
└── test.js
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "commonjs": true
5 | },
6 | "extends": "eslint:recommended",
7 | "rules": {
8 | "indent": [
9 | "error",
10 | 4
11 | ],
12 | "linebreak-style": [
13 | "error",
14 | "unix"
15 | ],
16 | "quotes": [
17 | "error",
18 | "single"
19 | ],
20 | "semi": [
21 | "error",
22 | "always"
23 | ]
24 | }
25 | };
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
3 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Before you post an issue, please review this document! Many of your questions,
2 | like "why isn't leaflet-image working" or "will it work with a plugin",
3 | are answered below.
4 |
5 | ## Requirements
6 |
7 | * Tile layer providers (OSM, MapBox, etc) must support [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
8 | * Any markers on the map must also support CORS. The default Leaflet-CDN markers
9 | don't, so they aren't supported.
10 | * Your browser must support [CORS](http://caniuse.com/#feat=cors) and [Canvas](http://caniuse.com/#feat=canvas),
11 | so `IE >= 10` with no exceptions.
12 | * This library **does not rasterize HTML** because **browsers cannot rasterize HTML**. Therefore,
13 | L.divIcon and other HTML-based features of a map, like zoom controls or legends, are not
14 | included in the output, because they are HTML.
15 |
16 | __For Leaflet < 1.0.0__: You must set `L_PREFER_CANVAS = true;` so that vector
17 | layers are drawn in Canvas
18 |
19 | __For Leaflet >= 1.0.0__: You must set `renderer: L.canvas()` for any layer that
20 | you want included in the generated image. You can also set this by setting [`preferCanvas: true`](http://leafletjs.com/reference-1.0.0.html#map-prefercanvas) in your map's options.
21 |
22 | ## Plugins that will _not_ work with leaflet-image
23 |
24 | * Leaflet.label: will not work because it uses HTML to display labels.
25 | * Leaflet.markercluster: will not work because it uses HTML for clusters.
26 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | BSD 2-Clause License
3 |
4 | Copyright (c) 2017, Mapbox
5 | All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions are met:
9 |
10 | * Redistributions of source code must retain the above copyright notice, this
11 | list of conditions and the following disclaimer.
12 |
13 | * Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## leaflet-image
2 |
3 | [](https://circleci.com/gh/mapbox/leaflet-image/tree/gh-pages)
4 |
5 | Export images out of Leaflet maps without a server component, by using
6 | Canvas and [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
7 |
8 | ## Requirements
9 |
10 | * Tile layer providers (OSM, MapBox, etc) must support [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
11 | * Any markers on the map must also support CORS. The default Leaflet-CDN markers
12 | don't, so they aren't supported.
13 | * Your browser must support [CORS](http://caniuse.com/#feat=cors) and [Canvas](http://caniuse.com/#feat=canvas),
14 | so `IE >= 10` with no exceptions.
15 | * This library **does not rasterize HTML** because **browsers cannot rasterize HTML**. Therefore,
16 | L.divIcon and other HTML-based features of a map, like zoom controls or legends, are not
17 | included in the output, because they are HTML.
18 |
19 | __For Leaflet < 1.0.0__: You must set `L_PREFER_CANVAS = true;` so that vector
20 | layers are drawn in Canvas
21 |
22 | __For Leaflet >= 1.0.0__: You must set `renderer: L.canvas()` for any layer that
23 | you want included in the generated image. You can also set this by setting [`preferCanvas: true`](http://leafletjs.com/reference-1.0.0.html#map-prefercanvas) in your map's options.
24 |
25 | ## Plugins that will _not_ work with leaflet-image
26 |
27 | * Leaflet.label: will not work because it uses HTML to display labels.
28 | * Leaflet.markercluster: will not work because it uses HTML for clusters.
29 |
30 | ### Usage
31 |
32 | browserify
33 |
34 | npm install --save leaflet-image
35 |
36 | web
37 |
38 | curl -L https://unpkg.com/leaflet-image@latest/leaflet-image.js > leaflet-image.js
39 |
40 | ### Example
41 |
42 | ```js
43 | var map = L.mapbox.map('map', 'YOUR.MAPID').setView([38.9, -77.03], 14);
44 | leafletImage(map, function(err, canvas) {
45 | // now you have canvas
46 | // example thing to do with that canvas:
47 | var img = document.createElement('img');
48 | var dimensions = map.getSize();
49 | img.width = dimensions.x;
50 | img.height = dimensions.y;
51 | img.src = canvas.toDataURL();
52 | document.getElementById('images').innerHTML = '';
53 | document.getElementById('images').appendChild(img);
54 | });
55 | ```
56 |
57 | ### Plugin CDN
58 |
59 | leaflet-image is [available through the Mapbox Plugin CDN](https://www.mapbox.com/mapbox.js/plugins/#leaflet-image) so you don't need to download & copy it. Just include the following script tag:
60 |
61 | ```html
62 |
63 | ```
64 |
65 | ### API
66 |
67 | ```js
68 | leafletImage(map, callback)
69 | ```
70 |
71 | map is a `L.map` or `L.mapbox.map`, callback takes `(err, canvas)`.
72 |
73 | ## Attribution
74 |
75 | Any images you generate from maps that require attribution - which is most, including all from commercial sources and those that include any data from OpenStreetMap - will require the same attribution as the map did. Remember to attribute.
76 |
77 | ## See Also
78 |
79 | * The [Mapbox Static Image API](https://www.mapbox.com/developers/api/static/) is simpler to use
80 | and faster than this approach.
81 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | node:
3 | version: 5
4 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |