Skip to content

Commit 6bbead4

Browse files
authored
Merge pull request #218 from devinit/feature/reset-map-on-double-click
Feature | reset map on double click
2 parents 666efb7 + 112f0c5 commit 6bbead4

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

components/MapSection/MapSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ const MapSection: FunctionComponent<MapSectionProps> = ({ onChangeLocation, ...p
7777
onChangeLocation(location);
7878
}
7979
};
80-
const onSelectLocationFromMap = (locationName: string): void => {
81-
onSelectLocation(findBoundaryByName(boundaries, locationName.toLowerCase()));
80+
const onSelectLocationFromMap = (locationName?: string): void => {
81+
onSelectLocation(locationName ? findBoundaryByName(boundaries, locationName.toLowerCase()) : undefined);
8282
};
8383

8484
const range = options.indicator && splitByComma(options.indicator.range);

components/SpotlightMap/SpotlightMap.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ const SpotlightMap: FunctionComponent<SpotlightMapProps> = props => {
6868
if (!location) {
6969
if (locationName) {
7070
if (props.onClick) {
71-
props.onClick(
72-
options.formatter ? (options.formatter(locationName, 'boundary') as string) : locationName,
73-
event
74-
);
71+
props.onClick(options.formatter ? (options.formatter(locationName, 'boundary') as string) : locationName);
7572
} else {
7673
flyToLocation(map, locationName, options);
7774
}
@@ -87,13 +84,19 @@ const SpotlightMap: FunctionComponent<SpotlightMapProps> = props => {
8784
showPopup(popup, map, event);
8885
}
8986
};
87+
const onDoubleClick = (): void => {
88+
if (props.onClick) {
89+
props.onClick();
90+
}
91+
};
9092
const onResize = debounce((event: MapboxEvent) => {
9193
const container = event.target.getContainer();
9294
setZoomByContainerWidth(map, container, options);
9395
onResize.cancel();
9496
}, 300);
9597

9698
map.on('click', COLOURED_LAYER, onClick);
99+
map.on('dblclick', COLOURED_LAYER, onDoubleClick);
97100
map.on('resize', onResize);
98101

99102
if (!loading && location && data) {
@@ -111,6 +114,7 @@ const SpotlightMap: FunctionComponent<SpotlightMapProps> = props => {
111114
map.off('mousemove', COLOURED_LAYER, onHover);
112115
map.off('mouseleave', COLOURED_LAYER, onBlur);
113116
map.off('click', COLOURED_LAYER, onClick);
117+
map.off('dblclick', COLOURED_LAYER, onDoubleClick);
114118
map.off('resize', onResize);
115119
popup.remove();
116120
if (timeoutID) {

components/SpotlightMap/utils/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LocationIndicatorData, SpotlightLocation } from '../../../utils';
22
import { FeatureCollection, Geometry, MultiPolygon } from 'geojson';
3-
import { Map, MapMouseEvent } from 'mapbox-gl';
3+
import { Map } from 'mapbox-gl';
44
import { LayerConfig } from './config';
55

66
export interface SpotlightMapProps {
@@ -18,7 +18,7 @@ export interface SpotlightMapProps {
1818
hideParentLayer?: boolean;
1919
locationHandling?: 'flyto' | 'highlight-only'; // highlight-only is the default
2020
onLoad?: (map: Map) => void;
21-
onClick?: (locationName: string, event: MapMouseEvent) => void;
21+
onClick?: (locationName?: string) => void;
2222
}
2323

2424
export interface SpotlightMapGeoJSON {

pages/_document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MyDocument extends Document {
1919
<Head>
2020
<meta
2121
httpEquiv="Content-Security-Policy"
22-
content="connect-src 'self' http://212.111.41.68:8000/ https://api.mapbox.com/ https://events.mapbox.com/events/"
22+
content="connect-src 'self' https://api.devinit.org/ https://api.mapbox.com/ https://events.mapbox.com/events/"
2323
/>
2424
<link href="/static/css/spotlights.min.css" rel="stylesheet" />
2525
<link href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700" rel="stylesheet" />

utils/apollo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fetch from 'node-fetch';
33

44
const cache = new InMemoryCache();
55
const link = createHttpLink({
6-
uri: 'http://212.111.41.68:8000/graphql',
6+
uri: 'https://api.devinit.org/graphql',
77
fetch: fetch as any // window.fetch and node-fetch have conflicting typings
88
});
99

0 commit comments

Comments
 (0)