Skip to content

Commit ddeb2fb

Browse files
committed
fix: update maplibre and mapbix types versions and add missing options
1 parent 4d627ec commit ddeb2fb

File tree

4 files changed

+54
-25
lines changed

4 files changed

+54
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ dist
103103
# TernJS port file
104104
.tern-port
105105
docs/
106+
package-lock.json

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jawg/types",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Shared TypeScript definitions for Jawg Maps projects",
55
"types": "./index.d.ts",
66
"typeScriptVersion": "2.3",
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"@types/geojson": "^7946.0.7",
4646
"@types/leaflet": "^1.7.3",
47-
"@types/mapbox-gl": "^2.3.1",
48-
"@types/maplibre-gl": "^1.13.1"
47+
"@types/mapbox-gl": "^1.13.2",
48+
"maplibre-gl": "^1.15.2"
4949
}
5050
}

src/places-js.d.ts

+45-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/// <reference types="mapbox-gl" />
44
/// <reference types="maplibre-gl" />
55

6+
import L = require('leaflet');
7+
68
declare class AbstractPlaces {
79
constructor(options: JawgPlaces.JawgPlacesOptions);
810
/**
@@ -151,7 +153,7 @@ declare namespace JawgPlaces {
151153
accessToken?: string;
152154
/**
153155
* The `<input>` to transform into a geocoding search bar.
154-
* This can be either a id (e.g `#my-input`), class selector (e.g `.my-input`) or the {@link HTMLElement}.
156+
* This can be either a id (e.g `#my-input`), class selector (e.g `.my-input`) or the [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement).
155157
* With some frameworks/UI libs such as React, you can't use the ref here.
156158
*/
157159
input?: string | HTMLElement;
@@ -321,14 +323,20 @@ declare namespace JawgPlaces {
321323
* Options for {@link JawgPlaces.MapLibre} and {@link JawgPlaces.Mapbox}
322324
*/
323325
interface JawgPlacesMaplibreOptions extends JawgPlacesOptions {
326+
/**
327+
* The custom `<div>` that will contain the input and geocoding results when Places JS is used as MapLibre Control.
328+
* By default this is generated by Jawg Places JS.
329+
* With some frameworks/UI libs such as React, you can't use the ref here.
330+
*/
331+
container?: string | HTMLElement;
324332
/**
325333
* Placeholder text to add when the input in generated by the library.
326334
*/
327335
placeholder?: string;
328336
/**
329337
* Class to add to the input when it's generated by the library.
330338
*/
331-
inputClasses?: string;
339+
inputClasses?: string | string[];
332340
/**
333341
* Option to show administrative area when available.
334342
*/
@@ -341,20 +349,30 @@ declare namespace JawgPlaces {
341349
* Option to configure transition on result selection.
342350
*/
343351
transition?: MapGLTransitionOptions;
352+
/**
353+
* Set a custom message when no results are found. This can be disabled.
354+
*/
355+
noResultsMessage?: string | false;
344356
}
345357

346358
/**
347359
* Options for {@link JawgPlaces.Leaflet}
348360
*/
349361
interface JawgPlacesLeafletOptions extends JawgPlacesOptions {
362+
/**
363+
* The custom `<div>` that will contain the input and geocoding results when Places JS is used as Leaflet Control.
364+
* By default this is generated by Jawg Places JS.
365+
* With some frameworks/UI libs such as React, you can't use the ref here.
366+
*/
367+
container?: string | HTMLElement;
350368
/**
351369
* Placeholder text to add when the input in generated by the library.
352370
*/
353371
placeholder?: string;
354372
/**
355373
* Class to add to the input when it's generated by the library.
356374
*/
357-
inputClasses?: string;
375+
inputClasses?: string | string[];
358376
/**
359377
* Option to show administrative area when available.
360378
*/
@@ -367,14 +385,18 @@ declare namespace JawgPlaces {
367385
* Option to configure transition on result selection.
368386
*/
369387
transition?: LeafletTransitionOptions;
388+
/**
389+
* Set a custom message when no results are found. This can be disabled.
390+
*/
391+
noResultsMessage?: string | false;
370392
/**
371393
* Position of the input on the map.
372394
*/
373395
position?: 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
374396
/**
375397
* The Leaflet instance for marker creation
376398
*/
377-
L: any;
399+
L: typeof L;
378400
}
379401

380402
/**
@@ -388,18 +410,20 @@ declare namespace JawgPlaces {
388410
* This class will help you to add or use search bar for geocoding with a MapLibre GL JS map.
389411
*/
390412
class MapLibre extends AbstractPlaces {
391-
constructor(options: JawgPlacesMaplibreOptions);
413+
constructor(options?: JawgPlacesMaplibreOptions);
392414
/**
393-
* This is the function used by MapLibre and Mapbox when you add a {@link mapboxgl.Control}.
415+
* This is the function used by MapLibre and Mapbox when you add a [maplibre.IControl](https://maplibre.org/maplibre-gl-js-docs/api/markers/#icontrol) or [mapboxgl.IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol).
394416
* Adds the control to the given map.
395-
* @param map from MapLibre or Mapbox
417+
* @param map from [MapLibre](https://maplibre.org/maplibre-gl-js-docs/api/map/) or [Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/)
418+
* @returns the generated control container
396419
*/
397-
onAdd(map: mapboxgl.Map): HTMLElement;
420+
onAdd(map: maplibregl.Map | mapboxgl.Map): HTMLElement;
398421
/**
399-
* When Jawg Places is not used as a control within your map, you will need to call this function.
400-
* @param map from MapLibre or Mapbox
422+
* When Jawg Places **is not used** as a control within your map, you will need to call this function.
423+
* @param map from [MapLibre](https://maplibre.org/maplibre-gl-js-docs/api/map/) or [Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/)
424+
* @returns itself
401425
*/
402-
attachMap(map: mapboxgl.Map): MapLibre | Mapbox;
426+
attachMap(map: maplibregl.Map | mapboxgl.Map): MapLibre;
403427
/**
404428
* The default position of the control in the map.
405429
*/
@@ -409,17 +433,20 @@ declare namespace JawgPlaces {
409433
/**
410434
* This class will help you to add or use search bar for geocoding with a Mapbox GL JS map.
411435
*/
412-
class Mapbox extends MapLibre {}
436+
class Mapbox extends MapLibre {
437+
attachMap(map: maplibregl.Map | mapboxgl.Map): Mapbox;
438+
}
413439

414440
/**
415441
* This class will help you to add or use search bar for geocoding with a Leaflet map.
416442
*/
417443
class Leaflet extends AbstractPlaces {
418444
constructor(options: JawgPlacesLeafletOptions);
419445
/**
420-
* This is the function used by Leaflet when you add a {@link L.Control}.
446+
* This is the function used by Leaflet when you add a [L.Control](https://leafletjs.com/reference-1.7.1.html#control).
421447
* Adds the control to the given map.
422-
* @param map from Leaflet
448+
* @param map from [Leaflet](https://leafletjs.com/reference-1.7.1.html#map-example)
449+
* @returns the generated control container
423450
*/
424451
onAdd(map: L.Map): void;
425452
/**
@@ -428,12 +455,13 @@ declare namespace JawgPlaces {
428455
getPosition(): string;
429456
/**
430457
* Adds the control to the given map.
431-
* @param map from leaflet
458+
* @param map from [Leaflet](https://leafletjs.com/reference-1.7.1.html#map-example)
432459
*/
433460
addTo(map: L.Map): void;
434461
/**
435-
* When Jawg Places is not used as a control within your map, you will need to call this function.
436-
* @param map from Leaflet
462+
* When Jawg Places **is not used** as a control within your map, you will need to call this function.
463+
* @param map from [Leaflet](https://leafletjs.com/reference-1.7.1.html#map-example)
464+
* @returns itself
437465
*/
438466
attachMap(map: L.Map): Leaflet;
439467
}

test/places-js.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Map as MapboxGLMap } from 'mapbox-gl';
22
import { Map as MapLibreGLMap } from 'maplibre-gl';
3+
import L = require('leaflet');
34
import { JawgPlaces } from '../';
45

5-
6-
new JawgPlaces.Input({input: '', accessToken: '<Access-Token>'})
7-
new JawgPlaces.MapLibre({input: '', accessToken: '<Access-Token>'})
8-
new JawgPlaces.Mapbox({input: '', accessToken: '<Access-Token>'}).attachMap(new MapboxGLMap())
9-
new JawgPlaces.Leaflet({input: '', accessToken: '<Access-Token>', L: {}})
6+
new JawgPlaces.Input({ input: '', accessToken: '<Access-Token>' });
7+
new JawgPlaces.MapLibre({ input: '', accessToken: '<Access-Token>' }).attachMap(new MapLibreGLMap());
8+
new JawgPlaces.Mapbox({ input: '', accessToken: '<Access-Token>' }).attachMap(new MapboxGLMap());
9+
new JawgPlaces.Leaflet({ input: '', accessToken: '<Access-Token>', L }).attachMap(new L.Map('my-map'));

0 commit comments

Comments
 (0)