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
8c62f7b7
Commit
8c62f7b7
authored
Nov 10, 2020
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Query tiles covering BBOX and filter by polygon
parent
11696c91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
42 deletions
+21
-42
index.html
public/index.html
+1
-0
functions.js
public/js/functions.js
+20
-42
No files found.
public/index.html
View file @
8c62f7b7
...
...
@@ -14,6 +14,7 @@
<body>
<div
id=
"mexmap"
></div>
<script
src=
"https://d3js.org/d3.v5.min.js"
></script>
<script
src=
"https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"
></script>
<script
src=
'https://unpkg.com/@turf/turf/turf.min.js'
></script>
<script
src=
"../js/functions.js"
></script>
...
...
public/js/functions.js
View file @
8c62f7b7
...
...
@@ -7,46 +7,21 @@
/* global mapboxgl, turf */
let
polygon
=
{
"type"
:
"Feature"
,
"properties"
:
{},
"geometry"
:
{
"type"
:
"Polygon"
,
"coordinates"
:
[
[
[
-
99.14920806884764
,
19.41608763433028
],
[
-
99.1123867034912
,
19.41608763433028
],
[
-
99.1123867034912
,
19.43818532931131
],
[
-
99.14920806884764
,
19.43818532931131
],
[
-
99.14920806884764
,
19.41608763433028
]
]
]
}
}
const
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
let
queryGeom
=
`
${
baseUrl
}
/query/dim_municipio?columns=st_asgeojson(box2d(st_geometryn(municipio_geom_4326,1))) box,st_asgeojson(st_geometryn(municipio_geom_4326,1)) geom&filter=municipio_cvegeo='09002'`
;
let
tiles
,
polygon
,
box
;
// define MVT layer for given table and some attributes
const
mapboxLayer
=
(
table
)
=>
{
const
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
const
mapboxLayer
=
(
table
,
polygon
,
box
)
=>
{
let
columns
=
[
"denue_nombre"
,
"sector"
,
"sector_nombre"
],
filter
=
`ST_Intersects(denue_geom_4326,ST_GeomFromGeoJSON('
${
JSON
.
stringify
(
box
)}
'))`
;
let
pbfLayer
=
{
id
:
table
,
source
:
{
type
:
"vector"
,
tiles
:
[
`
${
baseUrl
}
/
${
table
}
/mvt/{z}/{x}/{y}?geom_column=denue_geom_4326&columns=
denue_nombre, sector, sector_nombre
`
],
tiles
:
[
`
${
baseUrl
}
/
${
table
}
/mvt/{z}/{x}/{y}?geom_column=denue_geom_4326&columns=
${
columns
.
join
(
","
)}
&filter=
${
filter
}
`
],
maxzoom
:
19
,
minzoom
:
6
},
...
...
@@ -54,6 +29,7 @@ const mapboxLayer = (table) => {
type
:
"circle"
,
"paint"
:
{
//"circle-opacity": 0.5,
'circle-opacity'
:
[
'case'
,
[
'within'
,
polygon
],
0.5
,
0
],
"circle-radius"
:
3.5
,
"circle-color"
:
[
"interpolate"
,
...
...
@@ -62,8 +38,7 @@ const mapboxLayer = (table) => {
10
,
"rgb(49,54,149)"
,
50
,
"rgb(255,255,191)"
,
100
,
"rgb(158,1,66)"
],
'circle-opacity'
:
[
'case'
,
[
'within'
,
polygon
],
0.5
,
0
],
]
}
}
return
pbfLayer
;
...
...
@@ -73,16 +48,19 @@ let map = new mapboxgl.Map({
container
:
'mexmap'
,
accessToken
:
"pk.eyJ1IjoiZGV2ZWxvcGdlbyIsImEiOiJja2dwcXFic20wYnJnMzBrbG11d3dwYTkyIn0.4WwFOH6C7hDQXV9obU6mAw"
,
style
:
'mapbox://styles/mapbox/dark-v10'
,
center
:
[
-
100.94
,
21.15
],
zoom
:
7
center
:
[
-
99.18
,
19.48
],
zoom
:
12
});
map
.
addControl
(
new
mapboxgl
.
NavigationControl
());
let
tiles
=
mapboxLayer
(
"dim_denue2019"
);
map
.
on
(
"style.load"
,
()
=>
{
map
.
on
(
"style.load"
,
async
()
=>
{
d3
.
json
(
queryGeom
).
then
(
d
=>
{
polygon
=
JSON
.
parse
(
d
[
0
].
geom
);
box
=
JSON
.
parse
(
d
[
0
].
box
);
tiles
=
mapboxLayer
(
"dim_denue2019"
,
polygon
,
box
);
map
.
addLayer
(
tiles
);
});
});
map
.
on
(
'click'
,
e
=>
{
...
...
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