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

feat: Story Map Data Layers #1872

Merged
merged 43 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9f3c1b8
feat: (WIP) Story map data layers
josebui Apr 30, 2024
c7a0634
feat: (WIP) Add map to story map
josebui Apr 30, 2024
d6de8fc
feat: Title form data layer
josebui May 2, 2024
94aadf2
fix: Fixed remove layer errors, keep map viewport when updating map
josebui May 7, 2024
fea11e0
fix: Filter visualization without tileset ID
josebui May 7, 2024
a5140be
fix: Clean data layers not being used, show selected data layer, adde…
josebui May 7, 2024
1367913
fix: Set initial opacity
josebui May 7, 2024
8fbaa4c
refactor: Moved visualization map components to the correct folder
josebui May 7, 2024
a8080e5
feat: Improved data layer card UI
josebui May 8, 2024
bdfce4e
fix: Fixed UI for data layer bar
josebui May 8, 2024
52155b4
fix: Added conditional chain for titleTransition
josebui May 9, 2024
755a763
feat: Added data layer dialog content
josebui May 9, 2024
227f1d3
fix: Always move to data layer bounds when adding new one
josebui May 9, 2024
07fcaae
fix: Added error handling for json content parser
josebui May 9, 2024
2cc70dd
fix: Added count after fetching
josebui May 9, 2024
7383d5f
fix: Sort data layers by title
josebui May 9, 2024
7ba33e4
fix: Added datalayer validation, fixed strings
josebui May 10, 2024
54ab6ed
test: Added test
josebui May 10, 2024
b2aed94
test: Added test
josebui May 10, 2024
4bf4d26
test: Fixed tests
josebui May 10, 2024
8c71eec
test: Tests fixed
josebui May 10, 2024
5e31380
fix: Added new blue variant, added message when no data maps
josebui May 14, 2024
1e6109a
Update src/sharedData/visualization/components/VisualizationMapLayer.js
josebui May 14, 2024
de5de18
Update src/sharedData/visualization/components/VisualizationMapRemote…
josebui May 14, 2024
248154b
Update src/storyMap/components/StoryMapForm/DataLayerDialog.js
josebui May 14, 2024
6a429ce
Update src/localization/locales/en-US.json
josebui May 14, 2024
0578dba
Update src/localization/locales/en-US.json
josebui May 14, 2024
5a9a5bd
Update src/sharedData/visualization/components/VisualizationMapLayer.js
josebui May 14, 2024
a726908
Update src/gis/components/Map.js
josebui May 14, 2024
33159c2
fix: Improved opacity function
josebui May 15, 2024
245fef3
fix: Remove current data layer
josebui May 15, 2024
5e73b28
fix: Improved method name
josebui May 15, 2024
332d1be
fix: Added on close handler for dialog
josebui Jun 10, 2024
e632f58
chore: Added copy changes
josebui Jun 10, 2024
5a89c87
fix: Fixed test, removed not needed import
josebui Jun 10, 2024
d4d744d
fix: Fixed copy change
josebui Jun 10, 2024
6fe85e9
chore: Added ES translations
josebui Jun 17, 2024
47b4142
Update src/localization/locales/en-US.json
paulschreiber Jul 22, 2024
7e45c28
Update src/gis/components/Map.js
josebui Jul 22, 2024
ef2b3fd
Update src/gis/components/Map.js
josebui Jul 22, 2024
f25026c
Update src/gis/components/Map.js
josebui Jul 22, 2024
3995e04
fix: Improved names and log message
josebui Jul 22, 2024
6d808d1
Update src/localization/locales/es-ES.json
paulschreiber Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/gis/components/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Layer = props => {
return;
}

if (map.getLayer(id)) {
if (map.getStyle() && map.getLayer(id)) {
removeLayer(id);
}

Expand All @@ -42,14 +42,18 @@ const Layer = props => {
...layer,
});

for (const index in events) {
const eventGenerator =
typeof events[index] === 'function'
? events[index]
: () => events[index];
const eventParams = eventGenerator(map);
map.on(...eventParams);
}
const eventsParams =
events?.map((event, index) => {
const eventGenerator =
typeof event === 'function' ? event : () => event;
return eventGenerator(map);
}) || [];
eventsParams.forEach(eventParams => map.on(...eventParams));

return () => {
eventsParams.forEach(eventParams => map.off(...eventParams));
removeLayer(id);
};
}, [
id,
map,
Expand Down
32 changes: 27 additions & 5 deletions src/gis/components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ export const MapProvider = props => {
[map]
);

const removeSource = useCallback(
sourceName => {
if (!map) {
return;
}
try {
map.removeSource(sourceName);
setSources(_.omit(sourceName));
} catch (error) {
logger.error(`Error removing source {$sourceName}`, error);
}
},
[map]
);

const addLayer = useCallback(
(layer, before) => {
if (!map) {
Expand All @@ -243,14 +258,15 @@ export const MapProvider = props => {

const removeLayer = useCallback(
layerId => {
if (!map) {
if (!map?.getStyle()) {
return;
}

try {
map.removeLayer(layerId);
map?.removeLayer(layerId);
setLayers(_.omit(layerId));
} catch (error) {
logger.warn('Error removing layer', error);
logger.error(`Error removing layer ${layerId}`, error);
}
},
[map]
Expand All @@ -273,6 +289,7 @@ export const MapProvider = props => {
addImage,
removeImage,
addSource,
removeSource,
addLayer,
removeLayer,
}}
Expand All @@ -282,7 +299,7 @@ export const MapProvider = props => {
);
};

const Map = props => {
const Map = React.forwardRef((props, ref) => {
const {
id,
mapStyle,
Expand Down Expand Up @@ -325,6 +342,10 @@ const Map = props => {
...(initialLocation ? initialLocation : {}),
});

if (ref) {
ref.current = map;
}

if (padding) {
map.setPadding(padding);
}
Expand Down Expand Up @@ -381,6 +402,7 @@ const Map = props => {
bounds,
disableElevation,
padding,
ref,
]);

useEffect(() => {
Expand Down Expand Up @@ -420,6 +442,6 @@ const Map = props => {
{children}
</Box>
);
};
});

export default withWrapper(Map, MapProvider);
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ test('LandscapeNew: Save from GeoJSON', async () => {
addControl: jest.fn(),
removeControl: jest.fn(),
fitBounds: jest.fn(),
getStyle: jest.fn(),
off: jest.fn(),
getBounds: jest.fn().mockReturnValue({
getSouthWest: jest.fn().mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ test('LandscapeNew: Save form draw polygon boundary', async () => {
addControl: jest.fn(),
removeControl: jest.fn(),
fitBounds: jest.fn(),
getStyle: jest.fn(),
off: jest.fn(),
getBounds: jest.fn().mockReturnValue({
getSouthWest: jest.fn().mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ beforeEach(() => {
addControl: jest.fn(),
removeControl: jest.fn(),
fitBounds: jest.fn(),
getStyle: jest.fn(),
off: jest.fn(),
};
mapboxgl.NavigationControl = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => {
addImage: jest.fn(),
setTerrain: jest.fn(),
fitBounds: jest.fn(),
getStyle: jest.fn(),
hasImage: jest.fn(),
setPadding: jest.fn(),
dragRotate: { disable: jest.fn() },
Expand Down
1 change: 1 addition & 0 deletions src/landscape/components/LandscapeView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ beforeEach(() => {
addControl: jest.fn(),
removeControl: jest.fn(),
fitBounds: jest.fn(),
getStyle: jest.fn(),
off: jest.fn(),
};
});
Expand Down
17 changes: 15 additions & 2 deletions src/localization/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@
"form_delete_chapter_confirm_title": "Delete “{{name}}”?",
"form_delete_chapter_confirm_message": "Are you sure you want to delete the chapter {{name}}?",
"form_delete_chapter_confirm_button_tooltip": "Delete chapter “{{name}}”",
"form_chapter_location_button": "Set Map Location",
"form_chapter_location_button": "Edit Map",
"form_chapter_alignment_buttons": "Set alignment",
"form_chapter_alignment_left": "Align Left",
"form_chapter_alignment_center": "Align Center",
Expand All @@ -924,7 +924,7 @@
"form_location_dialog_title": "Set map location for <1>{{title}}</1>",
"form_location_dialog_title_blank": "Set map location",
"location_dialog_cancel_button": "Cancel",
"location_dialog_confirm_button": "Set Location",
"location_dialog_confirm_button": "Save Map",
"view_title_outline": "Outline",
"breadcrumbs_view": "{{title}}",
"breadcrumbs_tool_home": "Terraso Story Maps",
Expand Down Expand Up @@ -1016,6 +1016,19 @@
"form_location_helper_text_step_3_image_src": "/storyMap/set-map-step-3-en.png",
"form_location_helper_text_step_3_image_alt": "A screenshot of the Set Map Location screen. The “Set Location” button in the top right is circled.",
"form_location_helper_text_bearing_icon_alt": "Bearing",
"form_location_add_data_layer_button": "Add Map Layer",
"form_location_add_data_layer_current": "Map Layer: <1>{{title}}</1>",
"form_location_add_data_layer_dialog_title": "<0>Add a map layer to </0><1>{{title}}</1>",
"form_location_add_data_layer_dialog_title_blank": "Add a map layer to chapter",
"form_location_add_data_layer_dialog_subtitle": "Select a map from your landscape or group",
"form_location_add_data_layer_dialog_description": "Polygons, lines, points from the map will be added to this chapter. This content will be visible to the public when publishing this story map.",
"form_location_add_data_layer_dialog_layers_count_zero": "You haven’t created any maps in Terraso. Make a map in a group or landscape.",
"form_location_add_data_layer_dialog_layers_count_one": "{{count}} map is available",
"form_location_add_data_layer_dialog_layers_count_other": "{{count}} maps are available",
"form_location_add_data_layer_dialog_source_file": "Source file: {{filename}}",
"form_location_add_data_layer_dialog_restricted": "This map has restricted access. Adding it to a story map will make it public. Consulting with $t(user.full_name) is recommended.",
"form_location_add_data_layer_dialog_cancel": "Cancel",
"form_location_add_data_layer_confirm": "Add Map Layer",
"share_dialog_title": "Invite Editors",
"share_dialog_description": "Invite people to edit your story map. <1>Learn more about collaborating on story maps</1>.",
"share_dialog_help_url": "https://terraso.org/help/how-to-manage-editors-for-your-story-map/",
Expand Down
17 changes: 15 additions & 2 deletions src/localization/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@
"form_delete_chapter_confirm_title": "¿Eliminar “{{name}}”?",
"form_delete_chapter_confirm_message": "¿Está seguro de que desea eliminar el capítulo {{name}}?",
"form_delete_chapter_confirm_button_tooltip": "Eliminar el capítulo “{{name}}”",
"form_chapter_location_button": "Establecer ubicación en el mapa",
"form_chapter_location_button": "Editar mapa",
"form_chapter_alignment_buttons": "Establecer alineación",
"form_chapter_alignment_left": "alinear a la izquierda",
"form_chapter_alignment_center": "Alinear al centro",
Expand All @@ -929,7 +929,7 @@
"form_location_dialog_title": "Establecer la ubicación del mapa para <1>{{title}}</1>",
"form_location_dialog_title_blank": "Establecer ubicación en el mapa",
"location_dialog_cancel_button": "Cancelar",
"location_dialog_confirm_button": "Escoger localización",
"location_dialog_confirm_button": "Guardar mapa",
"view_title_outline": "Esquema",
"breadcrumbs_view": "{{title}}",
"breadcrumbs_tool_home": "Story Maps de Terraso",
Expand Down Expand Up @@ -1021,6 +1021,19 @@
"form_location_helper_text_step_3_image_src": "/storyMap/set-map-step-3-es.png",
"form_location_helper_text_step_3_image_alt": "Una captura de pantalla de la pantalla Establecer ubicación en el mapa. El botón “Establecer ubicación” en la parte superior derecha tiene un círculo.",
"form_location_helper_text_bearing_icon_alt": "Rumbo",
"form_location_add_data_layer_button": "Agregar capa de mapa",
"form_location_add_data_layer_current": "Capa de mapa: <1>{{title}}</1>",
"form_location_add_data_layer_dialog_title": "<0>Agregar una capa de mapa a </0><1>{{title}}</1>",
"form_location_add_data_layer_dialog_title_blank": "Agregar una capa de mapa al capítulo",
"form_location_add_data_layer_dialog_subtitle": "Selecciona un mapa de tu paisaje o grupo",
"form_location_add_data_layer_dialog_description": "A este capítulo se agregarán polígonos, líneas y puntos del mapa. Este contenido será visible para el público al publicar este story map.",
"form_location_add_data_layer_dialog_layers_count_zero": "No has creado ningún mapa en Terraso. Haz un mapa en un grupo o paisaje.",
"form_location_add_data_layer_dialog_layers_count_one": "{{count}} mapa está disponible",
"form_location_add_data_layer_dialog_layers_count_other": "{{count}} mapas están disponibles",
"form_location_add_data_layer_dialog_source_file": "Archivo fuente: {{filename}}",
"form_location_add_data_layer_dialog_restricted": "Este mapa tiene acceso restringido. Agregarlo a un story map lo hará público. Se recomienda consultar con $t(user.full_name).",
"form_location_add_data_layer_dialog_cancel": "Cancelar",
"form_location_add_data_layer_confirm": "Agregar capa de mapa",
"share_dialog_title": "Invitar a editores",
"share_dialog_description": "Invita a personas a editar tu story map. <1>Más información sobre cómo colaborar en story maps</1>.",
"share_dialog_help_url": "https://terraso.org/es/ayuda/como-gestionar-los-editores-de-tu-mapa-de-la-historia/",
Expand Down
Loading
Loading