Adapt endpoints to the new preview interface

This commit is contained in:
Daniel García Aubert 2019-06-17 10:43:30 +02:00
parent ef4370c213
commit f21eda2b40
4 changed files with 29 additions and 31 deletions

View File

@ -96,9 +96,10 @@ function getPreviewImageByCenter (previewBackend) {
};
const format = req.params.format === 'jpg' ? 'jpeg' : 'png';
const { mapConfigProvider: provider } = res.locals;
const { mapConfigProvider } = res.locals;
const options = { mapConfigProvider, format, width, height, zoom, center };
previewBackend.getImage(provider, format, width, height, zoom, center, (err, image, stats = {}) => {
previewBackend.getImage(options, (err, image, stats = {}) => {
req.profiler.done(`render-${format}`);
req.profiler.add(stats);
@ -121,16 +122,17 @@ function getPreviewImageByBoundingBox (previewBackend) {
return function getPreviewImageByBoundingBoxMiddleware (req, res, next) {
const width = +req.params.width;
const height = +req.params.height;
const bounds = {
const bbox = {
west: +req.params.west,
north: +req.params.north,
east: +req.params.east,
south: +req.params.south
};
const format = req.params.format === 'jpg' ? 'jpeg' : 'png';
const { mapConfigProvider: provider } = res.locals;
const { mapConfigProvider } = res.locals;
const options = { mapConfigProvider, format, width, height, bbox };
previewBackend.getImage(provider, format, width, height, bounds, (err, image, stats = {}) => {
previewBackend.getImage(options, (err, image, stats = {}) => {
req.profiler.done(`render-${format}`);
req.profiler.add(stats);

View File

@ -215,7 +215,6 @@ function getImageOptionsFromCoordinates (zoom, lon, lat) {
}
}
function getImageOptionsFromTemplate (template, zoom) {
if (template.view) {
var zoomCenter = templateZoomCenter(template.view);
@ -239,7 +238,7 @@ function getImageOptionsFromBoundingBox (bbox = '') {
if (_bbox.length === 4 && _bbox.every(Number.isFinite)) {
return {
bounds: {
bbox: {
west: _bbox[0],
south: _bbox[1],
east: _bbox[2],
@ -252,7 +251,7 @@ function getImageOptionsFromBoundingBox (bbox = '') {
function getImage({ previewBackend, label }) {
return function getImageMiddleware (req, res, next) {
const { imageOpts, mapConfigProvider } = res.locals;
const { zoom, center, bounds } = imageOpts;
const { zoom, center, bbox } = imageOpts;
let { width, height } = req.params;
@ -262,8 +261,9 @@ function getImage({ previewBackend, label }) {
const format = req.params.format === 'jpg' ? 'jpeg' : 'png';
if (zoom !== undefined && center) {
return previewBackend.getImage(mapConfigProvider, format, width, height, zoom, center,
(err, image, stats) => {
const options = { mapConfigProvider, format, width, height, zoom, center };
return previewBackend.getImage(options, (err, image, stats) => {
req.profiler.add(stats);
if (err) {
@ -278,7 +278,9 @@ function getImage({ previewBackend, label }) {
});
}
previewBackend.getImage(mapConfigProvider, format, width, height, bounds, (err, image, stats) => {
const options = { mapConfigProvider, format, width, height, bbox };
previewBackend.getImage(options, (err, image, stats) => {
req.profiler.add(stats);
req.profiler.done('render-' + format);
@ -348,7 +350,7 @@ function templateBounds(view) {
if (hasAllBounds) {
return {
bounds: {
bbox: {
west: view.bounds.west,
south: view.bounds.south,
east: view.bounds.east,

View File

@ -41,7 +41,7 @@ TablesExtentBackend.prototype.getBounds = function (username, tables, callback)
var result = null;
if (rows.length > 0) {
result = {
bounds: rows[0]
bbox: rows[0]
};
}
callback(null, result);

30
package-lock.json generated
View File

@ -5,8 +5,8 @@
"requires": true,
"dependencies": {
"@carto/cartonik": {
"version": "github:cartodb/cartonik#405095bf5b1a002754917b177d376d25e8f00ff9",
"from": "github:cartodb/cartonik#abaculus-integration",
"version": "github:cartodb/cartonik#c3ad19d9533a2ca938e002b33fded4f474aea723",
"from": "github:cartodb/cartonik#master",
"requires": {
"@carto/mapnik": "^3.6.2-carto.15",
"@mapbox/sphericalmercator": "^1.1.0",
@ -14,11 +14,6 @@
"mime": "^2.4.0"
},
"dependencies": {
"@mapbox/sphericalmercator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sphericalmercator/-/sphericalmercator-1.1.0.tgz",
"integrity": "sha512-pEsfZyG4OMThlfFQbCte4gegvHUjxXCjz0KZ4Xk8NdOYTQBLflj6U8PL05RPAiuRAMAQNUUKJuL6qYZ5Y4kAWA=="
},
"mime": {
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz",
@ -48,6 +43,11 @@
}
}
},
"@mapbox/sphericalmercator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sphericalmercator/-/sphericalmercator-1.1.0.tgz",
"integrity": "sha512-pEsfZyG4OMThlfFQbCte4gegvHUjxXCjz0KZ4Xk8NdOYTQBLflj6U8PL05RPAiuRAMAQNUUKJuL6qYZ5Y4kAWA=="
},
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -3708,11 +3708,6 @@
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.4.tgz",
"integrity": "sha512-7j8LYJLeY/Yb6ACbQ7F76qy5jHkp0U6jgBfJsk97bwWlVUnUWsAgpyaCvo17h0/RQGnQ036tVDomiwoI4pDkQA=="
},
"sphericalmercator": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/sphericalmercator/-/sphericalmercator-1.0.5.tgz",
"integrity": "sha1-3cWgSeNg4ADQ+tn8IsQHGIJYSYA="
},
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
@ -3727,9 +3722,9 @@
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"sqlite3": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.8.tgz",
"integrity": "sha512-kgwHu4j10KhpCHtx//dejd/tVQot7jc3sw+Sn0vMuKOw0X00Ckyg9VceKgzPyGmmz+zEoYue9tOLriWTvYy0ww==",
"version": "4.0.9",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.9.tgz",
"integrity": "sha512-IkvzjmsWQl9BuBiM4xKpl5X8WCR4w0AeJHRdobCdXZ8dT/lNc1XS6WqvY35N6+YzIIgzSBeY5prdFObID9F9tA==",
"requires": {
"nan": "^2.12.1",
"node-pre-gyp": "^0.11.0",
@ -4126,10 +4121,10 @@
"integrity": "sha1-tDFbtCFKPXBY6+7okuE/ok2YsHU="
},
"windshaft": {
"version": "github:cartodb/windshaft#82688a6a6d9f13b7dbe67a0da76a5ec823af962d",
"version": "github:cartodb/windshaft#ff176e1ab4a094ea4f786cca1c78f2c5e3481e8a",
"from": "github:cartodb/windshaft#abaculus-cartofy",
"requires": {
"@carto/cartonik": "github:cartodb/cartonik#abaculus-integration",
"@carto/cartonik": "github:cartodb/cartonik#master",
"@carto/mapnik": "3.6.2-carto.15",
"canvas": "^2.4.1",
"carto": "github:cartodb/carto#0.15.1-cdb5",
@ -4140,7 +4135,6 @@
"redis-mpool": "0.7.0",
"request": "2.87.0",
"semver": "5.5.0",
"sphericalmercator": "1.0.5",
"torque.js": "^3.1.0",
"underscore": "1.6.0"
}