Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tronçon plus large au survol #156

Merged
merged 6 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/content/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ const { data: geojson } = await useAsyncData(`geojson-${path}`, () => {
.findOne();
});

const features = geojson.value.features;
const features = geojson.value.features.map((feature, index) => ({
id: index,
...feature
}));

const doneFeatures = features.filter(feature => feature.properties.status === 'done');
const doneDistance = getDistance({ features: doneFeatures });
const avancement = Math.round(doneDistance / voie.distance * 100);
Expand Down
47 changes: 35 additions & 12 deletions composables/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ export const useMap = () => {
type: 'line',
source: 'done-sections',
paint: {
'line-width': 4,
'line-width': ['case', ['boolean', ['feature-state', 'hover'], false], 6, 4],
'line-color': ['get', 'color']
}
});

map.on('mouseenter', 'done-sections', () => (map.getCanvas().style.cursor = 'pointer'));
map.on('mouseleave', 'done-sections', () => (map.getCanvas().style.cursor = ''));
applyHoverEffect({ map, layer: 'done-sections' });
}

function plotWipSections({ map, features }: { map: any; features: LineStringFeature[] }) {
Expand Down Expand Up @@ -148,7 +147,7 @@ export const useMap = () => {
type: 'line',
source: 'wip-sections',
paint: {
'line-width': 4,
'line-width': ['case', ['boolean', ['feature-state', 'hover'], false], 6, 4],
'line-color': ['get', 'color'],
'line-dasharray': [0, 2, 2]
}
Expand Down Expand Up @@ -180,8 +179,7 @@ export const useMap = () => {
}
animateDashArray(0);

map.on('mouseenter', 'wip-sections', () => (map.getCanvas().style.cursor = 'pointer'));
map.on('mouseleave', 'wip-sections', () => (map.getCanvas().style.cursor = ''));
applyHoverEffect({ map, layer: 'wip-sections' });
}

function plotPlannedSections({ map, features }: { map: any; features: LineStringFeature[] }) {
Expand All @@ -203,23 +201,22 @@ export const useMap = () => {
if (sections.length === 0) {
return;
}
map.addSource('not-done-sections', {
map.addSource('planned-sections', {
type: 'geojson',
data: { type: 'FeatureCollection', features: sections }
});
map.addLayer({
id: 'not-done-sections',
id: 'planned-sections',
type: 'line',
source: 'not-done-sections',
source: 'planned-sections',
paint: {
'line-width': 4,
'line-width': ['case', ['boolean', ['feature-state', 'hover'], false], 6, 4],
'line-color': ['get', 'color'],
'line-dasharray': [2, 2]
}
});

map.on('mouseenter', 'not-done-sections', () => (map.getCanvas().style.cursor = 'pointer'));
map.on('mouseleave', 'not-done-sections', () => (map.getCanvas().style.cursor = ''));
applyHoverEffect({ map, layer: 'planned-sections' });
}

function plotVarianteSections({ map, features }: { map: any; features: LineStringFeature[] }) {
Expand Down Expand Up @@ -599,6 +596,32 @@ export const useMap = () => {
}
}

function applyHoverEffect({ map, layer }) {
let hoveredLineId = null;
map.on('mousemove', layer, e => {
map.getCanvas().style.cursor = 'pointer';

if (e.features.length > 0) {
if (hoveredLineId !== null) {
map.setFeatureState({ source: layer, id: hoveredLineId }, { hover: false });
}
if (e.features[0].id !== undefined) {
hoveredLineId = e.features[0].id;
if (hoveredLineId !== null) {
map.setFeatureState({ source: layer, id: hoveredLineId }, { hover: true });
}
}
}
});
map.on('mouseleave', layer, () => {
map.getCanvas().style.cursor = '';
if (hoveredLineId !== null) {
map.setFeatureState({ source: layer, id: hoveredLineId }, { hover: false });
}
hoveredLineId = null;
});
}

return {
plotDoneSections,
plotWipSections,
Expand Down
27 changes: 15 additions & 12 deletions pages/[_slug]/carte.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,38 @@
</template>

<script setup>
const { path } = useRoute()
const { path } = useRoute();

const regex = /voie-lyonnaise-(1[0-2]|[1-9])\b/
const line = path.match(regex)[1]
const regex = /voie-lyonnaise-(1[0-2]|[1-9])\b/;
const line = path.match(regex)[1];

// https://github.com/nuxt/framework/issues/3587
definePageMeta({
pageTransition: false,
layout: 'fullscreen',
middleware: 'voie-lyonnaise'
})
});

const mapOptions = {
shrink: true,
onShrinkControlClick: () => {
const route = useRoute()
return navigateTo({ path: `/${route.params._slug}` })
const route = useRoute();
return navigateTo({ path: `/${route.params._slug}` });
}
}
};

const { data: voie } = await useAsyncData(() => {
return queryContent('voies-lyonnaises')
.where({ _type: 'json', _path: `/voies-lyonnaises/ligne-${line}` })
.findOne()
})
.findOne();
});

const features = voie.value.features
const features = voie.value.features.map((feature, index) => ({
id: index,
...feature
}));

const description = `Carte de la Voie Lyonnaise ${line}. Découvrez les tronçons prévus, déjà réalisés, en travaux et ceux reportés après 2026.`
const description = `Carte de la Voie Lyonnaise ${line}. Découvrez les tronçons prévus, déjà réalisés, en travaux et ceux reportés après 2026.`;
useHead({
title: `Carte de la Voie Lyonnaise ${line}`,
meta: [
Expand All @@ -42,5 +45,5 @@ useHead({
{ hid: 'og:description', property: 'og:description', content: description },
{ hid: 'twitter:description', name: 'twitter:description', content: description }
]
})
});
</script>
5 changes: 4 additions & 1 deletion pages/carte-interactive/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const { data: voies } = await useAsyncData(() => {
return queryContent('voies-lyonnaises').where({ _type: 'json' }).find();
});

const features = voies.value.map(voie => voie.features).flat();
const features = voies.value.map(voie => voie.features).flat().map((feature, index) => ({
id: index,
...feature
}));

const description = 'Découvrez la carte interactive des Voies Lyonnaises. Itinéraires rue par rue. Plan régulièrement mis à jour pour une information complète.';
const COVER_IMAGE_URL = 'https://cyclopolis.lavilleavelo.org/cyclopolis.png';
Expand Down