Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-headless

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-headless - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

.travis.yml

68

index.js

@@ -9,40 +9,42 @@ /**

// make some globals to fake browser behaviour.
GLOBAL.document = jsdom('<html><head></head><body></body></html>');
GLOBAL.window = GLOBAL.document.defaultView;
GLOBAL.window.navigator.userAgent = 'webkit';
GLOBAL.navigator = GLOBAL.window.navigator;
GLOBAL.Image = require('./src/image.js');
if (!GLOBAL.L) {
// make some globals to fake browser behaviour.
GLOBAL.document = jsdom('<html><head></head><body></body></html>');
GLOBAL.window = GLOBAL.document.defaultView;
GLOBAL.window.navigator.userAgent = 'webkit';
GLOBAL.navigator = GLOBAL.window.navigator;
GLOBAL.Image = require('./src/image.js');
// Load leaflet
GLOBAL.L_DISABLE_3D = true;
GLOBAL.L_PREFER_CANVAS = true;
// Load leaflet
GLOBAL.L_DISABLE_3D = true;
GLOBAL.L_PREFER_CANVAS = true;
var leafletPath = require.resolve('leaflet');
var L = require(leafletPath);
GLOBAL.L = L;
var leafletPath = require.resolve('leaflet');
var L = require(leafletPath);
GLOBAL.L = L;
var scriptLength = leafletPath.split('/').slice(-1)[0].length;
L.Icon.Default.imagePath = leafletPath.substring(0, leafletPath.length - scriptLength) + 'images';
var scriptLength = leafletPath.split('/').slice(-1)[0].length;
L.Icon.Default.imagePath = leafletPath.substring(0, leafletPath.length - scriptLength) + 'images';
// Monkey patch map.getSize to make it work with fixed 1024x1024 elements
// jsdom appears to not have clientHeight/clientWidth on elements
L.Map.prototype.getSize = function () {
return L.point(1024, 1024);
};
// Monkey patch map.getSize to make it work with fixed 1024x1024 elements
// jsdom appears to not have clientHeight/clientWidth on elements
L.Map.prototype.getSize = function () {
return L.point(1024, 1024);
};
// Monkey patch Map to disable animations.
var originalMap = L.Map;
L.Map = originalMap.extend({
initialize: function (id, options) {
options = L.extend(options || {}, {
animate: false,
fadeAnimation: false,
zoomAnimation: false,
markerZoomAnimation: false
});
return originalMap.prototype.initialize.call(this, id, options);
}
});
// Monkey patch Map to disable animations.
var originalMap = L.Map;
L.Map = originalMap.extend({
initialize: function (id, options) {
options = L.extend(options || {}, {
animate: false,
fadeAnimation: false,
zoomAnimation: false,
markerZoomAnimation: false
});
return originalMap.prototype.initialize.call(this, id, options);
}
});
}
module.exports = L;
module.exports = GLOBAL.L;
{
"name": "leaflet-headless",
"version": "0.0.4",
"version": "0.0.5",
"description": "Leaflet for node.",
"main": "index.js",
"browser": "browser.js",
"scripts": {
"lint": "eslint index.js src/*",
"test": "mocha -t 10000 -R spec test/test.js",
"lint": "eslint index.js src/* examples/*/index.js",
"test": "mocha -t 20000 -R spec test/test.js && npm run lint",
"release": "mversion patch -m"

@@ -20,3 +21,3 @@ },

"canvas": "~1.2.1",
"jsdom": "https://github.com/springmeyer/jsdom-nogyp/tarball/c501ee8b71d8",
"jsdom": "~3.1.2",
"leaflet": "~0.7.3",

@@ -27,2 +28,3 @@ "request": "^2.53.0"

"chai": "^2.1.2",
"chai-leaflet": "0.0.10",
"eslint": "^0.17.0",

@@ -29,0 +31,0 @@ "leaflet-image": "~0.1.0",

@@ -29,2 +29,7 @@ /*

request.get(src, function (err, res, buffer) {
if (err) {
console.error('Could not get url', err);
return;
}
buffer2image(buffer);

@@ -43,2 +48,6 @@ });

fs.readFile(src, function (err, buffer) {
if (err) {
console.err(err);
return;
}
buffer2image(buffer);

@@ -45,0 +54,0 @@ });

@@ -5,7 +5,13 @@ 'use strict';

var L = require('../index.js');
var chai = require('chai').should();
var chai = require('chai');
require('chai-leaflet');
chai.should();
describe('Leaflet-headless', function () {
var element, map;
var lat = 52.4, lng = 4.5;
var latlng = [lat, lng];
beforeEach(function () {

@@ -24,5 +30,5 @@ element = document.createElement('div');

describe('basic functions', function () {
describe('Basic map functions', function () {
it('has a size', function () {
map.setView([52, 4], 10);
map.setView(latlng, 10);

@@ -34,16 +40,18 @@ var size = map.getSize();

it('map with marker', function () {
map.setView([52, 4], 10);
it('can change view', function () {
map.setView(latlng, 5);
var marker = L.marker([52, 4]).addTo(map);
map.getCenter().should.be.near(latlng);
map.getZoom().should.be.equal(5);
map.hasLayer(marker).should.be.true;
map.setView(latlng, 13);
map.getCenter().should.be.near(latlng);
map.getZoom().should.be.equal(13);
});
it('is pannable', function () {
var lat = 52,
lng = 4;
// although we tried to disable all animations
// this fails sometimes
it.skip('map is pannable', function () {
map.setView(latlng, 5);
map.setView([lat, lng], 5);
map.panBy([200, 0]);

@@ -56,4 +64,14 @@

it('map with marker', function () {
map.setView(latlng, 10);
var marker = L.marker(latlng).addTo(map);
map.hasLayer(marker).should.be.true;
});
});
describe('Adding layers', function () {
it('map with tilelayer', function () {
map.setView([52, 4], 10);
map.setView(latlng, 10);

@@ -71,52 +89,32 @@ L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {

fs.existsSync(path + 'marker-icon.png').should.be.true;
});
});
it('map with geojson', function () {
var geojson = JSON.parse('{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"foo":"bar"},"geometry":{"type":"Point","coordinates":[2.63671875,65.87472467098549]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-14.765625,-3.864254615721396]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[4.74609375,45.706179285330855]}},{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[-13.18359375,46.437856895024225],[-8.96484375,49.83798245308484],[-5.09765625,43.83452678223684],[-30.41015625,38.272688535980976],[-32.34375,55.87531083569679],[-42.01171875,54.97761367069625],[-62.22656249999999,30.751277776257812]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-13.0078125,12.039320557540584],[-13.0078125,39.36827914916014],[16.5234375,29.99300228455108],[9.4921875,12.039320557540584],[-13.0078125,12.039320557540584]]]}}]}');
/*
// Hmm, this takes lots of time, and is order-dependent. Disable for now...
describe('Advanced functions', function () {
var latlng = [52, 6];
var leafletImage = require('leaflet-image');
map.setView(latlng, 5);
it('saves an map with a marker and tiles using leaflet-image', function (done) {
var layer = L.geoJson(geojson).addTo(map);
map.fitBounds(layer.getBounds());
L.marker(latlng).addTo(map);
L.tileLayer('http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}).addTo(map);
map.setView(latlng, 12);
map.getCenter().should.not.be.near(latlng);
map.getZoom().should.be.equal(3);
});
});
leafletImage(map, function (err, canvas) {
var out = fs.createWriteStream(__dirname + '/test-map.png');
var stream = canvas.pngStream();
describe('Advanced functions', function () {
describe('examples', function () {
var leafletImageExample = require('../examples/leaflet-image/index.js');
stream.on('data', function (chunk) {
out.write(chunk);
});
stream.on('end', function () {
fs.existsSync(__dirname + '/test-map.png').should.be.true;
it('runs + wrote to file', function (done) {
leafletImageExample(function (testFilename) {
fs.existsSync(testFilename).should.be.true;
done();
});
});
});
it('saves an map with a marker using leaflet-image', function (done) {
var choroplethExample = require('../examples/choropleth/index.js');
L.marker(latlng).addTo(map);
map.setView(latlng, 12);
leafletImage(map, function (err, canvas) {
var out = fs.createWriteStream(__dirname + '/test-marker.png');
var stream = canvas.pngStream();
stream.on('data', function (chunk) {
out.write(chunk);
});
stream.on('end', function () {
fs.existsSync(__dirname + '/test-marker.png').should.be.true;
it('runs + wrote to file', function (done) {
choroplethExample(function (testFilename) {
fs.existsSync(testFilename).should.be.true;
done();

@@ -127,3 +125,2 @@ });

});
*/
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc