smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.02k stars 271 forks source link

Can not pan map after select geosearch result #281

Closed zamronypj closed 3 years ago

zamronypj commented 3 years ago

I use leaflet-geosearch 3.0.5. I do not use leaflet-geosearch own marker as I want to use my own draggable marker.

Before select search result, I can pan map or drag my own marker. When user select search result, I set my draggable marker position based on selected address location and map is centered to marker. It works fine.

The problem is after that I can not pan map when I drag outside marker. I can only drag marker. This is my code.

<script src='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.js'></script>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'></script>
<script src="https://unpkg.com/leaflet-geosearch@3.0.5/dist/geosearch.umd.js"></script>

<script>
$(document).ready(function(){
    var centerView = [{{ config('map.mapbox.center.latitude') }}, {{ config('map.mapbox.center.longitude') }}];

    L.mapbox.accessToken = '{{ config('map.mapbox.key') }}';

    var map = L.mapbox.map('map')
        .setView(centerView, {{ config('map.mapbox.zoom') }})
        .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'))
        .addControl(new L.Control.Fullscreen())
        .addControl(
            new GeoSearch.GeoSearchControl({
                showMarker : false,
                autoClose : true,
                searchLabel : 'Search address',
                notFoundMessage : 'Address is not found',
                provider: new GeoSearch.OpenStreetMapProvider()
            })
        );

    var marker = L.marker(centerView, {
        draggable: true
    }).addTo(map);

    //handle geocoder event when location is found
    map.on('geosearch/showlocation', function(e) {
        var newLatLng = new L.LatLng(e.location.y, e.location.x);
        marker.setLatLng(newLatLng);
        $('#latitude').val(newLatLng.lat);
        $('#longitude').val(newLatLng.lng);
    });

    var ondragend = function () {
        var ll = marker.getLatLng();
        $('#latitude').val(ll.lat);
        $('#longitude').val(ll.lng);
    };

    // every time the marker is dragged, update the form
    marker.on('dragend', ondragend);

    // set the initial values in the form
    ondragend();

});
</script>
sgrandstrand commented 3 years ago

I had a similar issue. Once I updated the cdn to the most recent version (3.3.2) the issue was fixed.

smeijer commented 3 years ago

Closing as this doesn't apply to the latest version. Thanks for letting us know @sgrandstrand!

zamronypj commented 3 years ago

@sgrandstrand Ok thanks @smeijer I will try upgrade asap and will report back

zamronypj commented 3 years ago

@smeijer I can confirm, upgrading to 3.3.2 fix issue.

smeijer commented 3 years ago

Thanks for reporting back @zamronyp