Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Moved compass icon loading to load event
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzhang8 committed Aug 8, 2022
1 parent e68b1c7 commit 762c995
Showing 1 changed file with 34 additions and 39 deletions.
73 changes: 34 additions & 39 deletions frontend/src/components/taskSelection/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ export const TasksMap = ({
positionOptions: {
enableHighAccuracy: true
},
// When active the map will receive updates to the device's location as it changes.
trackUserLocation: true,
// Draw an arrow next to the location dot to indicate which direction the device is heading.
showUserHeading: true
})
);
Expand Down Expand Up @@ -265,6 +263,40 @@ export const TasksMap = ({
}
});

map.loadImage(compassIcon, (error, image) => {
if (error) throw error;

map.addImage('compass', image);

})

map.addSource('point', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, 0]
}
}
]
}
});

map.addLayer({
'id': 'mapillary-compass',
'type': 'symbol',
'source': 'point', // reference the data source
'layout': {
'icon-image': 'compass', // reference the image
'icon-size': 0.5,
'visibility': 'none'
}
})

map.addLayer({
id: 'selected-tasks-border',
type: 'line',
Expand Down Expand Up @@ -444,44 +476,7 @@ export const TasksMap = ({
}
});

map.loadImage(compassIcon, (error, image) => {
if (error) throw error;

if (!map.hasImage('compass')) {
map.addImage('compass', image);
}

if (!map.getSource('point')) {
map.addSource('point', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, 0]
}
}
]
}
});
}

if (!map.getLayer('mapillary-compass')) {
map.addLayer({
'id': 'mapillary-compass',
'type': 'symbol',
'source': 'point', // reference the data source
'layout': {
'icon-image': 'compass', // reference the image
'icon-size': 0.5,
'visibility': 'none'
}
});
}
})



Expand Down

0 comments on commit 762c995

Please sign in to comment.