Skip to content

Commit

Permalink
➕ [#2176] added gesture handling for leaflet
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed Aug 1, 2023
1 parent 1c65e38 commit a25bfd2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"immer": "^9.0.6",
"leaflet": "^1.7.1",
"leaflet-geosearch": "^3.8.0",
"leaflet-gesture-handling": "^1.2.2",
"microscope-sass": "^2.0.0",
"moment": "^2.29.1",
"proj4leaflet": "^1.0.2",
Expand Down
10 changes: 10 additions & 0 deletions src/components/Map/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {GeoSearchControl} from 'leaflet-geosearch';
import {GestureHandling} from 'leaflet-gesture-handling';
import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';
import React, {useCallback, useContext, useEffect} from 'react';
Expand Down Expand Up @@ -95,6 +96,7 @@ const LeaftletMap = ({
}}
/>
{disabled ? <DisabledMapControls /> : <CaptureClick setMarker={onMarkerSet} />}
<GestureHandlingSetter />
</MapContainer>
);
};
Expand All @@ -113,6 +115,7 @@ const MapView = ({coordinates = null}) => {
if (!coordinates.filter(value => isFinite(value)).length === 2) return;
map.setView(coordinates);
}, [map, coordinates]);

// rendering is done by leaflet, so just return null
return null;
};
Expand Down Expand Up @@ -251,4 +254,11 @@ CaptureClick.propTypes = {
setMarker: PropTypes.func.isRequired,
};

const GestureHandlingSetter = () => {
const map = useMap();
map.gestureHandling.enable();
map.addHandler('gestureHandling', GestureHandling);
return null;
};

export default LeaftletMap;
1 change: 1 addition & 0 deletions src/scss/components/_leaflet-map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import 'leaflet-geosearch/dist/geosearch.css';

@import '../mixins/prefix';
@import 'leaflet-gesture-handling/dist/leaflet-gesture-handling.css';

.#{prefix(leaflet-map)} {
height: 400px;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9866,6 +9866,11 @@ leaflet-geosearch@^3.8.0:
"@googlemaps/js-api-loader" "^1.14.3"
leaflet "^1.6.0"

leaflet-gesture-handling@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/leaflet-gesture-handling/-/leaflet-gesture-handling-1.2.2.tgz#ea10afb94f2d477d77d47beb21e409ed327df07a"
integrity sha512-Blf5V4PoNphWkzL7Y1qge+Spkd4OCQ2atjwUNhMhLIcjKzPcBH++x/lwOinaR9jSqLWqJ6oKYO8d0XdTffy4hQ==

leaflet@^1.6.0, leaflet@^1.7.1:
version "1.9.4"
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
Expand Down

0 comments on commit a25bfd2

Please sign in to comment.