Extends L.
L.esri.
is a control for auto-complete enabled search. You can find more information and the source code for this plugin here.
Constructor
Constructor | Description |
---|---|
L.esri.Geocoding.geosearch(<GeosearchObject>options) | Creates a new Geosearch control |
Options
Option | Type | Default | Description |
---|---|---|---|
position | String | 'topleft' | Expects a valid Leaflet control position. |
zoom | Boolean | true | Determines whether or not the map will zoom to the result after geocoding is complete. |
use | Boolean or Integer | 12 | Determines if and when the geocoder should use the bounds of the map to filter search results. If true the geocoder will always return results in the current map bounds. If false it will always search the world. If an integer (like 11 ) is passed, the geocoder will use the bounds of the map for searching only if the map is currently zoomed in far enough. |
collapse | Boolean | true | Determines whether or not the geocoder should collapse after a result is found. |
expanded | Boolean | false | Determines whether or not the geocoder starts in an expanded state. |
allow | Boolean | true | If set to true and the user submits the form without a suggestion, the control will geocode the current text in the input. |
providers | Array | See description | An array of providers to search. |
placeholder | String | 'Search for places or addresses' | Placeholder text for the search input. |
title | String | 'Location Search' | Title text for the search input. Shows as a tooltip on hover. |
search | L.lat | null | If set, the geocoder will filter results using the provided static bounding box regardless of the current zoom level of the map, overriding use entirely. |
Events
Event | Data | Description |
---|---|---|
results | <Results | Fired when results are returned from the geocoder. |
Events from each provider will match the events fired by L.esri.
.
Methods
Method | Returns | Description |
---|---|---|
clear() | this | Clears the current text and collapses the control if |
disable() | grays out the input so that addresses cannot be searched. | |
enable() | ungray the input so that addresses can once again be searched. |
Styling
For reference here is the internal DOM structure of the geocoder
<div className="geocoder-control leaflet-control">
<input className="geocoder-control-input leaflet-bar">
<ul className="geocoder-control-suggestions leaflet-bar">
<li className="geocoder-control-suggestion geocoder-control-selected">The Selected Result</li>
<li className="geocoder-control-suggestion">Another Result</li>
</ul>
</div>
By default, ellipses are shown when the text of suggestions is too long. However, you may want to show the entire suggestions text.
The following CSS
rule will show the entire suggestions text, broken onto multiple lines. You will need to add the rule in your own custom stylesheet associated with your project:
.geocoder-control-suggestions .geocoder-control-suggestion {
overflow-wrap: break-word;
word-break: break-all;
overflow: visible;
white-space: break-spaces;
}
Example
Live sample here.
const map = L.map("map").setView([40.91, -96.63], 4);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: '© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const searchControl = L.esri.Geocoding.geosearch({
position: "topright",
placeholder: "Enter an address or place e.g. 1 York St",
useMapBounds: false,
providers: [
L.esri.Geocoding.arcgisOnlineProvider({
apikey: accessToken,
nearby: {
lat: -33.8688,
lng: 151.2093
}
})
]
}).addTo(map);
Providers
The Geosearch
control can also search for results from a variety of sources including Feature Layers and Map Services. This is done with plain text matching and is not "real" geocoding. But it allows you to mix custom results into a search box.
Available Providers
L.esri.
uses the ArcGIS geocoding service.Geocoding.arcgis Online Provider L.esri.
gets results by querying a Feature Layer for text matches.Geocoding.feature Layer Provider L.esri.
uses the find and query methods of ArcGIS Server Map Services to get text matches.Geocoding.map Service Provider L.esri.
uses an ArcGIS Server Geocode Service (and supports suggestions from ArcGIS Server 10.3+ enabled endpoints).Geocoding.geocode Service Provider
All providers share the following options:
Option | Type | Default | Description |
---|---|---|---|
label | String | ' | Text that will be used to group suggestions (when more than one provider is used). |
max | Integer | 5 | Maximum number of results to show for the provider. Hard limit for suggestions from the ArcGIS geocoding service is 15. |
attribution | string | Varies by provider | Adds attribution to the map to credit the source. |
apikey | String | null | Will use this API key to authenticate all calls to the service. |
token | String | null | Will use this token to authenticate all calls to the service. |
arcgisOnlineProvider
Option | Type | Default | Description |
---|---|---|---|
countries | String [ | null | Limit results to one or more countries. Any ISO 3166 2 or 3 digit country code supported by the ArcGIS World Geocode service is allowed. Note: using an array of country codes may result in inaccurate results even when a specific suggestion is supplied. |
categories | String [ | null | Limit results to one or more categories. See the list of valid categories for possible values. |
for | Boolean | false | Indicates whether results will be stored permanently. More information can be found here. |
Results from the arcgis will have an additional properties key which will correspond with all available fields in the World Geocode service |
geocodeServiceProvider
Option | Type | Default | Description |
---|---|---|---|
url | String | Required | The URL for the service that will be searched. |
label | String | ' | Text that will be used to group suggestions under when more than one provider is being used. |
Results from the geocode
will have an additional properties
key which will correspond with all the available fields in the service.
featureLayerProvider
Option | Type | Default | Description |
---|---|---|---|
url | String | Required | The URL for the service that will be searched. |
search | String Array[ | None | An array of fields to search for text. |
format | Function | See Description | Formatting function for the suggestion text. Receives feature information and returns a string. |
buffer | Integer | 1000 | If a service or layer contains points, buffer points by this radius (in meters) to create bounds. |
search | String | 'contain' | Sets how the search is performed against features. Options are contain , start , end , or strict . Please refer to the FeatureLayer Provider JavaScript file for how the different searches are structured. |
featureLayerProvider Methods
Method | Returns | Description |
---|---|---|
orderBy(<String>fieldname, <String>order) | this | Sort output features using values from an individual field. |
Results from the feature
will have an additional properties
key which will contain all the information for the feature and a geojson
key that will contain a GeoJSON representation of the feature.
mapServiceProvider
Option | Type | Default | Description |
---|---|---|---|
url | String | Required | The URL for the service that will be searched. |
search | String Array[ | None | An array of fields to search for text. |
layers | Integer Array[ | [0] | An array of layer identifiers to find text matches on. |
format | Function | See Description | Formatting function for the suggestion text. Receives feature information and returns a string. |
buffer | Integer Array[ | Buffer point results by this radius to create bounds. |
Results from the map
will have an additional properties
key which will contain all the information for the feature and a geojson
key that will contain a GeoJSON representation of the feature.
Events from each provider will match the events fired by L.esri.
.
Results
Property | Type | Description |
---|---|---|
bounds | L. | The bounds around this suggestion. Helpful for zooming to results like cities and states. |
latlng | L. | The center of the results. |
text | String | The entered search text. |
results | [ | An array of result objects. |
Result Object
A single result from a provider. You should not rely on all these properties being present in every result object. Some providers may add additional properties.
Property | Type | Description |
---|---|---|
text | String | The text that was passed to the provider. |
bounds | L. | The bounds around this result. Helpful for zooming to results like cities and states. |
latlng | L. | The center of the result. |
The result object will also contain any additional properties from the provider. See the available providers for more information.