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

after clicking on map it changes center of the map #180

Open
VardgesHA777 opened this issue Aug 5, 2023 · 3 comments
Open

after clicking on map it changes center of the map #180

VardgesHA777 opened this issue Aug 5, 2023 · 3 comments

Comments

@VardgesHA777
Copy link

I am using react-leaflet version 4, and installed leaflet-measure, but when i clicked [Create a new measurement] and then clicked on Map my map center has been changed.

import { useEffect } from "react";
import { MapContainer, TileLayer, useMap } from "react-leaflet";
import * as L from "leaflet";
import "leaflet-measure";
import '../../components/LeafletRuler/leaflet-ruler.css'
import "leaflet/dist/leaflet.css";

const Map = () => {
const position = [51.505, -0.09];

function MeasureControl() {
    const map = useMap();

    useEffect(() => {
        let measureControl = new L.Control.Measure({
            position: 'topright',
            lineColor: 'blue'
        });
        map.on('measurefinish', function(evt) {
            console.log('this is measurement area')
            console.log(evt)
        });
        measureControl.addTo(map);
    }, []); // Add the control when the map reference changes

    return null;
}

return (
    <div>
        <MapContainer center={position} zoom={13} style={{ height: "100vh" }}>
            <TileLayer
                attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            />
            <MeasureControl />
        </MapContainer>
    </div>
);

};

export default Map;

@HugoP27
Copy link

HugoP27 commented Aug 10, 2023

I also started having this issue with the new leaflet version, have you managed to find a solution yet?

@emilhe
Copy link

emilhe commented Aug 10, 2023

I am also having this issue. Any solution found?

EDIT: A workaround was posted here.

@HugoP27
Copy link

HugoP27 commented Aug 10, 2023

#171 has a workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants