Interface JawgPlacesOptions

Options to configure a Places JS instance.

const options = {
accessToken: '<Access-Token>',
input: '#my-input',
}
interface JawgPlacesOptions {
    accessToken?: string;
    boundary?: BoudaryOptions;
    clearCross?: boolean;
    debounceDelay?: number;
    focus?: FocusOptions;
    focusPoint?: LatLon | (() => LatLon);
    input?: string | HTMLElement;
    language?: string | (() => string);
    layers?:
        | string
        | string[]
        | (() => string)
        | (() => string[]);
    minLength?: number;
    noResultsMessage?: string | false;
    onClear?: (() => void);
    onClick?: ((feature: Feature) => void);
    onClose?: (() => void);
    onError?: ((error: any) => void);
    onFeatures?: ((features: Feature[]) => void);
    place?: boolean | PlaceOptions;
    resultContainer?: string | HTMLElement;
    reverse?: boolean | ReverseOptions;
    searchOnTyping?: boolean;
    showResultIcons?: boolean;
    size?: number;
    sources?:
        | string
        | string[]
        | (() => string[])
        | (() => string);
}

Hierarchy (view full)

Properties

accessToken?: string

Your personal access token, create your own on the Jawg Lab. This is filled automatically when you get the library with our CDN or @jawg/js-loader.

boundary?: BoudaryOptions

Set of options to restrict your forward geocoding to specific regions. It will filter out all locations outside of the configured boundaries.

const boundary = {
countries: 'fra',
circle: { lat: 46.842269, lon: 2.39985, radius: 500 },
rectangle: {
min: { lat: 43.032582, lon: 5.097656 },
max: { lat: 49.006466, lon: 26.762695 },
},
gids: ['openstreetmap:island:relation/966358']
}
clearCross?: boolean

Add a clear cross in the right side of the input.

debounceDelay?: number

Set the number of milliseconds to wait before a search validation. If you press Enter the search will be immediately validated. This option work only when searchOnTyping=true.

with a basic plan you may set this option to 1000 to avoid your restrictions.

350
focus?: FocusOptions

Set of options to prioritize your forward geocoding to specific regions. All locations in these regions will have a better ranking.

const focus = {
countries: 'fra',
point: { lat: 46.842269, lon: 2.39985 },
gids: ['openstreetmap:island:relation/966358']
}
focusPoint?: LatLon | (() => LatLon)

Sort results in part by their proximity to the given coordinate. Coordinates can be static or dynamic with the function.

Point can be static or dynamic through a function. The radius is 50km and cannot be changed.

Replaced by FocusOptions.point

input?: string | HTMLElement

The <input> to transform into a geocoding search bar. This can be either an id (e.g #my-input), class selector (e.g .my-input) or the HTMLElement. With some frameworks/UI libs such as React, you can't use the ref here.

language?: string | (() => string)

Return results in a specific language using BCP47 standard (e.g 'en', 'fr', 'de', ...). By default, we use HTTP Header set by the browser and English when not present.

Language can be static or dynamic through a function.

layers?:
    | string
    | string[]
    | (() => string)
    | (() => string[])

Restrict your search (forward and reverse) to specific layers. You can get only addresses or administrative areas for example.

Layers can be static or dynamic through a function.

minLength?: number

Set the minimum number of characters to trigger a geocoding request. If you press Enter the search will be validated even if the length is not reached. This option work only when searchOnTyping=true.

0.
noResultsMessage?: string | false

Set a custom message when no results are found. This can be disabled.

onClear?: (() => void)

Callback triggered when the input is empty.

onClick?: ((feature: Feature) => void)

Callback triggered when the user click on a result.

Type declaration

    • (feature): void
    • Parameters

      • feature: Feature

        The feature selected by the user

      Returns void

onClose?: (() => void)

Callback triggered when the result list is closed/cleared.

onError?: ((error: any) => void)

Callback triggered when Jawg Places API returns an error.

onFeatures?: ((features: Feature[]) => void)

Callback triggered when Jawg Places API returns without error.

Type declaration

    • (features): void
    • Parameters

      • features: Feature[]

        The list of features returned by Jawg Places API

      Returns void

place?: boolean | PlaceOptions

Option to activate Place Details detection within the input. You can paste one or many GIDs in the input. The separation can be either , (comma) or (space).

const place = {
enabled: true,
geometries: 'source'
}
false
resultContainer?: string | HTMLElement

The custom <div> that will contain the geocoding results. By default the container is created by Jawg Places JS. With some frameworks/UI libs such as React, you can't use the ref here.

reverse?: boolean | ReverseOptions

Option to activate Reverse Geocoding detection within the input. You can paste coordinates in the form {lat}/{lon} in the input. The separation can be either / (slash), , (comma) or (space).

const reverse = {
enabled: true,
radius: 5,
}
false
searchOnTyping?: boolean

Set this to true to activate search on typing, this will also use autocomplete search. Default value is false, you will need to press Enter to validate your search.

showResultIcons?: boolean

Show icon at the left each results.

size?: number

Set the maximum number of results for forward and reverse geocoding.

10
sources?:
    | string
    | string[]
    | (() => string[])
    | (() => string)

Restrict your search (forward and reverse) to specific data sources. You can get only OSM or WOF data for example. This is not recommanded.

Sources can be static or dynamic through a function.