Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
309169ce
Commit
309169ce
authored
Jun 20, 2022
by
xaralis
Browse files
Options
Downloads
Patches
Plain Diff
refactor(district): fix/unify js map handling for both block and page-based approach
parent
040aceea
Branches
Branches containing commit
No related tags found
2 merge requests
!559
Release
,
!557
Promote some geo feature collection items
Pipeline
#8585
passed
Jun 20, 2022
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
district/models.py
+3
-11
3 additions, 11 deletions
district/models.py
maps_utils/blocks.py
+22
-23
22 additions, 23 deletions
maps_utils/blocks.py
maps_utils/static/maps_utils/geo-feature-collection.js
+19
-13
19 additions, 13 deletions
maps_utils/static/maps_utils/geo-feature-collection.js
with
44 additions
and
47 deletions
district/models.py
+
3
−
11
View file @
309169ce
...
@@ -1647,7 +1647,7 @@ class DistrictGeoFeatureDetailPage(
...
@@ -1647,7 +1647,7 @@ class DistrictGeoFeatureDetailPage(
def
as_geojson_object
(
self
,
request
):
def
as_geojson_object
(
self
,
request
):
collection
=
json
.
loads
(
self
.
geojson
)
collection
=
json
.
loads
(
self
.
geojson
)
image
=
(
image
=
(
self
.
image
.
get_rendition
(
"
fill-
8
00x
450
|jpegquality-80
"
).
url
self
.
image
.
get_rendition
(
"
fill-
12
00x
675
|jpegquality-80
"
).
url
if
self
.
image
if
self
.
image
else
None
else
None
)
)
...
@@ -1667,23 +1667,15 @@ class DistrictGeoFeatureDetailPage(
...
@@ -1667,23 +1667,15 @@ class DistrictGeoFeatureDetailPage(
}
}
)
)
feature
[
"
properties
"
][
"
selfTitle
"
]
=
feature
[
"
properties
"
].
get
(
"
title
"
)
feature
[
"
properties
"
][
"
title
"
]
=
(
feature
[
"
properties
"
][
"
title
"
]
+
"
-
"
+
self
.
title
if
feature
[
"
properties
"
][
"
selfTitle
"
]
else
self
.
title
)
if
not
"
description
"
in
feature
[
"
properties
"
]:
if
not
"
description
"
in
feature
[
"
properties
"
]:
feature
[
"
properties
"
][
"
description
"
]
=
None
feature
[
"
properties
"
][
"
description
"
]
=
None
# This extends GeoJSON spec to pass down more context to the map.
# This extends GeoJSON spec to pass down more context to the map.
collection
[
"
properties
"
]
=
{}
collection
[
"
properties
"
]
=
{}
collection
[
"
properties
"
][
"
slug
"
]
=
f
"
{
self
.
pk
}
-
{
self
.
slug
}
"
collection
[
"
properties
"
][
"
slug
"
]
=
f
"
{
self
.
pk
}
-
{
self
.
slug
}
"
collection
[
"
properties
"
][
"
title
"
]
=
self
.
title
collection
[
"
properties
"
][
"
collectionTitle
"
]
=
self
.
title
collection
[
"
properties
"
][
"
category
"
]
=
self
.
category
.
name
collection
[
"
properties
"
][
"
collectionDescription
"
]
=
self
.
perex
collection
[
"
properties
"
][
"
collectionDescription
"
]
=
self
.
perex
collection
[
"
properties
"
][
"
category
"
]
=
self
.
category
.
name
collection
[
"
properties
"
][
"
index
"
]
=
self
.
index
collection
[
"
properties
"
][
"
index
"
]
=
self
.
index
collection
[
"
properties
"
][
"
image
"
]
=
image
collection
[
"
properties
"
][
"
image
"
]
=
image
collection
[
"
properties
"
][
"
link
"
]
=
url
collection
[
"
properties
"
][
"
link
"
]
=
url
...
...
This diff is collapsed.
Click to expand it.
maps_utils/blocks.py
+
22
−
23
View file @
309169ce
...
@@ -50,6 +50,8 @@ class MapPointBlock(blocks.StructBlock):
...
@@ -50,6 +50,8 @@ class MapPointBlock(blocks.StructBlock):
"
properties
"
:
{
"
properties
"
:
{
"
slug
"
:
feature_id
,
"
slug
"
:
feature_id
,
"
title
"
:
None
,
"
title
"
:
None
,
"
collectionTitle
"
:
None
,
"
collectionDescription
"
:
None
,
},
},
"
features
"
:
[
"
features
"
:
[
{
{
...
@@ -66,6 +68,7 @@ class MapPointBlock(blocks.StructBlock):
...
@@ -66,6 +68,7 @@ class MapPointBlock(blocks.StructBlock):
"
slug
"
:
feature_id
,
"
slug
"
:
feature_id
,
"
title
"
:
None
,
"
title
"
:
None
,
"
description
"
:
None
,
"
description
"
:
None
,
"
collectionTitle
"
:
None
,
"
collectionDescription
"
:
None
,
"
collectionDescription
"
:
None
,
"
image
"
:
None
,
"
image
"
:
None
,
"
color
"
:
value
[
"
hex_color
"
],
"
color
"
:
value
[
"
hex_color
"
],
...
@@ -139,11 +142,14 @@ class MapFeatureCollectionBlock(blocks.StructBlock):
...
@@ -139,11 +142,14 @@ class MapFeatureCollectionBlock(blocks.StructBlock):
fwp
[
"
properties
"
].
update
(
fwp
[
"
properties
"
].
update
(
{
{
"
id
"
:
feature_id
,
"
id
"
:
feature_id
,
"
slug
"
:
f
"
{
feature_id
}
-
{
slugify
(
feature
[
'
title
'
])
}
"
,
"
slug
"
:
f
"
0-
{
feature_id
}
-
{
slugify
(
feature
[
'
title
'
])
}
"
,
"
collectionTItle
"
:
feature
[
"
title
"
],
# Individual features are suppressed to emulate collection-like style.
"
title
"
:
None
,
"
description
"
:
None
,
"
collectionTitle
"
:
feature
[
"
title
"
],
"
collectionDescription
"
:
feature
[
"
description
"
],
"
collectionDescription
"
:
feature
[
"
description
"
],
"
image
"
:
feature
[
"
image
"
]
"
image
"
:
feature
[
"
image
"
]
.
get_rendition
(
"
fill-
8
00x
450
|jpegquality-80
"
)
.
get_rendition
(
"
fill-
12
00x
675
|jpegquality-80
"
)
.
url
.
url
if
feature
[
"
image
"
]
if
feature
[
"
image
"
]
else
None
,
else
None
,
...
@@ -151,38 +157,31 @@ class MapFeatureCollectionBlock(blocks.StructBlock):
...
@@ -151,38 +157,31 @@ class MapFeatureCollectionBlock(blocks.StructBlock):
"
color
"
:
feature
[
"
hex_color
"
],
"
color
"
:
feature
[
"
hex_color
"
],
}
}
)
)
fwp
[
"
properties
"
][
"
selfTitle
"
]
=
fwp
[
"
properties
"
].
get
(
"
title
"
)
fwp
[
"
properties
"
][
"
title
"
]
=
(
fwp
[
"
properties
"
][
"
title
"
]
+
"
-
"
+
feature
[
"
title
"
]
if
fwp
[
"
properties
"
][
"
selfTitle
"
]
else
self
.
title
)
if
not
"
description
"
in
fwp
[
"
properties
"
]:
fwp
[
"
properties
"
][
"
description
"
]
=
None
return
fwp
return
fwp
features
=
[
_geojson_feature_with_props
(
i
,
f
)
for
i
,
f
in
enumerate
(
value
[
"
features
"
])
]
context
=
super
().
get_context
(
value
,
parent_context
)
context
=
super
().
get_context
(
value
,
parent_context
)
collection_id
=
str
(
uuid4
())
context
[
"
js_map
"
]
=
{
context
[
"
js_map
"
]
=
{
"
tile_server_config
"
:
json
.
dumps
(
TILE_SERVER_CONFIG
),
"
tile_server_config
"
:
json
.
dumps
(
TILE_SERVER_CONFIG
),
"
geojson
"
:
json
.
dumps
(
"
geojson
"
:
json
.
dumps
(
[
[
# Each feature dumped as individual collection to make things consistent.
{
{
# Dump individual features in collection
"
type
"
:
"
FeatureCollection
"
,
"
type
"
:
"
FeatureCollection
"
,
"
properties
"
:
{
"
properties
"
:
{
"
slug
"
:
collection_id
,
"
slug
"
:
f
"
{
f
[
'
properties
'
][
'
id
'
]
}
-
{
slugify
(
f
[
'
properties
'
][
'
collectionTitle
'
])
}
"
,
"
title
"
:
None
,
"
collectionTitle
"
:
f
[
"
properties
"
][
"
collectionTitle
"
],
},
"
collectionDescription
"
:
f
[
"
properties
"
][
"
features
"
:
[
"
collectionDescription
"
_geojson_feature_with_props
(
i
,
f
)
for
i
,
f
in
enumerate
(
value
[
"
features
"
])
],
],
"
image
"
:
f
[
"
properties
"
][
"
image
"
],
},
"
features
"
:
[
f
],
}
}
for
f
in
features
]
]
),
),
}
}
...
...
This diff is collapsed.
Click to expand it.
maps_utils/static/maps_utils/geo-feature-collection.js
+
19
−
13
View file @
309169ce
...
@@ -372,6 +372,8 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -372,6 +372,8 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
:
buildMarkerIcon
(
"
000000
"
,
number
);
:
buildMarkerIcon
(
"
000000
"
,
number
);
const
addMarker
=
(
feature
,
markerPosLatLng
,
onClick
)
=>
{
const
addMarker
=
(
feature
,
markerPosLatLng
,
onClick
)
=>
{
const
tooltipTitle
=
[
feature
.
properties
.
title
,
feature
.
properties
.
collectionTitle
].
filter
(
i
=>
!!
i
).
join
(
'
-
'
);
// add marker
// add marker
const
featureMarker
=
new
L
.
marker
(
markerPosLatLng
,
{
const
featureMarker
=
new
L
.
marker
(
markerPosLatLng
,
{
icon
:
feature
.
properties
.
color
icon
:
feature
.
properties
.
color
...
@@ -385,7 +387,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -385,7 +387,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
),
),
})
})
.
on
(
"
click
"
,
onClick
)
.
on
(
"
click
"
,
onClick
)
.
bindTooltip
(
feature
.
properties
.
t
itle
,
{
.
bindTooltip
(
tooltipT
itle
,
{
className
:
"
geo-feature-collection-tooltip
"
,
className
:
"
geo-feature-collection-tooltip
"
,
direction
:
"
top
"
,
direction
:
"
top
"
,
offset
:
[
0
,
-
64
],
offset
:
[
0
,
-
64
],
...
@@ -573,6 +575,8 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -573,6 +575,8 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
*/
*/
setMuted
(
featureCollection
,
muted
)
{
setMuted
(
featureCollection
,
muted
)
{
featureCollection
.
properties
.
muted
=
muted
;
featureCollection
.
properties
.
muted
=
muted
;
if
(
featureCollection
.
properties
.
categoryObj
)
{
// Update muted flag on category this featureCollection belongs to.
// Update muted flag on category this featureCollection belongs to.
// Category is muted when all featureCollections in it are muted.
// Category is muted when all featureCollections in it are muted.
featureCollection
.
properties
.
categoryObj
.
muted
=
featureCollection
featureCollection
.
properties
.
categoryObj
.
muted
=
featureCollection
...
@@ -581,6 +585,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -581,6 +585,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
.
featureCollections
.
featureCollections
.
map
(
featureCollection
=>
featureCollection
.
properties
.
muted
)
.
map
(
featureCollection
=>
featureCollection
.
properties
.
muted
)
.
reduce
((
a
,
b
)
=>
a
&&
b
,
true
);
.
reduce
((
a
,
b
)
=>
a
&&
b
,
true
);
}
if
(
featureCollection
.
properties
.
muted
)
{
if
(
featureCollection
.
properties
.
muted
)
{
if
(
this
.
featureGroup
.
hasLayer
(
featureCollection
.
properties
.
geoJSONLayer
))
{
if
(
this
.
featureGroup
.
hasLayer
(
featureCollection
.
properties
.
geoJSONLayer
))
{
...
@@ -747,7 +752,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -747,7 +752,7 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
<button class="text-left leading-tight text-xs flex justify-between w-full items-center space-x-2" :class="{'opacity-50': featureCollection.properties.muted}">
<button class="text-left leading-tight text-xs flex justify-between w-full items-center space-x-2" :class="{'opacity-50': featureCollection.properties.muted}">
<div @click="toggleSolo(featureCollection)" class="flex items-center space-x-2" style="min-width: 0;">
<div @click="toggleSolo(featureCollection)" class="flex items-center space-x-2" style="min-width: 0;">
<span v-if="featureCollection.properties.index" class="rounded-full inline-flex items-center justify-center bg-grey-125 font-bold text-center text-2xs w-4 h-4" style="min-width: 1rem">{{ featureCollection.properties.index }}</span>
<span v-if="featureCollection.properties.index" class="rounded-full inline-flex items-center justify-center bg-grey-125 font-bold text-center text-2xs w-4 h-4" style="min-width: 1rem">{{ featureCollection.properties.index }}</span>
<span class="geo-feature-collection__legend-item">{{ featureCollection.properties.
t
itle }}</span>
<span class="geo-feature-collection__legend-item">{{ featureCollection.properties.
collectionT
itle }}</span>
</div>
</div>
<i @click="setMuted(featureCollection, !featureCollection.properties.muted)" class="text-xs" :class="{'ico--eye': !featureCollection.properties.muted, 'ico--eye-off': featureCollection.properties.muted}"></i>
<i @click="setMuted(featureCollection, !featureCollection.properties.muted)" class="text-xs" :class="{'ico--eye': !featureCollection.properties.muted, 'ico--eye-off': featureCollection.properties.muted}"></i>
</button>
</button>
...
@@ -773,13 +778,14 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
...
@@ -773,13 +778,14 @@ const GeoFeatureCollection = Vue.component("GeoFeatureCollection", {
</div>
</div>
<div class="card-headline flex items-center mb-2">
<div class="card-headline flex items-center mb-2">
<span v-if="!currentItem.image && currentItem.index" class="rounded-full inline-flex items-center justify-center bg-grey-125 font-bold text-center text-sm w-6 h-6 mr-2">{{ currentItem.index }}</span>
<span v-if="!currentItem.image && currentItem.index" class="rounded-full inline-flex items-center justify-center bg-grey-125 font-bold text-center text-sm w-6 h-6 mr-2">{{ currentItem.index }}</span>
<span class="flex-1">{{ currentItem.title }}</span>
<span class="flex-1" v-if="currentItem.collectionTitle">{{ currentItem.collectionTitle }}</span>
<span class="flex-1" v-else>{{ currentItem.title }}</span>
</div>
</div>
<div class="card-body-text space-y-4">
<div class="card-body-text space-y-4">
<div v-if="currentItem.collectionDescription">{{ currentItem.collectionDescription }}</div>
<div v-if="currentItem.collectionDescription">{{ currentItem.collectionDescription }}</div>
<div v-if="currentItem.
selfT
itle && currentItem.description">
<div v-if="currentItem.
t
itle && currentItem.description">
<h2 class="head-allcaps-4xs">{{ currentItem.
selfT
itle }}</h2>
<h2 class="head-allcaps-4xs">{{ currentItem.
t
itle }}</h2>
<div v-if="currentItem.description">{{ currentItem.description }}</div>
<div v-if="currentItem.description">{{ currentItem.description }}</div>
</div>
</div>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment