diff --git a/tests/tutorials.js b/tests/tutorials.js index cd3d10969b..aac0eab890 100644 --- a/tests/tutorials.js +++ b/tests/tutorials.js @@ -58,14 +58,25 @@ describe('tutorials', function () { tut$.when.apply(tut$, deferreds).fail(function () { throw new Error('Idle functions were rejected'); }).then(function () { + var subtestDeferreds = []; test.data('tests').forEach(function (testExp) { - var result = targetWindow.eval(testExp); - /* If the result isn't truthy, make sure our expect has a - * description telling which test block and specific test - * failed. */ - expect(result).toBeTruthy(test.data('description') + ' -> ' + testExp); + /* The test expression can return a value or a promise. We + * use jQuery's when to generically get the results in a + * resolution function. A rejection is a failure. */ + var testResult = targetWindow.eval(testExp); + var subtestDefer = tut$.when(testResult).done(function (result) { + /* If the result isn't truthy, make sure our expect has a + * description telling which test block and specific test + * failed. */ + expect(result).toBeTruthy(test.data('description') + ' -> ' + testExp); + }).fail(function () { + expect(false).toBeTruthy(test.data('description') + ' promise failed -> ' + testExp); + }); + subtestDeferreds.push(subtestDefer); + }); + tut$.when.apply(tut$, subtestDeferreds).then(function () { + testDefer.resolve(); }); - testDefer.resolve(); }); }; /* If we have already run the specific codeblock, don't run it diff --git a/tutorials/basic/thumb.jpg b/tutorials/basic/thumb.jpg new file mode 100755 index 0000000000..1892cbbbfc Binary files /dev/null and b/tutorials/basic/thumb.jpg differ diff --git a/tutorials/tile_source/thumb.jpg b/tutorials/tile_source/thumb.jpg new file mode 100755 index 0000000000..9f3af56a96 Binary files /dev/null and b/tutorials/tile_source/thumb.jpg differ diff --git a/tutorials/wms/index.pug b/tutorials/wms/index.pug index 0d959dd246..da0e0acf40 100644 --- a/tutorials/wms/index.pug +++ b/tutorials/wms/index.pug @@ -18,43 +18,46 @@ block mainTutorial }); // place a base tile layer on the map map.createLayer('osm'); + + // define a function that, given a tile location, returns a URL with + // appropriate parameters for a WMS server + function getWMSURL(x, y, zoom) { + var service = 'NWS_Observations'; + var observation = 'radar_base_reflectivity'; + // get data from NOAA + var baseUrl = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/' + service + '/' + observation + '/MapServer/export'; + // Get the bounding box of the tile in the desired projection + var bb = this.gcsTileBounds({x: x, y: y, level: zoom}, projection); + // Set the WMS server parameters + var params = { + transparent: true, + format: 'png32', + bbox: bb.left + ',' + bb.bottom + ',' + bb.right + ',' + bb.top, + bboxSR: projection.split(':')[1], + imageSR: projection.split(':')[1], + size: '256,256', + layers: 'show:3', + f: 'image' + } + // construct the url for a tile. We can use jQuery's $.param function. + var url = baseUrl + '?' + $.param(params); + return url; + } + // create a tile layer with the WMS data map.createLayer('osm', { - attribution: null, + attribution: 'Data from NOAA', // the tiles are transparent, so don't keep the lower level ones; they // would build up keepLower: false, - // the map tile URL can be generated from a function - url: function (x, y, zoom) { - var service = 'NWS_Observations'; - var observation = 'radar_base_reflectivity'; - // get data from NOAA - var baseUrl = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/' + service + '/' + observation + '/MapServer/export'; - - // Get the bounding box of the tile in the desired projection - var bb = this.gcsTileBounds({x: x, y: y, level: zoom}, projection); - // make a string which the WMS server requires for the bounding box - var bbSpec = bb.left + ',' + bb.bottom + ',' + bb.right + ',' + bb.top; - - // Set the WMS server parameters - var params = { - transparent: true, - format: 'png32', - bbox: bbSpec, - bboxSR: projection.split(':')[1], - imageSR: projection.split(':')[1], - size: '256,256', - layers: 'show:3', - f: 'image' - } - // construct the url for a tile. We can use jQuery's $.param function. - var url = baseUrl + '?' + $.param(params); - return url; - } + // the map tile URL is generated from a function + url: getWMSURL }); +codeblock_test('map has two osm layers, one from a WMS server', [ 'map.layers().length === 2', 'map.layers()[0] instanceof geo.osmLayer', 'map.layers()[1] instanceof geo.osmLayer', - 'geo.util.isFunction(map.layers()[1].url())' + 'geo.util.isFunction(map.layers()[1].url())', + /* Test that the WMS server responds with a PNG */ + '$.ajax({url: getWMSURL.call(map.layers()[1], 3, 6, 4), dataFilter: function (resp) { return resp.substr(1, 3) == "PNG"; }})' ]) diff --git a/tutorials/wms/thumb.jpg b/tutorials/wms/thumb.jpg new file mode 100755 index 0000000000..7598fbed0b Binary files /dev/null and b/tutorials/wms/thumb.jpg differ