Skip to content

Commit

Permalink
Allow data URL for marker source, sharper rendering of image markers (m…
Browse files Browse the repository at this point in the history
…apbox#64)

* Ensure marker positions are not subpixel, to stop blurriness

* Do not append cache string to Data URL markers

* updated leaflet-image script
  • Loading branch information
daamsie authored and tmcw committed Apr 13, 2016
1 parent bec29a2 commit 008aaf9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ module.exports = function leafletImage(map, callback) {

if (size instanceof L.Point) size = [size.x, size.y];

var x = pos.x - size[0] + anchor.x,
y = pos.y - anchor.y;
var x = Math.round(pos.x - size[0] + anchor.x),
y = Math.round(pos.y - anchor.y);

canvas.width = dimensions.x;
canvas.height = dimensions.y;
Expand All @@ -216,6 +216,18 @@ module.exports = function leafletImage(map, callback) {
}

function addCacheString(url) {
return url + ((url.match(/\?/)) ? '&' : '?') + 'cache=' + (+new Date());
// If it's a data URL we don't want to touch this.
if (isDataURL(url)) {
return url;
}
else {
return url + ((url.match(/\?/)) ? '&' : '?') + 'cache=' + (+new Date());
}
}

function isDataURL(url) {
var dataURLRegex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
return !!url.match(dataURLRegex);
}

};
27 changes: 18 additions & 9 deletions leaflet-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(function(e){if("function"==typeof bootstrap)bootstrap("leafletimage",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeLeafletImage=e}else"undefined"!=typeof window?window.leafletImage=e():global.leafletImage=e()})(function(){var define,ses,bootstrap,module,exports;
return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.leafletImage = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var queue = require('./queue');

// leaflet-image
Expand Down Expand Up @@ -198,8 +197,8 @@ module.exports = function leafletImage(map, callback) {

if (size instanceof L.Point) size = [size.x, size.y];

var x = pos.x - size[0] + anchor.x,
y = pos.y - anchor.y;
var x = Math.round(pos.x - size[0] + anchor.x),
y = Math.round(pos.y - anchor.y);

canvas.width = dimensions.x;
canvas.height = dimensions.y;
Expand All @@ -218,8 +217,20 @@ module.exports = function leafletImage(map, callback) {
}

function addCacheString(url) {
return url + ((url.match(/\?/)) ? '&' : '?') + 'cache=' + (+new Date());
// If it's a data URL we don't want to touch this.
if (isDataURL(url)) {
return url;
}
else {
return url + ((url.match(/\?/)) ? '&' : '?') + 'cache=' + (+new Date());
}
}

function isDataURL(url) {
var dataURLRegex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
return !!url.match(dataURLRegex);
}

};

},{"./queue":2}],2:[function(require,module,exports){
Expand Down Expand Up @@ -303,7 +314,5 @@ module.exports = function leafletImage(map, callback) {
function noop() {}
})();

},{}]},{},[1])
(1)
});
;
},{}]},{},[1])(1)
});

0 comments on commit 008aaf9

Please sign in to comment.