mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-09 23:51:56 +01:00
3727c9ad5e
Fixes #814 * fix: remove outdated references to mapbox * docs: fix references in readme * chore: fix mapbox references in tests * chore: fix mapbox references in stories, webpack config * chore: remove empty array
98 lines
1.9 KiB
JavaScript
98 lines
1.9 KiB
JavaScript
const cors = require("cors");
|
|
const express = require("express");
|
|
const fs = require("fs");
|
|
const sourceData = require("./sources");
|
|
|
|
|
|
var app = express();
|
|
|
|
app.use(cors());
|
|
|
|
|
|
function buildStyle(opts) {
|
|
opts = opts || {};
|
|
opts = Object.assign({
|
|
sources: {}
|
|
}, opts);
|
|
|
|
return {
|
|
"id": "test-style",
|
|
"version": 8,
|
|
"name": "Test Style",
|
|
"metadata": {
|
|
"maputnik:renderer": "mlgljs"
|
|
},
|
|
"sources": opts.sources,
|
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
|
"layers": []
|
|
}
|
|
}
|
|
|
|
function buildGeoJSONSource(data) {
|
|
return {
|
|
type: "vector",
|
|
data: data
|
|
};
|
|
}
|
|
|
|
function buildResterSource(req, key) {
|
|
return {
|
|
"tileSize": 256,
|
|
"tiles": [
|
|
req.protocol + '://' + req.get('host') + "/" + key + "/{x}/{y}/{z}"
|
|
],
|
|
"type": "raster"
|
|
};
|
|
}
|
|
|
|
|
|
app.get("/sources/raster/{x}/{y}/{z}", function(req, res) {
|
|
res.status(404).end();
|
|
})
|
|
|
|
app.get("/styles/empty/:sources", function(req, res) {
|
|
var reqSources = req.params.sources.split(",");
|
|
|
|
var sources = {};
|
|
reqSources.forEach(function(key) {
|
|
var parts = key.split(":");
|
|
var type = parts[0];
|
|
var key = parts[1];
|
|
|
|
if(type === "geojson") {
|
|
sources[key] = buildGeoJSONSource(sourceData[key]);
|
|
}
|
|
else if(type === "raster") {
|
|
sources[key] = buildResterSource(req, key);
|
|
}
|
|
else {
|
|
console.error("ERR: Invalid type: %s", type);
|
|
throw "Invalid type"
|
|
}
|
|
});
|
|
|
|
var json = buildStyle({
|
|
sources: sources
|
|
});
|
|
res.send(json);
|
|
})
|
|
|
|
app.get("/example-layer-style.json", function(req, res) {
|
|
res.json(
|
|
JSON.parse(
|
|
fs.readFileSync(__dirname+"/example-layer-style.json").toString()
|
|
)
|
|
);
|
|
})
|
|
|
|
app.get("/example-style.json", function(req, res) {
|
|
res.json(
|
|
JSON.parse(
|
|
fs.readFileSync(__dirname+"/example-style.json").toString()
|
|
)
|
|
);
|
|
})
|
|
|
|
|
|
module.exports = app;
|