• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    JavaScript
  • Created about 11 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Leaflet for node.

Leaflet-headless

Leaflet for node.

  • Has Leaflet 1.1.x as dependency.
  • Uses jsdom to fake ad DOM.
  • Uses Image implementation and canvas from canvas. Note that node-canvas needs some dependencies to be installed: for ubuntu: sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
  • Tiles, Markers and vector layers work well with leaflet-image
  • It's slow (~4s for the examples/choropleth/ on my machine).

Example

Run npm install leaflet-headless to install the package. Requiring leaflet-headless will introduce a global L which just works like in the browser.

For vector layers, make sure to use the canvas renderer if you want to use leaflet-image:

var L = require('leaflet-headless');

var map = L.map(document.createElement('div')).setView([52, 4], 10);

var marker = L.marker([52, 4]).addTo(map);

var latlngs = [[52, 4], [54, 4], [54, 6], [52, 6], [52, 4]];
var polyline = L.polyline(latlngs).addTo(map);

Setting map size

Because jsdom does not support clientWidth/clientHeight, leaflet-headless defaults to a map size of 1024x1024px. To adjust this size, use L.Map.setSize(width, height).

map.setSize(800, 600);

Saving images

leaflet-headless adds a convenience function to L.Map to save the current map to an image using leaflet-image.

L.Map.saveImage(filename, callback): Save image to filename and call callback when ready.

map.saveImage('test.png', function (filename) {
    console.log('Saved map image to ' + filename);
});

Other examples:

~/leaflet-headless$ npm install
[...]
~/leaflet-headless$ cd examples/leaflet-image/
~/leaflet-headless/examples/leaflet-image/$ node index.js
Save to image using leaflet-image...
Saved test.png

Run tests

npm test

Attribution

This is inspired by https://github.com/rclark/server-side-leaflet.

More Repositories

1

django-tables2

django-tables2 - An app for creating HTML tables
Python
1,850
star
2

Leaflet.Sync

Synchronized view of two maps.
JavaScript
235
star
3

Leaflet.encoded

Plugin to support Google's polyline encoding in Leaflet.
JavaScript
176
star
4

Leaflet-semicircle

Extend Leaflet's circle class to display semicircles.
JavaScript
120
star
5

orc-data

Display/visualize some freely available ORC certificate sailboat data.
Svelte
72
star
6

python-lora

Decrypt LoRa payloads in python.
Python
67
star
7

leaflet.layerscontrol-minimap

Leaflet layers control with minimaps.
JavaScript
49
star
8

marinetraffic

Node module to use marinetraffic tracks.
JavaScript
26
star
9

leaflet-clonelayer

Clone leaflet layers
JavaScript
25
star
10

Leaflet.Grid

Displays a lat/lng grid overlay on Leaflet maps.
JavaScript
22
star
11

Leaflet.latlngcontrol

Show and edit the lat/lng for the center of a leaflet map
JavaScript
5
star
12

grunt-geojsonhint

Grunt task to run geojsonhint
JavaScript
3
star
13

chai-leaflet

Chai assertions to use with Leaflet map apps
JavaScript
3
star
14

fph-parser

Read Fisher & Paykel CPAP .FPH files.
Python
3
star
15

laser-gcode-swatch

Generate a series of paths at different feedrates / laser power, to check the effect of your CNC laser etcher on different materials.
JavaScript
3
star
16

f-engrave

Fork of f-engrave
Python
3
star
17

Compare-NewYork

Compare 1836 and modern New York
JavaScript
2
star
18

d3-legend

Simple legend for d3 using data-legend attributes on paths.
JavaScript
2
star
19

coconut-graph

Graph lib using d3
JavaScript
2
star
20

leaflet-layerscontrol-buttons

Leaflet layers control using a set of buttons.
CSS
2
star
21

saillogs

Stories about sailing in dutch.
JavaScript
2
star
22

rws2gpx

Rijkswaterstaat drijvende markeringen naar GPX converteren
HTML
2
star
23

svelte-django-gettext

Use Django's translation catalog in Svelte
JavaScript
2
star
24

NL-travel-advice

Travel advice from The Netherlands ministry of foreign affairs; JSON + map
JavaScript
1
star
25

NL-social-churches

Lijst van kerken in NL die actief zijn op social media met wat cijfertjes.
JavaScript
1
star