Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ const CustomFeatureInfoTemplate: any = () => {
content: string;
lngLat: { lng: number; lat: number };
} | null>(null);
const mapHook = useMap({
mapId: undefined,
});

const initializedRef = useRef(false);

useEffect(() => {
if (!mapHook.map || initializedRef.current) return;

initializedRef.current = true;
mapHook.map.map.flyTo({ center: [2.3522, 48.8566], zoom: 12 });
}, [mapHook.map]);

const handleFeatureInfoSuccess = (content: string, lngLat: { lng: number; lat: number }) => {
setFeatureInfoData({ content, lngLat });
Expand Down
16 changes: 10 additions & 6 deletions packages/react-maplibre/src/components/MlWmsLoader/MlWmsLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,27 @@ const defaultGetFeatureInfoUrlParameters = {
*/
const MlWmsLoader = (props: MlWmsLoaderProps) => {
// Merge defaults with props using useMemo for stable references
// The dependencies are the prop objects - if consumers pass inline objects,
// they should memoize them. This follows standard React patterns.
// Use JSON.stringify for stable dependency comparison to prevent reinitialization
// when consumers pass inline objects as props
const baseUrlParametersJson = JSON.stringify(props.baseUrlParameters);
const baseUrlParameters = useMemo(
() => ({ ...defaultBaseUrlParameters, ...props.baseUrlParameters }),
[props.baseUrlParameters]
[baseUrlParametersJson]
);
const getCapabilitiesUrlParametersJson = JSON.stringify(props.getCapabilitiesUrlParameters);
const getCapabilitiesUrlParameters = useMemo(
() => ({ ...defaultGetCapabilitiesUrlParameters, ...props.getCapabilitiesUrlParameters }),
[props.getCapabilitiesUrlParameters]
[getCapabilitiesUrlParametersJson]
);
const getMapUrlParametersJson = JSON.stringify(props.getMapUrlParameters);
const getMapUrlParameters = useMemo(
() => ({ ...defaultGetMapUrlParameters, ...props.getMapUrlParameters }),
[props.getMapUrlParameters]
[getMapUrlParametersJson]
);
const getFeatureInfoUrlParametersJson = JSON.stringify(props.getFeatureInfoUrlParameters);
const getFeatureInfoUrlParameters = useMemo(
() => ({ ...defaultGetFeatureInfoUrlParameters, ...props.getFeatureInfoUrlParameters }),
[props.getFeatureInfoUrlParameters]
[getFeatureInfoUrlParametersJson]
);

const featureInfoSuccessRef = useRef(props.featureInfoSuccess);
Expand Down
Loading