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
11696c91
Commit
11696c91
authored
Nov 08, 2020
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter tiles inside polygon
parent
077df679
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
16 deletions
+56
-16
index.html
public/index.html
+1
-0
functions.js
public/js/functions.js
+55
-16
No files found.
public/index.html
View file @
11696c91
...
...
@@ -15,6 +15,7 @@
<body>
<div
id=
"mexmap"
></div>
<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>
</body>
...
...
public/js/functions.js
View file @
11696c91
...
...
@@ -5,7 +5,41 @@
* November 2020
*/
// define MVT layer for given table and all trimester column
/* 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
]
]
]
}
}
// define MVT layer for given table and some attributes
const
mapboxLayer
=
(
table
)
=>
{
const
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
let
pbfLayer
=
{
...
...
@@ -19,7 +53,7 @@ const mapboxLayer = (table) => {
"source-layer"
:
table
,
type
:
"circle"
,
"paint"
:
{
"circle-opacity"
:
0.5
,
//
"circle-opacity": 0.5,
"circle-radius"
:
3.5
,
"circle-color"
:
[
"interpolate"
,
...
...
@@ -28,7 +62,8 @@ 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
;
...
...
@@ -50,7 +85,8 @@ map.on("style.load", () => {
map
.
addLayer
(
tiles
);
});
map
.
on
(
'click'
,
function
(
e
)
{
map
.
on
(
'click'
,
e
=>
{
if
(
turf
.
booleanWithin
(
turf
.
point
([
e
.
lngLat
.
lng
,
e
.
lngLat
.
lat
]),
polygon
))
{
var
features
=
map
.
queryRenderedFeatures
(
e
.
point
,
{
layers
:
[
'dim_denue2019'
]
}
);
...
...
@@ -61,14 +97,17 @@ map.on('click', function (e) {
.
setHTML
(
features
[
0
].
properties
[
'denue_nombre'
])
.
addTo
(
map
);
}
}
});
// Change the cursor to a pointer when the mouse is over the states layer.
map
.
on
(
'mouseenter'
,
'dim_denue2019'
,
function
()
{
// Change the cursor to a pointer when the mouse is over the denue layer.
map
.
on
(
'mouseenter'
,
'dim_denue2019'
,
e
=>
{
if
(
turf
.
booleanWithin
(
turf
.
point
([
e
.
lngLat
.
lng
,
e
.
lngLat
.
lat
]),
polygon
))
{
map
.
getCanvas
().
style
.
cursor
=
'pointer'
;
}
});
// Change it back to a pointer when it leaves.
map
.
on
(
'mouseleave'
,
'dim_denue2019'
,
function
()
{
map
.
on
(
'mouseleave'
,
'dim_denue2019'
,
()
=>
{
map
.
getCanvas
().
style
.
cursor
=
''
;
});
\ No newline at end of file
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