Gathering detailed insights and metrics for react-map-gl-geocoder
Gathering detailed insights and metrics for react-map-gl-geocoder
Gathering detailed insights and metrics for react-map-gl-geocoder
Gathering detailed insights and metrics for react-map-gl-geocoder
@mapbox/mapbox-gl-geocoder
A geocoder control for Mapbox GL JS
@maplibre/maplibre-gl-geocoder
A geocoder control for Maplibre GL JS
react-map-gl
React components for Mapbox GL JS-compatible libraries
@types/mapbox__mapbox-gl-geocoder
TypeScript definitions for @mapbox/mapbox-gl-geocoder
npm install react-map-gl-geocoder
53.6
Supply Chain
86.8
Quality
70.6
Maintenance
50
Vulnerability
95.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
122 Stars
119 Commits
29 Forks
4 Watching
37 Branches
4 Contributors
Updated on 07 Oct 2024
Minified
Minified + Gzipped
JavaScript (88.3%)
HTML (11.7%)
Cumulative downloads
Total Downloads
Last day
-18.9%
616
Compared to previous day
Last week
13.1%
3,577
Compared to previous week
Last month
-8.6%
14,682
Compared to previous month
Last year
-25.4%
202,753
Compared to previous year
1
React wrapper for mapbox-gl-geocoder for use with react-map-gl.
npm
$ npm install react-map-gl-geocoder
or
Yarn
$ yarn add react-map-gl-geocoder
Import:
1import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css'
or
Link tag in header:
1<link href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.2.0/mapbox-gl-geocoder.css' rel='stylesheet' />
Only mapRef
and mapboxApiAccessToken
are required.
All non-primitive prop values besides mapRef
and containerRef
should be memoized.
Name | Type | Default | Description |
---|---|---|---|
mapRef | Object | Ref for react-map-gl map component. | |
containerRef | Object | This can be used to place the geocoder outside of the map. The position prop is ignored if this is passed in. Example: https://codesandbox.io/s/v0m14q5rly | |
onViewportChange | Function | () => {} | Is passed updated viewport values after executing a query. |
mapboxApiAccessToken | String | https://www.mapbox.com/ | |
inputValue | String | Sets the search input value | |
origin | String | "https://api.mapbox.com" | Use to set a custom API origin. |
zoom | Number | 16 | On geocoded result what zoom level should the map animate to when a bbox isn't found in the response. If a bbox is found the map will fit to the bbox . |
placeholder | String | "Search" | Override the default placeholder attribute value. |
proximity | Object | A proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority. | |
trackProximity | Boolean | false | If true, the geocoder proximity will automatically update based on the map view. |
collapsed | Boolean | false | If true, the geocoder control will collapse until hovered or in focus. |
clearAndBlurOnEsc | Boolean | false | If true, the geocoder control will clear it's contents and blur when user presses the escape key. |
clearOnBlur | Boolean | false | If true, the geocoder control will clear its value when the input blurs. |
bbox | Array | A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box. | |
types | String | A comma seperated list of types that filter results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type for available types. | |
countries | String | A comma separated list of country codes to limit results to specified country or countries. | |
minLength | Number | 2 | Minimum number of characters to enter before results are shown. |
limit | Number | 5 | Maximum number of results to show. |
language | String | Specify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas. | |
filter | Function | A function which accepts a Feature in the Carmen GeoJSON format to filter out results from the Geocoding API response before they are included in the suggestions list. Return true to keep the item, false otherwise. | |
localGeocoder | Function | A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format. | |
localGeocoderOnly | Boolean | false | If true, indicates that the localGeocoder results should be the only ones returned to the user. If false, indicates that the localGeocoder results should be combined with those from the Mapbox API with the localGeocoder results ranked higher. |
reverseGeocode | Boolean | false | Enable reverse geocoding. Defaults to false. Expects coordinates to be lat, lon. |
enableEventLogging | Boolean | true | Allow Mapbox to collect anonymous usage statistics from the plugin. |
marker | Boolean or Object | true | If true, a Marker will be added to the map at the location of the user-selected result using a default set of Marker options. If the value is an object, the marker will be constructed using these options. If false, no marker will be added to the map. |
render | Function | A function that specifies how the results should be rendered in the dropdown menu. Accepts a single Carmen GeoJSON object as input and return a string. Any html in the returned string will be rendered. Uses mapbox-gl-geocoder's default rendering if no function provided. | |
position | String | "top-right" | Position on the map to which the geocoder control will be added. Valid values are "top-left" , "top-right" , "bottom-left" , and "bottom-right" . |
onInit | Function | () => {} | Is passed Mapbox geocoder instance as param and is executed after Mapbox geocoder is initialized. |
onClear | Function | () => {} | Executed when the input is cleared. |
onLoading | Function | () => {} | Is passed { query } as a param and is executed when the geocoder is looking up a query. |
onResults | Function | () => {} | Is passed { results } as a param and is executed when the geocoder returns a response. |
onResult | Function | () => {} | Is passed { result } as a param and is executed when the geocoder input is set. |
onError | Function | () => {} | Is passed { error } as a param and is executed when an error occurs with the geocoder. |
1import 'mapbox-gl/dist/mapbox-gl.css' 2import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css' 3import React, { useState, useRef, useCallback } from 'react' 4import MapGL from 'react-map-gl' 5import Geocoder from 'react-map-gl-geocoder' 6 7// Ways to set Mapbox token: https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens 8const MAPBOX_TOKEN = 'REPLACE_WITH_YOUR_MAPBOX_TOKEN' 9 10const Example = () => { 11 const [viewport, setViewport] = useState({ 12 latitude: 37.7577, 13 longitude: -122.4376, 14 zoom: 8 15 }); 16 const mapRef = useRef(); 17 const handleViewportChange = useCallback( 18 (newViewport) => setViewport(newViewport), 19 [] 20 ); 21 22 // if you are happy with Geocoder default settings, you can just use handleViewportChange directly 23 const handleGeocoderViewportChange = useCallback( 24 (newViewport) => { 25 const geocoderDefaultOverrides = { transitionDuration: 1000 }; 26 27 return handleViewportChange({ 28 ...newViewport, 29 ...geocoderDefaultOverrides 30 }); 31 }, 32 [] 33 ); 34 35 return ( 36 <div style={{ height: "100vh" }}> 37 <MapGL 38 ref={mapRef} 39 {...viewport} 40 width="100%" 41 height="100%" 42 onViewportChange={handleViewportChange} 43 mapboxApiAccessToken={MAPBOX_TOKEN} 44 > 45 <Geocoder 46 mapRef={mapRef} 47 onViewportChange={handleGeocoderViewportChange} 48 mapboxApiAccessToken={MAPBOX_TOKEN} 49 position="top-left" 50 /> 51 </MapGL> 52 </div> 53 ); 54}; 55 56export default Example
You can use the containerRef
prop to place the Geocoder
component outside of the MapGL
component to avoid propagating the mouse events to the MapGL
component. You can use CSS to position it over the map as shown in this example.
1import 'mapbox-gl/dist/mapbox-gl.css' 2import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css' 3import React, { useState, useRef, useCallback } from 'react' 4import MapGL from 'react-map-gl' 5import Geocoder from 'react-map-gl-geocoder' 6 7// Ways to set Mapbox token: https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens 8const MAPBOX_TOKEN = 'REPLACE_WITH_YOUR_MAPBOX_TOKEN' 9 10const Example = () => { 11 const [viewport, setViewport] = useState({ 12 latitude: 37.7577, 13 longitude: -122.4376, 14 zoom: 8, 15 }); 16 const geocoderContainerRef = useRef(); 17 const mapRef = useRef(); 18 const handleViewportChange = useCallback( 19 (newViewport) => setViewport(newViewport), 20 [] 21 ); 22 23 return ( 24 <div style={{ height: "100vh" }}> 25 <div 26 ref={geocoderContainerRef} 27 style={{ position: "absolute", top: 20, left: 20, zIndex: 1 }} 28 /> 29 <MapGL 30 ref={mapRef} 31 {...viewport} 32 width="100%" 33 height="100%" 34 onViewportChange={handleViewportChange} 35 mapboxApiAccessToken={MAPBOX_TOKEN} 36 > 37 <Geocoder 38 mapRef={mapRef} 39 containerRef={geocoderContainerRef} 40 onViewportChange={handleViewportChange} 41 mapboxApiAccessToken={MAPBOX_TOKEN} 42 position="top-left" 43 /> 44 </MapGL> 45 </div> 46 ); 47};
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
94 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More