leaflet-headless
Advanced tools
Comparing version 0.0.4 to 0.0.5
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 @@ }); |
103
test/test.js
@@ -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: '© <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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
10438
11
192
0
6
+ Addedacorn@0.11.02.7.0(transitive)
+ Addedacorn-globals@1.0.9(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbrowser-request@0.3.3(transitive)
+ Addedcontextify@0.1.15(transitive)
+ Addedcssom@0.3.8(transitive)
+ Addedcssstyle@0.2.37(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddom-serializer@0.2.2(transitive)
+ Addeddomelementtype@1.3.12.3.0(transitive)
+ Addeddomhandler@2.4.2(transitive)
+ Addeddomutils@1.7.0(transitive)
+ Addedentities@1.1.22.2.0(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedhtmlparser2@3.10.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjsdom@3.1.2(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addednwmatcher@1.4.4(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedparse5@1.5.1(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedxml-name-validator@1.0.0(transitive)
+ Addedxmlhttprequest@1.8.0(transitive)
Updatedjsdom@~3.1.2