Skip to content

Commit

Permalink
feat: update display for route in detail page (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
joselegitan authored Dec 4, 2023
1 parent 6059331 commit b0e1478
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
8 changes: 5 additions & 3 deletions components/Map/MapBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ export default defineNuxtComponent({
initPoiLayer(
features: MapPoi[],
clusterPropertiesValues: string[],
clusterPropertiesKeyExpression: maplibregl.ExpressionSpecification
clusterPropertiesKeyExpression: maplibregl.ExpressionSpecification,
cluster?: boolean
) {
if (this.map.getLayer(POI_LAYER)) {
this.map.removeLayer(POI_LAYER)
Expand Down Expand Up @@ -255,7 +256,7 @@ export default defineNuxtComponent({
this.map.addSource(POI_SOURCE, {
type: 'geojson',
cluster: true,
cluster: cluster || true,
clusterRadius: 32,
clusterProperties: clusterProps,
clusterMaxZoom: 15,
Expand Down Expand Up @@ -378,7 +379,8 @@ export default defineNuxtComponent({
this.markers,
POI_SOURCE,
this.fitBounds,
(feature: ApiPoi) => this.$emit('feature-click', feature)
(feature: ApiPoi) => this.$emit('feature-click', feature),
this.features
)
}
Expand Down
29 changes: 23 additions & 6 deletions components/Map/MapPois.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export default defineNuxtComponent({
>,
default: undefined,
},
fullscreenControl: {
type: Boolean,
default: false,
},
cluster: {
type: Boolean,
default: true,
},
},
setup() {
return {
Expand Down Expand Up @@ -127,12 +135,21 @@ export default defineNuxtComponent({
)
),
]
this.mapBase!.initPoiLayer(this.features, colors, [
'case',
['all', ['has', 'display'], ['has', 'color_fill', ['get', 'display']]],
['get', 'color_fill', ['get', 'display']],
'#000000',
])
this.mapBase!.initPoiLayer(
this.features,
colors,
[
'case',
[
'all',
['has', 'display'],
['has', 'color_fill', ['get', 'display']],
],
['get', 'color_fill', ['get', 'display']],
'#000000',
],
this.cluster
)
if (this.featureIds) {
filterRouteByPoiIds(this.map as maplibregl.Map, this.featureIds)
Expand Down
5 changes: 5 additions & 0 deletions components/PoisCard/PoiCardLight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:picto="icon"
size="lg"
:image="undefined"
:text="poi.properties.position"
/>
{{ name }}
</h3>
Expand Down Expand Up @@ -77,6 +78,10 @@ export default defineNuxtComponent({
type: Object as PropType<ApiPoi>,
required: true,
},
position: {
type: String,
required: false,
},
},
data(): {
Expand Down
6 changes: 4 additions & 2 deletions components/PoisDetails/Route/RouteMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:feature-ids="[poiId]"
:fullscreen-control="true"
:off-map-attribution="true"
:cluster="false"
/>
<div class="detail-wrapper">
<div v-if="points.length > 0" class="detail-left">
Expand Down Expand Up @@ -97,12 +98,13 @@ export default defineNuxtComponent({
},
created() {
this.routeCollection = this.route.features.map((feature) => {
this.routeCollection = this.route.features.map((feature, index) => {
if (feature.properties['route:point:type']) {
const mapPoi = apiRouteWaypointToApiPoi(
feature as ApiRouteWaypoint,
this.colorFill,
this.colorLine
this.colorLine,
(index + 1).toString()
)
this.points.push(mapPoi)
return mapPoi
Expand Down
6 changes: 6 additions & 0 deletions components/UI/TeritorioIconBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
:style="{ backgroundColor: colorFill }"
>
<TeritorioIcon
v-if="!text"
:class="`tw-text-${iconSize}`"
:picto="picto"
:image="image"
/>
<b v-else>{{ text }}</b>
<slot></slot>
</span>
</template>
Expand Down Expand Up @@ -44,6 +46,10 @@ export default defineNuxtComponent({
type: String as PropType<string>,
default: null,
},
text: {
type: String as PropType<string>,
required: false,
},
},
computed: {
Expand Down
4 changes: 3 additions & 1 deletion lib/apiPoiDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const iconMap: { [key: string]: string } = {
export function apiRouteWaypointToApiPoi(
waypoint: ApiRouteWaypoint,
colorFill: string,
colorLine: string
colorLine: string,
position?: string
): ApiPoi {
return {
...waypoint,
Expand All @@ -79,6 +80,7 @@ export function apiRouteWaypointToApiPoi(
color_fill: colorFill,
color_line: colorLine,
},
position,
editorial: {
popup_fields: [
{
Expand Down
17 changes: 13 additions & 4 deletions lib/markerLayerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
LngLatBoundsLike,
FitBoundsOptions,
} from 'maplibre-gl'
import { createApp } from 'vue'
import { createApp, PropType } from 'vue'

import { ApiPoi } from './apiPois'
import { getBBoxFeatures } from './bbox'
Expand Down Expand Up @@ -79,7 +79,8 @@ export function makerHtmlFactory(
colorFill: string,
icon: string,
thumbnail: string | undefined,
size: string | null = null
size: string | null = null,
text?: string
): ITMarker {
// Marker
const el: HTMLElement = document.createElement('div')
Expand All @@ -100,6 +101,7 @@ export function makerHtmlFactory(
picto: icon,
image: thumbnail,
size,
text: text,
}).mount(el)

return marker
Expand All @@ -110,7 +112,8 @@ export function updateMarkers(
markers: { [id: string]: ITMarker },
src: string,
fitBounds: (bounds: LngLatBoundsLike, options: FitBoundsOptions) => void,
markerClickCallBack: ((feature: ApiPoi) => void) | undefined
markerClickCallBack: ((feature: ApiPoi) => void) | undefined,
initFeatures: PropType<ApiPoi[]> = []
) {
const markerIdPrevious = Object.keys(markers)
const markerIdcurrent: string[] = []
Expand Down Expand Up @@ -188,12 +191,18 @@ export function updateMarkers(
}

// Marker
const index = initFeatures.findIndex(
(initFeature) => initFeature.properties.id === props.id
)

markers[id] = makerHtmlFactory(
id,
markerCoords, // Using this to avoid misplaced marker
props.display?.color_fill || '#000000',
props.display?.icon || '#000000',
props['image:thumbnail']
props['image:thumbnail'],
null,
typeof index === 'number' ? index + 1 : undefined
)

// Click handler
Expand Down

0 comments on commit b0e1478

Please sign in to comment.