Add track on project

This commit is contained in:
2024-02-26 22:44:19 +01:00
parent 0cd509a99d
commit 25ff80ad7a
6 changed files with 81 additions and 29 deletions

View File

@@ -144,13 +144,17 @@ class Project extends PhpObject {
if($sCodeName != '' && !Converter::isGeoJsonValid($sCodeName)) Converter::convertToGeoJson($sCodeName); if($sCodeName != '' && !Converter::isGeoJsonValid($sCodeName)) Converter::convertToGeoJson($sCodeName);
$asProject['geofilepath'] = Spot::addTimestampToFilePath(GeoJson::getDistFilePath($sCodeName)); //$asProject['geofilepath'] = Spot::addTimestampToFilePath(GeoJson::getDistFilePath($sCodeName));
$asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Gpx::getDistFilePath($sCodeName)); $asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Gpx::getDistFilePath($sCodeName));
$asProject['codename'] = $sCodeName; $asProject['codename'] = $sCodeName;
} }
return $bSpecificProj?$asProject:$asProjects; return $bSpecificProj?$asProject:$asProjects;
} }
public function getGeoJson() {
return json_decode(file_get_contents(GeoJson::getDistFilePath($this->sCodeName)), true);
}
public function getProject() { public function getProject() {
return $this->getProjects($this->getProjectId()); return $this->getProjects($this->getProjectId());
} }

View File

@@ -205,6 +205,10 @@ class Spot extends Main
$this->oProject->setProjectId($iProjectId); $this->oProject->setProjectId($iProjectId);
} }
public function getProjectGeoJson() {
return self::getJsonResult(true, '', $this->oProject->getGeoJson());
}
public function updateProject() { public function updateProject() {
$bNewMsg = false; $bNewMsg = false;
$bSuccess = true; $bSuccess = true;

View File

@@ -39,6 +39,9 @@ if($sAction!='')
case 'markers': case 'markers':
$sResult = $oSpot->getMarkers(); $sResult = $oSpot->getMarkers();
break; break;
case 'geojson':
$sResult = $oSpot->getProjectGeoJson();
break;
case 'next_feed': case 'next_feed':
$sResult = $oSpot->getNextFeed($iId); $sResult = $oSpot->getNextFeed($iId);
break; break;

View File

@@ -1,6 +1,6 @@
<script> <script>
import 'maplibre-gl/dist/maplibre-gl.css'; import 'maplibre-gl/dist/maplibre-gl.css';
import { Map, NavigationControl, Marker } from 'maplibre-gl'; import { Map, NavigationControl, Marker, LngLatBounds } from 'maplibre-gl';
import simplebar from 'simplebar-vue'; import simplebar from 'simplebar-vue';
@@ -39,8 +39,12 @@ export default {
user: {name:'', email:''}, user: {name:'', email:''},
baseMaps: {}, baseMaps: {},
baseMap: null, baseMap: null,
map: {}, messages: null,
hikeTypes: ['main', 'off-track', 'hitchhiking'] map: null,
hikes: {
colors:{'main':'#00ff78', 'off-track':'#0000ff', 'hitchhiking':'#FF7814'},
width: 4
}
}; };
}, },
computed: { computed: {
@@ -155,6 +159,7 @@ export default {
//Get Map Info //Get Map Info
const aoMarkers = await this.spot.get2('markers', {id_project: this.project.id}); const aoMarkers = await this.spot.get2('markers', {id_project: this.project.id});
this.baseMaps = aoMarkers.maps; this.baseMaps = aoMarkers.maps;
this.messages = aoMarkers.messages;
//Base maps (raster tiles) //Base maps (raster tiles)
let asSources = {}; let asSources = {};
@@ -176,6 +181,7 @@ export default {
} }
//Map //Map
if(this.map) this.map.remove();
this.map = new Map({ this.map = new Map({
container: 'map', container: 'map',
style: { style: {
@@ -183,19 +189,68 @@ export default {
sources: asSources, sources: asSources,
layers: asLayers layers: asLayers
}, },
center: [-122.45427081556572, 42.17865477384241],
zoom: 5,
attributionControl: false attributionControl: false
}); });
new Marker() this.map.once('load', async () => {
.setLngLat([-122.45427081556572, 42.17865477384241]) //Track
.addTo(this.map); const oTrack = await this.spot.get2('geojson', {id_project: this.project.id});
this.map.addSource('track', {
'type': 'geojson',
'data': oTrack
});
//Toggle only when map is ready, for the tilt effet //Color mapping
this.toggleFeedPanel(!this.mobile); let asColorMapping = ['match', ['get', 'type']];
for(const sHikeType in this.hikes.colors) {
asColorMapping.push(sHikeType);
asColorMapping.push(this.hikes.colors[sHikeType]);
}
asColorMapping.push('black'); //fallback value
this.map.once('load', () => { //Track layer
this.map.addLayer({
'id': 'track',
'type': 'line',
'source': 'track',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': asColorMapping,
'line-width': this.hikes.width
}
});
//Centering map
let oBounds = new LngLatBounds();
if(
this.project.mode == this.spot.consts.modes.blog &&
this.messages.length > 0 &&
this.$parent.hash.items[2] != 'message'
) {
//Fit to last message
let oLastMsg = this.messages[this.messages.length - 1];
oBounds.extend(new LngLat(oLastMsg.longitude, oLastMsg.latitude));
}
else {
//Fit to track
for(const iFeatureId in oTrack.features) {
oBounds = oTrack.features[iFeatureId].geometry.coordinates.reduce(
(bounds, coord) => {
return bounds.extend(coord);
},
oBounds
);
}
}
await this.map.fitBounds(oBounds, {padding: 20, animate: false});
//Toggle only when map is ready, for the tilt effet
this.toggleFeedPanel(!this.mobile);
//Default Basemap
this.baseMap = this.baseMaps.filter((asBM)=>asBM.default_map)[0].codename; this.baseMap = this.baseMaps.filter((asBM)=>asBM.default_map)[0].codename;
}); });
@@ -399,8 +454,8 @@ export default {
<SpotIcon :icon="settingsPanelOpen?'prev':'menu'" /> <SpotIcon :icon="settingsPanelOpen?'prev':'menu'" />
</div> </div>
<div v-if="!mobile" id="legend" class="map-control settings-control map-control-bottom"> <div v-if="!mobile" id="legend" class="map-control settings-control map-control-bottom">
<div v-for="hikeType in hikeTypes" class="track"> <div v-for="(color, hikeType) in hikes.colors" class="track">
<span :class="'line '+hikeType"></span> <span class="line" :style="'background-color:'+color+'; height:'+hikes.width+'px;'"></span>
<span class="desc">{{ spot.lang('track_'+hikeType) }}</span> <span class="desc">{{ spot.lang('track_'+hikeType) }}</span>
</div> </div>
</div> </div>

View File

@@ -160,20 +160,9 @@ $panel-actual-width: min(#{$panel-width}, #{$panel-width-max});
white-space: nowrap; white-space: nowrap;
.line { .line {
width: 2em; width: 2em;
height: 4px;
display: inline-block; display: inline-block;
border-radius: 2px; border-radius: 2px;
vertical-align: middle; vertical-align: middle;
&.main {
background-color: $track-main-color;
}
&.off-track {
background-color: $track-off-track-color;
}
&.hitchhiking {
background-color: $track-hitchhiking-color;
}
} }
.desc { .desc {

View File

@@ -21,9 +21,6 @@ $title-color: $post-color;
$subtitle-color: #999; $subtitle-color: #999;
//Legend colors //Legend colors
$track-main-color: #00ff78;
$track-off-track-color: #0000ff;
$track-hitchhiking-color: #FF7814;
$legend-color: $post-color; $legend-color: $post-color;
@import 'page.project.map'; @import 'page.project.map';
@@ -77,7 +74,7 @@ $legend-color: $post-color;
top: 1px; top: 1px;
} }
.fa-track-end { .fa-track-end {
color: $track-hitchhiking-color; color: #FF7814;
} }
} }
} }