Hover opening popup on tracks

This commit is contained in:
2019-01-27 00:28:24 +01:00
parent 0ea31c8ff2
commit 3149a80fa5
5 changed files with 39 additions and 26 deletions

View File

@@ -66,8 +66,8 @@ oSpot.pageInit = function(asHash)
url: self.vars(['project', 'geofile']), url: self.vars(['project', 'geofile']),
mimeType: 'application/json' mimeType: 'application/json'
}) })
).done(function(oMessages, aoTracks) { ).done(function(aoMessages, aoTracks) {
buildSpotMessages(oMessages[0]['data'], aoTracks[0]); buildSpotMessages(aoMessages[0]['data'], aoTracks[0]);
}); });
//Posts //Posts
@@ -75,7 +75,7 @@ oSpot.pageInit = function(asHash)
initPosts(); initPosts();
}; };
function buildSpotMessages(oMessages, aoTracks){ function buildSpotMessages(aoMessages, aoTracks){
//Build Feed //Build Feed
self.tmp('updatable', true); self.tmp('updatable', true);
@@ -90,12 +90,11 @@ function buildSpotMessages(oMessages, aoTracks){
//Tile layers //Tile layers
var oMapBoxSat = L.tileLayer(self.tmp('tile_api'), {id: 'mapbox.satellite', minZoom: 0, maxZoom: 19}), var oMapBoxSat = L.tileLayer(self.tmp('tile_api'), {id: 'mapbox.satellite', minZoom: 0, maxZoom: 19}),
//oOpenTopoMap = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {id: 'OpenTopoMap', minZoom: 2, maxZoom: 19}); oOpenTopoMap = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {id: 'OpenTopoMap', minZoom: 2, maxZoom: 19}),
//oMapBoxStreet = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token='+self.vars('mapbox_key'), {id: 'mapbox.streets'}), //oMapBoxStreet = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token='+self.vars('mapbox_key'), {id: 'mapbox.streets'}),
oIgnSpain = L.tileLayer(self.tmp('tile_api'), {id: 'ign.es', minZoom: 1, maxZoom: 20}), oIgnSpain = L.tileLayer(self.tmp('tile_api'), {id: 'ign.es', minZoom: 1, maxZoom: 20}),
oIgnFrance = L.tileLayer(self.tmp('tile_api'), {id: 'ign.fr', minZoom: 0, maxZoom: 18, tileSize: 256}), oIgnFrance = L.tileLayer(self.tmp('tile_api'), {id: 'ign.fr', minZoom: 0, maxZoom: 18, tileSize: 256}),
oLinz = L.tileLayer(self.tmp('tile_api'), {id: 'linz', maxZoom: 17, continuousWorld: true, attribution: 'Sourced from LINZ. CC BY 4.0'}); oLinz = L.tileLayer(self.tmp('tile_api'), {id: 'linz', maxZoom: 17, continuousWorld: true, attribution: 'Sourced from LINZ. CC BY 4.0'});
//oGoogleSatellite = L.tileLayer('https://mt.google.com/vt/lyrs=y&x={x}&y={y}&z={z}', {id: 'GoogleSatellite', minZoom: 1, maxZoom: 22});
//Map //Map
var oMap = L.map(self.tmp('$Map')[0], { var oMap = L.map(self.tmp('$Map')[0], {
@@ -106,14 +105,23 @@ function buildSpotMessages(oMessages, aoTracks){
//Tracks, colors & popup //Tracks, colors & popup
var oTracks = L.geoJson(aoTracks, { var oTracks = L.geoJson(aoTracks, {
style: function(oTrack) {return {color: self.tmp(['tracktype-colors', oTrack.properties.type]), weight: 4, opacity: 1};} style: function(oTrack) {return {color: self.tmp(['tracktype-colors', oTrack.properties.type]), weight: 4, opacity: 1};},
}) onEachFeature: function (feature, oLayer) {
.bindPopup(function(oLayer) { var asProperties = feature.properties;
var asProperties = oLayer.feature.properties; var $Tooltip = $('<div>', {'class':'track_tooltip'});
var $Tooltip = $('<div>', {'class':'track_tooltip'}); $('<p>', {'class':'name'}).addIcon('fa-track-'+asProperties.type, true).append(asProperties.name).appendTo($Tooltip);
$('<p>', {'class':'name'}).addIcon('fa-track-'+asProperties.type, true).append(asProperties.name).appendTo($Tooltip); if(asProperties.Name != asProperties.description) $('<p>', {'class':'description'}).text(asProperties.description).appendTo($Tooltip);
if(asProperties.Name != asProperties.description) $('<p>', {'class':'description'}).text(asProperties.description).appendTo($Tooltip);
return $Tooltip[0]; oLayer
.bindPopup($Tooltip[0])
.on('mouseover', function(e) {
var popup = e.target.getPopup();
popup.setLatLng(e.latlng).openOn(self.tmp('map'));
})
.on('mouseout', function(e) {
e.target.closePopup();
});
}
}) })
.addTo(oMap); .addTo(oMap);
@@ -121,7 +129,7 @@ function buildSpotMessages(oMessages, aoTracks){
if(self.vars(['project', 'mode'])==self.consts.modes.blog) if(self.vars(['project', 'mode'])==self.consts.modes.blog)
{ {
//Zoom on last message //Zoom on last message
var oLastMsg = oMessages[oMessages.length-1]; var oLastMsg = aoMessages[aoMessages.length-1];
oMap.setView(L.latLng(oLastMsg.latitude, oLastMsg.longitude), 15); oMap.setView(L.latLng(oLastMsg.latitude, oLastMsg.longitude), 15);
//Recenter map to be at the center of 70% (map_offset) of the page, 30% being used by posts //Recenter map to be at the center of 70% (map_offset) of the page, 30% being used by posts
@@ -132,13 +140,14 @@ function buildSpotMessages(oMessages, aoTracks){
//Controls //Controls
L.control.layers({ L.control.layers({
'Satellite': oMapBoxSat, 'Satellite': oMapBoxSat,
'Open Topo Map': oOpenTopoMap,
'IGN (France)': oIgnFrance, 'IGN (France)': oIgnFrance,
'IGN (Espagne)': oIgnSpain, 'IGN (Espagne)': oIgnSpain,
'LINZ (Nouvelle-Zélande)': oLinz 'LINZ (Nouvelle-Zélande)': oLinz
}, null, {position: 'topleft'}).addTo(oMap); }, null, {position: 'topleft'}).addTo(oMap);
//Building messages //Building messages
$.each(oMessages, function(iKey, oMsg){ $.each(aoMessages, function(iKey, oMsg){
//Marker //Marker
var oMarker = L.marker(L.latLng(oMsg.latitude, oMsg.longitude), { var oMarker = L.marker(L.latLng(oMsg.latitude, oMsg.longitude), {
@@ -152,23 +161,28 @@ function buildSpotMessages(oMessages, aoTracks){
}).addTo(oMap); }).addTo(oMap);
//Marker events //Marker events
oMarker.on({ /*oMarker.on({
mouseover: function(){ mouseover: function(){
this.openPopup(); this.openPopup();
}, },
/*mouseout: function(){ mouseout: function(){
},*/ },
click: function(oPoint){ click: function(oPoint){
self.tmp('map').setOffsetView(self.tmp('map_offset'), oPoint.latlng, 15); self.tmp('map').setOffsetView(self.tmp('map_offset'), oPoint.latlng, 15);
} }
}); });*/
//Tooltip //Tooltip
$Tooltip = $('<div>', {'class':'info-window'}) $Tooltip = $('<div>', {'class':'info-window'})
.append($('<h1>').append('Message '+oMsg.type+' #'+oMsg.id_message)) .append($('<h1>')
.append($('<p>', {'class':'time'}).addIcon('fa-time').append(oMsg.formatted_time+' ('+oMsg.relative_time+')')) .append('Message '+oMsg.type+' #'+oMsg.id_message))
.append($('<p>', {'class':'coordinates'}).addIcon('fa-message', false).append('Lat : '+oMsg.latitude+', Lng : '+oMsg.longitude)); .append($('<p>', {'class':'time'})
.addIcon('fa-time')
.append(oMsg.formatted_time+(self.vars(['project', 'mode'])==self.consts.modes.blog?' ('+oMsg.relative_time+')':'')))
.append($('<p>', {'class':'coordinates'})
.addIcon('fa-message', false)
.append('Lat : '+oMsg.latitude+', Lng : '+oMsg.longitude));
//Tooltip pictures //Tooltip pictures
if(oMsg.pics) { if(oMsg.pics) {

View File

@@ -31,4 +31,4 @@ $fa-css-prefix: fa;
.#{$fa-css-prefix}-tasks:before { content: fa-content($fa-var-tasks); } .#{$fa-css-prefix}-tasks:before { content: fa-content($fa-var-tasks); }
.#{$fa-css-prefix}-track-off-track:before { content: fa-content($fa-var-hiking); } .#{$fa-css-prefix}-track-off-track:before { content: fa-content($fa-var-hiking); }
.#{$fa-css-prefix}-track-main:before { content: fa-content($fa-var-hiking); } .#{$fa-css-prefix}-track-main:before { content: fa-content($fa-var-hiking); }
.#{$fa-css-prefix}-track-hitchhiking:before { content: fa-content($fa-var-bus); } .#{$fa-css-prefix}-track-hitchhiking:before { content: fa-content($fa-var-car-side); }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
todo
View File

@@ -2,7 +2,6 @@ To Do List
---------- ----------
- Elevation chart - Elevation chart
- Radio button projects - Radio button projects
- Hover on track segments
- Table for images - Table for images
- Static maps in backend - Static maps in backend
- Device/Spot Class - Device/Spot Class