feat: Extract zoomIn and zoomOut functions to separate file
- Moved zoomIn and zoomOut functions from MapComponent.js to a new file zoomUtils.js in the utils directory. - Updated MapComponent.js to import and use the zoomIn and zoomOut functions from the new file. - This change improves code modularity and readability.
This commit is contained in:
@@ -79,6 +79,7 @@ import { MAP_VERSION } from "../config/settings";
|
|||||||
import * as layers from "../config/layers.js";
|
import * as layers from "../config/layers.js";
|
||||||
import useMapContextMenu from "./useMapContextMenu.js";
|
import useMapContextMenu from "./useMapContextMenu.js";
|
||||||
import { openInSameWindow } from "../utils/openInSameWindow";
|
import { openInSameWindow } from "../utils/openInSameWindow";
|
||||||
|
import { zoomIn, zoomOut } from "../utils/zoomUtils";
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
//-------------------- MapComponent -----------------------------------
|
//-------------------- MapComponent -----------------------------------
|
||||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||||
@@ -234,20 +235,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
//-----Kontextmenu----------------
|
//-----Kontextmenu----------------
|
||||||
|
|
||||||
const zoomIn = (e) => {
|
|
||||||
initMap.flyTo(e.latlng, 12);
|
|
||||||
//console.log("ZoomIn koordinaten in MapComponent", e.latlng);
|
|
||||||
// Speichern der Daten in LocalStorage
|
|
||||||
localStorage.setItem("mapZoom", map.getZoom());
|
|
||||||
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
|
||||||
};
|
|
||||||
|
|
||||||
const zoomOut = (e) => {
|
|
||||||
fly();
|
|
||||||
localStorage.setItem("mapZoom", map.getZoom());
|
|
||||||
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
|
||||||
};
|
|
||||||
const centerHere = (e) => {
|
const centerHere = (e) => {
|
||||||
initMap.panTo(e.latlng);
|
initMap.panTo(e.latlng);
|
||||||
};
|
};
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodeMap 11.07.2024",
|
"name": "nodeMap 12.07.2024",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
15
utils/zoomUtils.js
Normal file
15
utils/zoomUtils.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// utils/zoomUtils.js
|
||||||
|
export const zoomIn = (e, map) => {
|
||||||
|
map.flyTo(e.latlng, 12);
|
||||||
|
localStorage.setItem("mapZoom", map.getZoom());
|
||||||
|
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const zoomOut = (map) => {
|
||||||
|
const x = 51.41321407879154;
|
||||||
|
const y = 7.739617925303934;
|
||||||
|
const zoom = 7;
|
||||||
|
map.flyTo([x, y], zoom);
|
||||||
|
localStorage.setItem("mapZoom", map.getZoom());
|
||||||
|
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user