@navigoo/map-components 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navigoo/map-components",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Reusable React components for mapping and routing in Yaoundé",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,11 +53,11 @@ const MapView: React.FC<MapViewProps> = ({
53
53
  useEffect(() => {
54
54
  if (mapContainerRef.current && !mapRef.current) {
55
55
  mapRef.current = L.map(mapContainerRef.current, {
56
- center: [3.8480, 11.5021], // Centre par défaut : Yaoundé
57
- zoom: 12,
58
- minZoom: 11,
56
+ center: [7.365, 12.3], // Centre approximatif du Cameroun
57
+ zoom: 7, // Zoom ajusté pour voir l'ensemble du Cameroun
58
+ minZoom: 6,
59
59
  maxZoom: 16,
60
- maxBounds: [[3.7, 11.4], [4.0, 11.6]],
60
+ maxBounds: [[1.65, 8.4], [13.08, 16.2]], // Limites pour le Cameroun
61
61
  maxBoundsViscosity: 1.0,
62
62
  });
63
63
 
@@ -102,17 +102,35 @@ const MapView: React.FC<MapViewProps> = ({
102
102
  useEffect(() => {
103
103
  if (!mapRef.current) return;
104
104
 
105
- if (routeLayerRef.current) routeLayerRef.current.clearLayers();
106
- if (markerRef.current) markerRef.current.remove();
107
- if (clickMarkerRef.current) clickMarkerRef.current.remove();
105
+ // Nettoyer les couches précédentes
106
+ if (routeLayerRef.current) {
107
+ routeLayerRef.current.clearLayers();
108
+ }
109
+ if (markerRef.current) {
110
+ markerRef.current.remove();
111
+ markerRef.current = null;
112
+ }
113
+ if (clickMarkerRef.current) {
114
+ clickMarkerRef.current.remove();
115
+ clickMarkerRef.current = null;
116
+ }
117
+
108
118
  routePolylinesRef.current = [];
109
119
 
120
+ // Fonction pour centrer la carte sur un point avec un marqueur
110
121
  const centerOnPoint = async (lat: number, lng: number, placeName: string, zoom: number = 16) => {
111
122
  let displayName = placeName;
112
123
  if (placeName === 'Votre position') {
113
124
  const closestPlace = await apiClient.findClosestPlace(lat, lng);
114
125
  displayName = closestPlace?.name || placeName;
115
126
  }
127
+
128
+ // Supprimer l'ancien marqueur s'il existe
129
+ if (markerRef.current) {
130
+ markerRef.current.remove();
131
+ markerRef.current = null;
132
+ }
133
+
116
134
  mapRef.current!.setView([lat, lng], zoom, { animate: true });
117
135
  markerRef.current = L.marker([lat, lng])
118
136
  .addTo(mapRef.current!)
@@ -121,6 +139,7 @@ const MapView: React.FC<MapViewProps> = ({
121
139
  };
122
140
 
123
141
  if (routes && routes.length > 0) {
142
+ // Gérer les itinéraires
124
143
  let allCoordinates: [number, number][] = [];
125
144
  routes.forEach((route, index) => {
126
145
  const coordinates: [number, number][] = [];
@@ -191,7 +210,7 @@ const MapView: React.FC<MapViewProps> = ({
191
210
  } else if (userLocation) {
192
211
  centerOnPoint(userLocation.latitude, userLocation.longitude, 'Votre position');
193
212
  } else {
194
- mapRef.current!.setView([3.8480, 11.5021], 12, { animate: true });
213
+ mapRef.current!.setView([7.365, 12.3], 7, { animate: true });
195
214
  }
196
215
  }, [apiClient, userLocation, searchedPlace, routes, selectedRouteIndex, setSelectedRouteIndex]);
197
216