+
Центр города на карте
+
Нажмите на карту, затем при необходимости перетащите маркер. Вручную координаты вводить не нужно.
+
+
+
+
+
+ {position && }
+
+
+
+ {position ? <>Выбрано: {position[0].toFixed(6)}, {position[1].toFixed(6)}> : 'Точка ещё не выбрана.'}
+
+
;
+}
+
+function CityAvatarEditor({ city }) {
+ const { replaceCity } = useCity();
+ const inputRef = useRef(null);
+ const [uploading, setUploading] = useState(false);
+ const [error, setError] = useState('');
+
+ async function selectImage(event) {
+ const file = event.target.files?.[0];
+ event.target.value = '';
+ if (!file) return;
+ const validationError = isImageValid(file);
+ if (validationError) return setError(validationError);
+
+ setUploading(true);
+ setError('');
+ try {
+ const { data } = await citiesApi.uploadAvatar(city.id, file);
+ replaceCity(data.city);
+ } catch (requestError) {
+ setError(requestError.response?.data?.error || 'Не удалось загрузить изображение.');
+ } finally {
+ setUploading(false);
+ }
+ }
+
+ return
+ {notice &&
{notice}
}
+
{showForm &&
}
{cities.map(city =>
- {city.name}
{city.center_lat != null ? 'Центр карты настроен' : 'Центр карты можно указать при создании'}
+ {city.name}
{city.center_lat != null ? 'Центр карты настроен' : 'Центр карты ещё не указан'}
+
{city.id === activeCity?.id && Активен}
)}
diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js
index a8981b1..bf7fbef 100644
--- a/frontend/src/services/api.js
+++ b/frontend/src/services/api.js
@@ -101,7 +101,14 @@ export const routesApi = {
export const citiesApi = {
getAll: () => api.get('/cities'),
- create: (data) => api.post('/cities', data)
+ create: (data) => api.post('/cities', data),
+ uploadAvatar: (cityId, file) => {
+ const formData = new FormData();
+ formData.append('avatar', file);
+ return api.post(`/cities/${cityId}/avatar`, formData, {
+ headers: { 'Content-Type': 'multipart/form-data' }
+ });
+ }
};
// Route Stops API (привязка остановок к маршрутам)