11import * as React from 'react' ;
22import { useState } from 'react' ;
3- import { useControl , Marker , ControlPosition } from 'react-map-gl' ;
4- import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder' ;
3+ import { useControl , Marker , MarkerProps , ControlPosition } from 'react-map-gl' ;
4+ import MapboxGeocoder , { GeocoderOptions } from '@mapbox/mapbox-gl-geocoder' ;
55
6- type GeocoderControlProps = {
6+ type GeocoderControlProps = Omit < GeocoderOptions , 'accessToken' | 'mapboxgl' | 'marker' > & {
77 mapboxAccessToken : string ;
8- origin ?: string ;
9- zoom ?: number ;
10- flyTo ?: boolean | object ;
11- placeholder ?: string ;
12- proximity ?: {
13- longitude : number ;
14- latitude : number ;
15- } ;
16- trackProximity ?: boolean ;
17- collapsed ?: boolean ;
18- clearAndBlurOnEsc ?: boolean ;
19- clearOnBlur ?: boolean ;
20- box ?: [ number , number , number , number ] ;
21- countries ?: string ;
22- types ?: string ;
23- minLength ?: number ;
24- limit ?: number ;
25- language ?: string ;
26- filter ?: ( feature : object ) => boolean ;
27- localGeocoder ?: Function ;
28- externalGeocoder ?: Function ;
29- reverseMode ?: 'distance' | 'score' ;
30- reverseGeocode ?: boolean ;
31- enableEventLogging ?: boolean ;
32- marker ?: boolean | object ;
33- render ?: ( feature : object ) => string ;
34- getItemValue ?: ( feature : object ) => string ;
35- mode ?: 'mapbox.places' | 'mapbox.places-permanent' ;
36- localGeocoderOnly ?: boolean ;
37- autocomplete ?: boolean ;
38- fuzzyMatch ?: boolean ;
39- routing ?: boolean ;
40- worldview ?: string ;
8+ marker ?: boolean | Omit < MarkerProps , 'longitude' | 'latitude' > ;
419
4210 position : ControlPosition ;
4311
@@ -55,6 +23,7 @@ export default function GeocoderControl(props: GeocoderControlProps) {
5523 ( ) => {
5624 const ctrl = new MapboxGeocoder ( {
5725 ...props ,
26+ marker : false ,
5827 accessToken : props . mapboxAccessToken
5928 } ) ;
6029 ctrl . on ( 'loading' , props . onLoading ) ;
@@ -66,7 +35,7 @@ export default function GeocoderControl(props: GeocoderControlProps) {
6635 const location =
6736 result &&
6837 ( result . center || ( result . geometry ?. type === 'Point' && result . geometry . coordinates ) ) ;
69- if ( location ) {
38+ if ( location && props . marker ) {
7039 setMarker ( < Marker { ...props . marker } longitude = { location [ 0 ] } latitude = { location [ 1 ] } /> ) ;
7140 } else {
7241 setMarker ( null ) ;
@@ -80,6 +49,7 @@ export default function GeocoderControl(props: GeocoderControlProps) {
8049 }
8150 ) ;
8251
52+ // @ts -ignore (TS2339) private member
8353 if ( geocoder . _map ) {
8454 if ( geocoder . getProximity ( ) !== props . proximity && props . proximity !== undefined ) {
8555 geocoder . setProximity ( props . proximity ) ;
@@ -94,48 +64,50 @@ export default function GeocoderControl(props: GeocoderControlProps) {
9464 geocoder . setZoom ( props . zoom ) ;
9565 }
9666 if ( geocoder . getFlyTo ( ) !== props . flyTo && props . flyTo !== undefined ) {
97- geocoder . setFlyTo ( props . zoom ) ;
67+ geocoder . setFlyTo ( props . flyTo ) ;
9868 }
9969 if ( geocoder . getPlaceholder ( ) !== props . placeholder && props . placeholder !== undefined ) {
100- geocoder . setPlaceholder ( props . zoom ) ;
70+ geocoder . setPlaceholder ( props . placeholder ) ;
10171 }
10272 if ( geocoder . getCountries ( ) !== props . countries && props . countries !== undefined ) {
103- geocoder . setCountries ( props . zoom ) ;
73+ geocoder . setCountries ( props . countries ) ;
10474 }
10575 if ( geocoder . getTypes ( ) !== props . types && props . types !== undefined ) {
106- geocoder . setTypes ( props . zoom ) ;
76+ geocoder . setTypes ( props . types ) ;
10777 }
10878 if ( geocoder . getMinLength ( ) !== props . minLength && props . minLength !== undefined ) {
109- geocoder . setMinLength ( props . zoom ) ;
79+ geocoder . setMinLength ( props . minLength ) ;
11080 }
11181 if ( geocoder . getLimit ( ) !== props . limit && props . limit !== undefined ) {
112- geocoder . setLimit ( props . zoom ) ;
82+ geocoder . setLimit ( props . limit ) ;
11383 }
11484 if ( geocoder . getFilter ( ) !== props . filter && props . filter !== undefined ) {
115- geocoder . setFilter ( props . zoom ) ;
85+ geocoder . setFilter ( props . filter ) ;
11686 }
11787 if ( geocoder . getOrigin ( ) !== props . origin && props . origin !== undefined ) {
118- geocoder . setOrigin ( props . zoom ) ;
119- }
120- if ( geocoder . getAutocomplete ( ) !== props . autocomplete && props . autocomplete !== undefined ) {
121- geocoder . setAutocomplete ( props . zoom ) ;
122- }
123- if ( geocoder . getFuzzyMatch ( ) !== props . fuzzyMatch && props . fuzzyMatch !== undefined ) {
124- geocoder . setFuzzyMatch ( props . zoom ) ;
125- }
126- if ( geocoder . getRouting ( ) !== props . routing && props . routing !== undefined ) {
127- geocoder . setRouting ( props . zoom ) ;
128- }
129- if ( geocoder . getWorldview ( ) !== props . worldview && props . worldview !== undefined ) {
130- geocoder . setWorldview ( props . zoom ) ;
131- }
88+ geocoder . setOrigin ( props . origin ) ;
89+ }
90+ // Types missing from @types /mapbox__mapbox-gl-geocoder
91+ // if (geocoder.getAutocomplete() !== props.autocomplete && props.autocomplete !== undefined) {
92+ // geocoder.setAutocomplete(props.autocomplete);
93+ // }
94+ // if (geocoder.getFuzzyMatch() !== props.fuzzyMatch && props.fuzzyMatch !== undefined) {
95+ // geocoder.setFuzzyMatch(props.fuzzyMatch);
96+ // }
97+ // if (geocoder.getRouting() !== props.routing && props.routing !== undefined) {
98+ // geocoder.setRouting(props.routing);
99+ // }
100+ // if (geocoder.getWorldview() !== props.worldview && props.worldview !== undefined) {
101+ // geocoder.setWorldview(props.worldview);
102+ // }
132103 }
133104 return marker ;
134105}
135106
136107const noop = ( ) => { } ;
137108
138109GeocoderControl . defaultProps = {
110+ marker : true ,
139111 onLoading : noop ,
140112 onResults : noop ,
141113 onResult : noop ,
0 commit comments