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
ab52bb05
Commit
ab52bb05
authored
Dec 18, 2020
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a circle and its tile intersection logic
parent
3048d545
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1528 additions
and
19 deletions
+1528
-19
circle.geojson
public/circle.geojson
+1459
-0
index.html
public/index.html
+1
-0
functions.js
public/js/functions.js
+68
-19
No files found.
public/circle.geojson
0 → 100644
View file @
ab52bb05
This diff is collapsed.
Click to expand it.
public/index.html
View file @
ab52bb05
...
...
@@ -16,6 +16,7 @@
<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 @
ab52bb05
...
...
@@ -5,10 +5,11 @@
* November-December 2020
*/
/* global mapboxgl */
/* global mapboxgl
, turf
*/
const
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
let
selectedMunis
=
[
"09002"
,
"09012"
];
let
selectedMunis
=
[{
id
:
"09002"
,
geom
:
{
coordinates
:
[[
-
99.25958633422852
,
19.34791392861453
]],
type
:
"Polygon"
}},
{
id
:
"09012"
,
geom
:
{
coordinates
:
[[
-
99.25958633422852
,
19.34791392861453
]],
type
:
"Polygon"
}}],
selectedIDs
=
selectedMunis
.
map
(
m
=>
m
.
id
);
// define MVT layer for given table and some attributes
//const mapboxLayer = (table, n, polygon, box) => {
...
...
@@ -121,7 +122,7 @@ map.on("style.load", async () => {
[
"match"
,
[
"get"
,
"municipio_cvegeo"
],
selected
Muni
s
,
selected
ID
s
,
true
,
false
]
...
...
@@ -147,7 +148,7 @@ map.on("style.load", async () => {
}
});
selected
Muni
s
.
forEach
(
muniID
=>
{
selected
ID
s
.
forEach
(
muniID
=>
{
map
.
setFeatureState
({
source
:
"dim_municipio"
,
sourceLayer
:
"dim_municipio"
,
...
...
@@ -156,9 +157,26 @@ map.on("style.load", async () => {
selected
:
true
});
});
map
.
addSource
(
'circle'
,
{
'type'
:
'geojson'
,
'data'
:
'http://localhost:8090/circle.geojson'
});
map
.
addLayer
({
'id'
:
'circle'
,
'type'
:
'fill'
,
'source'
:
'circle'
,
'layout'
:
{},
'paint'
:
{
'fill-color'
:
'#088'
,
'fill-opacity'
:
0.56
}
});
});
let
muniID
=
null
;
let
muniID
=
null
,
intersects
=
null
,
muniGeoms
=
[];
map
.
on
(
"click"
,
"denue"
,
async
e
=>
{
// flag we're only clicking denue points
...
...
@@ -183,18 +201,23 @@ map.on("click", "muni_polygon", e => {
return
;
}
// check type of click between polygons and circle
// 1. polygons that do not intersect circle - select and deselect
// 2. polygons that intersect circle - select and deselect
let
clickedMuni
=
map
.
queryRenderedFeatures
(
e
.
point
,
{
layers
:
[
"muni_polygon"
]
});
if
(
clickedMuni
.
length
!=
0
)
{
muniID
=
e
.
features
[
0
].
id
;
if
(
selectedMunis
.
includes
(
muniID
))
{
let
muniGeom
=
e
.
features
[
0
].
geometry
;
if
(
selectedMunis
.
some
(
e
=>
e
.
id
===
muniID
))
{
// if muni was clicked before
map
.
removeFeatureState
({
source
:
"dim_municipio"
,
sourceLayer
:
"dim_municipio"
,
id
:
muniID
});
selectedMunis
=
selectedMunis
.
filter
(
id
=>
id
!==
muniID
);
}
else
{
selectedMunis
.
push
(
muniID
);
// remove clicked polygon from array
selectedMunis
=
selectedMunis
.
filter
(
el
=>
el
.
id
!==
muniID
);
}
else
{
// if first time clicking muni
map
.
setFeatureState
({
source
:
"dim_municipio"
,
sourceLayer
:
"dim_municipio"
,
...
...
@@ -202,17 +225,43 @@ map.on("click", "muni_polygon", e => {
},
{
selected
:
true
});
// add clicked polygon to array
selectedMunis
.
push
({
id
:
muniID
,
geom
:
muniGeom
});
}
map
.
setFilter
(
"denue"
,
[
"all"
,[
"match"
,
[
"get"
,
"municipio_cvegeo"
],
selectedMunis
,
true
,
false
]
]
);
// get array of ids and geoms
selectedIDs
=
selectedMunis
.
map
(
a
=>
a
.
id
);
muniGeoms
=
selectedMunis
.
map
(
a
=>
a
.
geom
);
// check if selectedMunis intersect circle
let
circleLayer
=
map
.
queryRenderedFeatures
(
{
layers
:
[
"circle"
]
});
let
circleGeom
=
circleLayer
[
0
].
geometry
;
let
muniInteresects
=
selectedMunis
.
filter
(
el
=>
turf
.
intersect
(
el
.
geom
,
circleGeom
));
let
intersectedIDs
=
muniInteresects
.
map
(
a
=>
a
.
id
);
if
(
intersectedIDs
.
length
>
0
)
{
let
selectedIDs2
=
selectedIDs
.
filter
(
id
=>
intersectedIDs
.
indexOf
(
id
)
==
-
1
);
map
.
setFilter
(
"denue"
,
[
"any"
,[
"match"
,
[
"get"
,
"municipio_cvegeo"
],
selectedIDs2
,
true
,
false
],
[
'within'
,
circleGeom
]
]
);
}
else
{
map
.
setFilter
(
"denue"
,
[
"all"
,[
"match"
,
[
"get"
,
"municipio_cvegeo"
],
selectedIDs
,
true
,
false
]
]
);
}
//TODO: handle case when nothing is selected
}
});
...
...
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