Skip to content

Commit

Permalink
Add and fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 18, 2016
1 parent 008aaf9 commit 81b2e12
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
24 changes: 10 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global L */

var queue = require('./queue');

// leaflet-image
Expand Down Expand Up @@ -26,8 +28,8 @@ module.exports = function leafletImage(map, callback) {
if (map._pathRoot) {
layerQueue.defer(handlePathRoot, map._pathRoot);
} else if (map._panes) {
var firstCanvas = map._panes.overlayPane.getElementsByTagName('canvas').item(0);
if (firstCanvas) { layerQueue.defer(handlePathRoot, firstCanvas); }
var firstCanvas = map._panes.overlayPane.getElementsByTagName('canvas').item(0);
if (firstCanvas) { layerQueue.defer(handlePathRoot, firstCanvas); }
}
map.eachLayer(drawMarkerLayer);
layerQueue.awaitAll(layersDone);
Expand All @@ -49,7 +51,7 @@ module.exports = function leafletImage(map, callback) {

function layersDone(err, layers) {
if (err) throw err;
layers.forEach(function(layer) {
layers.forEach(function (layer) {
if (layer && layer.canvas) {
ctx.drawImage(layer.canvas, 0, 0);
}
Expand Down Expand Up @@ -78,17 +80,11 @@ module.exports = function leafletImage(map, callback) {
return callback();
}

var offset = new L.Point(
((origin.x / tileSize) - Math.floor(origin.x / tileSize)) * tileSize,
((origin.y / tileSize) - Math.floor(origin.y / tileSize)) * tileSize
);

var tileBounds = L.bounds(
bounds.min.divideBy(tileSize)._floor(),
bounds.max.divideBy(tileSize)._floor()),
tiles = [],
center = tileBounds.getCenter(),
j, i, point,
j, i,
tileQueue = new queue(1);

for (j = tileBounds.min.y; j <= tileBounds.max.y; j++) {
Expand All @@ -97,7 +93,7 @@ module.exports = function leafletImage(map, callback) {
}
}

tiles.forEach(function(tilePoint) {
tiles.forEach(function (tilePoint) {
var originalTilePoint = tilePoint.clone();

if (layer._adjustTilePoint) {
Expand Down Expand Up @@ -132,14 +128,14 @@ module.exports = function leafletImage(map, callback) {
function loadTile(url, tilePos, tileSize, callback) {
var im = new Image();
im.crossOrigin = '';
im.onload = function() {
im.onload = function () {
callback(null, {
img: this,
pos: tilePos,
size: tileSize
});
};
im.onerror = function(e) {
im.onerror = function (e) {
// use canvas instead of errorTileUrl if errorTileUrl get 404
if (layer.options.errorTileUrl != '' && e.target.errorCheck === undefined) {
e.target.errorCheck = true;
Expand Down Expand Up @@ -203,7 +199,7 @@ module.exports = function leafletImage(map, callback) {
canvas.height = dimensions.y;
im.crossOrigin = '';

im.onload = function() {
im.onload = function () {
ctx.drawImage(this, x, y, size[0], size[1]);
callback(null, {
canvas: canvas
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "export leaflet maps as images",
"main": "index.js",
"scripts": {
"make": "browserify -s leafletImage index.js > leaflet-image.js"
"make": "browserify -s leafletImage index.js > leaflet-image.js",
"test": "eslint index.js"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +24,7 @@
"url": "https://github.com/mapbox/leaflet-image/issues"
},
"devDependencies": {
"browserify": "~2.32.2"
"browserify": "~13.0.1",
"eslint": "2.10.2"
}
}

0 comments on commit 81b2e12

Please sign in to comment.