Allow examples to use local files for tiles instead of external data.
This removes the network dependency to openstreetmap.org in the tests.
As additional examples are added, the tiles.tgz file will need to be updated.
MODIFY
examples/lines/main.js
examples/lines/main.js
@@ -144,7 +144,9 @@ $(function () {
lineFeature.draw();
var text = 'Shown: ' + segments;
$('#lines-shown').text(text).attr('title', text);
+ map.onIdle(function () {
$('#map').addClass('ready');
+ });
}
/**

MODIFY
karma-base.js
karma-base.js
@@ -183,6 +183,27 @@ var notes_middleware = function (config) {
};
};
+/**
+ * Express style middleware to handle REST requests for OSM tiles on the test
+ * server.
+ */
+var osmtiles_middleware = function (config) {
+ return function (request, response, next) {
+ var match = request.url.match(/.*http:\/\/[a-c]\.tile.openstreetmap.org\/([0-9]+\/[0-9]+\/[0-9]+.png)$/);
+ /* Serve tiles if they have been proxied */
+ if (match && request.method === 'GET') {
+ var imagePath = 'dist/data/tiles/' + match[1];
+ var img = new Buffer(fs.readFileSync(imagePath));
+ response.setHeader('Content-Type', 'image/png');
+ response.setHeader('Content-Length', img.length);
+ response.setHeader('Access-Control-Allow-Origin', '*');
+ response.writeHead(200);
+ return response.end(img);
+ }
+ next();
+ };
+};
+
module.exports = function (config) {
var newConfig = {
autoWatch: false,
@@ -218,10 +239,12 @@ module.exports = function (config) {
'kjhtml'
],
middleware: [
- 'notes'
+ 'notes',
+ 'osmtiles'
],
plugins: [
{'middleware:notes': ['factory', notes_middleware]},
+ {'middleware:osmtiles': ['factory', osmtiles_middleware]},
'karma-*'
],
preprocessors: {},
@@ -239,6 +262,5 @@ module.exports = function (config) {
}
};
newConfig.preprocessors[test_case] = ['webpack', 'sourcemap'];
-
return newConfig;
};

MODIFY
testing/test-data/base-images.tgz.md5
testing/test-data/base-images.tgz.md5
-2f4ea11110deac8f5de053c49d09ce1e
\ No newline at end of file
+914356846f8c541a813bb7e53efc6c57
\ No newline at end of file

MODIFY
testing/test-data/base-images.tgz.url
testing/test-data/base-images.tgz.url
-https://data.kitware.com/api/v1/file/586bfea38d777f05f44a5c6f/download
\ No newline at end of file
+https://data.kitware.com/api/v1/file/586d1ff18d777f05f44a5c75/download
\ No newline at end of file

MODIFY
testing/test-data/tiles.tgz.md5
testing/test-data/tiles.tgz.md5
-73d3e6e8800e5d82d5f668413379373a
\ No newline at end of file
+910b4894cc906dc3762dc9e314fd4025

MODIFY
testing/test-data/tiles.tgz.url
testing/test-data/tiles.tgz.url
-https://data.kitware.com/api/v1/file/560a89528d777f7bfaadd3f8/download
+https://data.kitware.com/api/v1/file/586d1e958d777f05f44a5c72/download

MODIFY
tests/data/proxy-for-tests.pac
tests/data/proxy-for-tests.pac
+/* global dnsDomainIs */
+
function FindProxyForURL(url, host) {
// Don't serve certain remote addresses
- if (dnsDomainIs(host, "fonts.googleapis.com")) {
- return "PROXY http://192.0.2.0";
+ if (dnsDomainIs(host, 'fonts.googleapis.com')) {
+ // If we use a testing address such as 192.0.2.0, requests will take a
+ // long time to fail. Using an address starting with 0 fails promptly.
+ return 'PROXY 0.0.0.1';
}
- return "DIRECT";
+ // Redirect tiles to our test server
+ if (dnsDomainIs(host, '.tile.openstreetmap.org')) {
+ return 'PROXY 127.0.0.1:9876';
+ }
+ return 'DIRECT';
}

MODIFY
tests/example-cases/lines.js
tests/example-cases/lines.js
@@ -9,7 +9,7 @@ describe('lines example', function () {
});
it('basic', function (done) {
- $('#map').attr('src', '/examples/lines/index.html?showmap=false');
+ $('#map').attr('src', '/examples/lines/index.html');
imageTest.imageTest('exampleLines', '#map', 0.0015, done, null, 0, 2, '#map.ready');
}, 10000);
it('more lines', function (done) {

Allow examples to use local files for tiles instead of external data.

This removes the network dependency to openstreetmap.org in the tests.

As additional examples are added, the tiles.tgz file will need to be updated.