Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DENUE tiles
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rodrigo Tapia-McClung
DENUE tiles
Commits
9ea9f68e
Commit
9ea9f68e
authored
Dec 15, 2020
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added geojsonmvt
parent
aa360524
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
145 additions
and
16 deletions
+145
-16
geojsonmvt.js
geojsonmvt.js
+145
-0
pgserver.js
pgserver.js
+0
-16
No files found.
geojsonmvt.js
0 → 100644
View file @
9ea9f68e
//var fs = require('fs');
var
geojson2mvt
=
require
(
'geojson2mvt'
);
const
sqlTableName
=
require
(
'./utils/sqltablename.js'
);
var
turf
=
require
(
"@turf/turf"
);
const
tableSQL
=
(
params
,
query
)
=>
{
return
`
SELECT
${
query
.
columns
}
FROM
${
sqlTableName
(
params
.
table
)}
-- Optional Filter
${
query
.
filter
?
`WHERE
${
query
.
filter
}
`
:
''
}
-- Optional Group
${
query
.
group
?
`GROUP BY
${
query
.
group
}
`
:
''
}
-- Optional sort
${
query
.
sort
?
`ORDER BY
${
query
.
sort
}
`
:
''
}
-- Optional limit
${
query
.
limit
?
`LIMIT
${
query
.
limit
}
`
:
''
}
`
}
const
geojsonSQL
=
(
params
,
query
)
=>
{
let
bounds
=
query
.
bounds
?
query
.
bounds
.
split
(
','
).
map
(
Number
)
:
null
;
bounds
&&
bounds
.
length
===
3
?
bounds
=
merc
.
bbox
(
bounds
[
1
],
bounds
[
2
],
bounds
[
0
])
:
null
;
return
`
SELECT
Row_to_json(fc) as geojson
FROM (
SELECT
'FeatureCollection' AS type,
COALESCE(Array_to_json(Array_agg(f)), '[]'::json) AS features
FROM (
SELECT
'Feature' AS type,
St_asgeojson(ST_Transform(lg.
${
query
.
geom_column
}
, 4326))::json AS geometry,
${
query
.
columns
?
`
Row_to_json(
(
SELECT
l
FROM
(SELECT
${
query
.
columns
}
) AS l
)
) AS properties
`
:
`'{}'::json AS properties`
}
FROM
${
sqlTableName
(
params
.
table
)}
AS lg
${
bounds
?
`, (SELECT ST_SRID(
${
query
.
geom_column
}
) as srid FROM
${
sqlTableName
(
params
.
table
)}
LIMIT 1) sq`
:
''
}
-- Optional Filter
${
query
.
filter
||
bounds
?
'WHERE'
:
''
}
${
query
.
filter
?
`
${
query
.
filter
}
`
:
''
}
${
query
.
filter
&&
bounds
?
'AND'
:
''
}
${
bounds
?
`
${
query
.
geom_column
}
&&
ST_Transform(
ST_MakeEnvelope(
${
bounds
.
join
()}
, 4326),
srid
)
`
:
''
}
) AS f
) AS fc;
`
}
module
.
exports
=
function
(
app
,
pool
)
{
app
.
get
(
'/data/geojsonmvt/:table'
,
async
(
req
,
res
)
=>
{
//console.log(req)
if
(
!
req
.
query
.
geom_column
)
{
req
.
query
.
geom_column
=
'geom'
;
}
const
geojson
=
geojsonSQL
(
req
.
params
,
req
.
query
);
//const bbox = tableSQL(req.params, req.query);
try
{
const
result
=
await
pool
.
query
(
geojson
);
let
geoJson
=
result
.
rows
[
0
].
geojson
;
const
geojsonBBOX
=
turf
.
bbox
(
geoJson
);
// minX, minY, maxX, maxY order
// minY, minX, maxY, maxX
// 1, 0, 3, 2
// south,west,north,east]
//res.json(geoJson);
//const box = await pool.query(bbox);
//res.json(box.row[0].geojson)
//const box = await pool.query(sqlStringBox);
//res.json(box.rows[0])
//const filePath = './bus_routes.geojson';
//let geoJson = result.rows[0].box;
//let geoJson = res.json(result.rows[0].geojson);
var
options
=
{
rootDir
:
'public/tiles'
,
//bbox : [40.426042,-74.599228,40.884448,-73.409958], //[south,west,north,east]
bbox
:
[
geojsonBBOX
[
1
],
geojsonBBOX
[
0
],
geojsonBBOX
[
3
],
geojsonBBOX
[
2
]],
zoom
:
{
min
:
8
,
max
:
18
,
},
layerName
:
'denue'
,
};
//var geoJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// build the static tile pyramid
geojson2mvt
(
geoJson
,
options
);
}
catch
(
err
)
{
console
.
log
(
err
);
let
status
=
500
;
switch
(
err
.
code
)
{
case
'42P01'
:
// table does not exist
status
=
422
;
break
;
case
'42703'
:
// column does not exist
status
=
422
;
break
;
default
:
}
res
.
status
(
status
).
json
({
error
:
err
.
message
})
}
})
}
\ No newline at end of file
pgserver.js
View file @
9ea9f68e
...
@@ -27,23 +27,7 @@ let header = {
...
@@ -27,23 +27,7 @@ let header = {
"Content-Encoding"
:
"gzip"
"Content-Encoding"
:
"gzip"
};
};
let
options
=
{
extensions
:
[
'pbf'
],
setHeaders
:
function
(
res
,
path
,
req
)
{
let
ext
=
path
.
split
(
'.'
).
pop
()
//console.log(res)
if
(
ext
===
'pbf'
)
{
/*res.header('Content-Type', 'application/x-protobuf');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET');
res.header('Access-Control-Allow-Headers', 'Content-Type');
//res.header('Content-Encoding', 'gzip');*/
res
.
header
(
header
);
}
}
}
app
.
use
(
'/'
,
express
.
static
(
__dirname
+
'/public'
));
app
.
use
(
'/'
,
express
.
static
(
__dirname
+
'/public'
));
//app.use('/', express.static(__dirname + '/public', options));
// Route which handles requests like the following: /<mbtiles-name>/0/1/2.pbf
// Route which handles requests like the following: /<mbtiles-name>/0/1/2.pbf
app
.
get
(
'/denue/:z/:x/:y.pbf'
,
function
(
req
,
res
)
{
app
.
get
(
'/denue/:z/:x/:y.pbf'
,
function
(
req
,
res
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment