1
0
Fork 0

Fix disappearing mark on the map in station view

Sometimes mark on the map wasn't visible for the initial zoom. This was
result of a race condition between loading the pin image (loadImage and
addImage) and adding the layer with the mark on the map (addLayer).

Adding addLayer call inside the loadImage callback solves the race
condition by having the pin image always loaded before adding the layer.

Signed-off-by: Alfredos-Panagiotis Damkalis <fredy@fredy.gr>
merge-requests/780/head
Alfredos-Panagiotis Damkalis 2019-09-30 16:57:30 +03:00
parent 29a545c1d4
commit cf28114f54
1 changed files with 29 additions and 29 deletions

View File

@ -44,36 +44,36 @@ $(document).ready(function() {
map.on('load', function () {
map.loadImage('/static/img/pin.png', function(error, image) {
map.addImage('pin', image);
});
var map_points = {
'id': 'points',
'type': 'symbol',
'source': {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
parseFloat(station_info.lng),
parseFloat(station_info.lat)]
},
'properties': {
'description': '<a href="/stations/' + station_info.id + '">' + station_info.id + ' - ' + station_info.name + '</a>',
'icon': 'circle'
}
}]
var map_points = {
'id': 'points',
'type': 'symbol',
'source': {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
parseFloat(station_info.lng),
parseFloat(station_info.lat)]
},
'properties': {
'description': '<a href="/stations/' + station_info.id + '">' + station_info.id + ' - ' + station_info.name + '</a>',
'icon': 'circle'
}
}]
}
},
'layout': {
'icon-image': 'pin',
'icon-size': 0.4,
'icon-allow-overlap': true
}
},
'layout': {
'icon-image': 'pin',
'icon-size': 0.4,
'icon-allow-overlap': true
}
};
map.addLayer(map_points);
};
map.addLayer(map_points);
});
map.repaint = true;
});
}