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

Marker switch on learn/local #37163

Merged
merged 3 commits into from
Oct 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 49 additions & 55 deletions apps/src/sites/code.org/pages/public/learn/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,63 +156,57 @@ function loadMap(locations) {
center: [lng, lat]
});
map.on('load', function() {
map.loadImage(
'https://docs.mapbox.com/mapbox-gl-js/assets/custom_marker.png',
function(error, image) {
if (error) {
logToCloud.addPageAction(
logToCloud.PageAction.MapboxMarkerLoadError,
{
error
}
);
throw error;
}
map.addImage('custom-marker', image);
map.addSource('places', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: featureList
}
});
// Add a layer showing the places.
map.addLayer({
id: 'places',
type: 'symbol',
source: 'places',
layout: {
'icon-image': 'custom-marker',
'icon-allow-overlap': true
}
});

// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'places', function(e) {
var coordinates = e.features[0].geometry.coordinates.slice();

// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
resultList(featureList, lng, lat, e.features[0].properties.index + 1);
createPopUp(e.features[0]);
});

// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'places', function() {
map.getCanvas().style.cursor = 'pointer';
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'places', function() {
map.getCanvas().style.cursor = '';
map.loadImage('/images/map-markers/dot-marker.png', function(error, image) {
if (error) {
logToCloud.addPageAction(logToCloud.PageAction.MapboxMarkerLoadError, {
error
});
throw error;
}
);
map.addImage('dot-marker', image);
map.addSource('places', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: featureList
}
});
// Add a layer showing the places.
map.addLayer({
id: 'places',
type: 'symbol',
source: 'places',
layout: {
'icon-image': 'dot-marker',
'icon-allow-overlap': true
}
});

// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'places', function(e) {
var coordinates = e.features[0].geometry.coordinates.slice();

// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
resultList(featureList, lng, lat, e.features[0].properties.index + 1);
createPopUp(e.features[0]);
});

// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'places', function() {
map.getCanvas().style.cursor = 'pointer';
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'places', function() {
map.getCanvas().style.cursor = '';
});
});
});
// builds the side menu with the list of classes
if (featureList.length > 0) {
Expand Down