Skip to content

Commit

Permalink
Add WMS test, fix WMS. Fixes mapbox#70
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 18, 2016
1 parent daddac6 commit e1856ab
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var cacheBusterDate = +new Date();
// leaflet-image
module.exports = function leafletImage(map, callback) {

var hasMapbox = !L.mapbox;

var dimensions = map.getSize(),
layerQueue = new queue(1);

Expand Down Expand Up @@ -78,7 +80,8 @@ module.exports = function leafletImage(map, callback) {
if (zoom > layer.options.maxZoom ||
zoom < layer.options.minZoom ||
// mapbox.tileLayer
(layer.options.format && !layer.options.tiles)) {
(hasMapbox &&
layer instanceof L.mapbox.tileLayer && !layer.options.tiles)) {
return callback();
}

Expand Down
5 changes: 4 additions & 1 deletion leaflet-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var cacheBusterDate = +new Date();
// leaflet-image
module.exports = function leafletImage(map, callback) {

var hasMapbox = !L.mapbox;

var dimensions = map.getSize(),
layerQueue = new queue(1);

Expand Down Expand Up @@ -79,7 +81,8 @@ module.exports = function leafletImage(map, callback) {
if (zoom > layer.options.maxZoom ||
zoom < layer.options.minZoom ||
// mapbox.tileLayer
(layer.options.format && !layer.options.tiles)) {
(hasMapbox &&
layer instanceof L.mapbox.tileLayer && !layer.options.tiles)) {
return callback();
}

Expand Down
Binary file modified test/out/one-point-oh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/out/osm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/out/wms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions test/pages/wms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<head>
<script>L_PREFER_CANVAS = true;</script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' />
<link href='./shared/style.css' rel='stylesheet' />
</head>
<body>
<div id='snapshot'></div>
<div id='map'></div>
<script src='../../leaflet-image.js'></script>
<script>
var snapshot = document.getElementById('snapshot');
var map = L.map('map')
.setView([38.88995, -77.00906], 8);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var precipitation = L.tileLayer.wms('http://nowcoast.noaa.gov/arcgis/services/nowcoast/analysis_meteohydro_sfc_qpe_time/MapServer/WmsServer', {
format: 'image/png',
transparent: true,
layers: '5'
}).addTo(map);

setTimeout(function() {
leafletImage(map, doImage);
}, 2000);

function doImage(err, canvas) {
var img = document.createElement('img');
var dimensions = map.getSize();
img.width = dimensions.x;
img.height = dimensions.y;
img.src = canvas.toDataURL();
snapshot.innerHTML = '';
snapshot.appendChild(img);
}
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var pixelmatch = require('pixelmatch');
var fs = require('fs');
var Pageres = require('pageres');

['simple', 'circle-marker', 'osm', 'one-point-oh', 'style-layer', 'no-tiles'].forEach(name => {
['simple', 'circle-marker', 'osm', 'one-point-oh',
'style-layer', 'no-tiles', 'wms'].forEach(name => {
test(name, t => {
const pageres = new Pageres({ delay: 5 })
.src(path.join(__dirname, 'pages/', name + '.html'), ['400x400'])
Expand Down

0 comments on commit e1856ab

Please sign in to comment.