mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[esri-leaftlet-geocoder] introduce typings (#18699)
This commit is contained in:
parent
990c3d6829
commit
c23b6de8cf
69
types/esri-leaflet-geocoder/esri-leaflet-geocoder-tests.ts
Normal file
69
types/esri-leaflet-geocoder/esri-leaflet-geocoder-tests.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import * as L from 'esri-leaflet-geocoder';
|
||||
|
||||
const map = L.map('map').setView([45.5165, -122.6764], 12);
|
||||
const tiles = L.esri.basemapLayer("Streets").addTo(map);
|
||||
|
||||
const searchControl = L.esri.Geocoding.geosearch().addTo(map);
|
||||
|
||||
const results = L.layerGroup([]).addTo(map);
|
||||
|
||||
// listen for the results event and add every result to the map
|
||||
searchControl.on("results", data => {
|
||||
results.clearLayers();
|
||||
for (let i = (<any> data).results.length - 1; i >= 0; i--) {
|
||||
results.addLayer(L.marker((<any> data).results[i].latlng));
|
||||
}
|
||||
});
|
||||
|
||||
const arcgisOnline = L.esri.Geocoding.arcgisOnlineProvider();
|
||||
const gisDay = L.esri.Geocoding.featureLayerProvider({
|
||||
url: 'https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/GIS_Day_Final/FeatureServer/0',
|
||||
searchFields: ['Name', 'Organization'], // Search these fields for text matches
|
||||
label: 'GIS Day Events', // Group suggestions under this header
|
||||
formatSuggestion(feature) {
|
||||
return feature.properties.Name + ' - ' + feature.properties.Organization; // format suggestions like this.
|
||||
}
|
||||
});
|
||||
|
||||
L.esri.Geocoding.geosearch({
|
||||
providers: [arcgisOnline, gisDay] // will geocode via ArcGIS Online and search the GIS Day feature service.
|
||||
}).addTo(map);
|
||||
|
||||
L.esri.Geocoding.geocode().text('380 New York St, Redlands, California, 92373').run((err, results, response) => {
|
||||
console.log(results);
|
||||
});
|
||||
|
||||
L.esri.Geocoding.geocode().address('380 New York St').city('Redlands').region('California').postal('92373').run((err, results, response) => {
|
||||
console.log(results);
|
||||
});
|
||||
|
||||
const southWest = L.latLng(37.712, -108.227);
|
||||
const northEast = L.latLng(41.774, -102.125);
|
||||
const bounds = L.latLngBounds(southWest, northEast); // Colorado
|
||||
|
||||
L.esri.Geocoding.geocode().text("Denver").within(bounds).run((err, response) => {
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
const denver = L.latLng(37.712, -108.227);
|
||||
|
||||
L.esri.Geocoding.geocode().text("Highlands Ranch").nearby(denver, 20000).run((err, response) => {
|
||||
const res: any[] = response.results;
|
||||
});
|
||||
|
||||
L.esri.Geocoding.suggest()
|
||||
.text('trea')
|
||||
.nearby([45, -121], 5000)
|
||||
.run((error, response) => {
|
||||
/* response syntax is documented here:
|
||||
https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm#ESRI_SECTION1_FC3884A45AD24E62BD11C9888F1392DB
|
||||
*/
|
||||
});
|
||||
|
||||
L.esri.Geocoding.reverseGeocode()
|
||||
.latlng([48.8583, 2.2945])
|
||||
.run((error, result, response) => {
|
||||
// callback is called with error, result, and raw response.
|
||||
// result.latlng contains the coordinates of the located address
|
||||
// result.address contains information about the match
|
||||
});
|
||||
178
types/esri-leaflet-geocoder/index.d.ts
vendored
Normal file
178
types/esri-leaflet-geocoder/index.d.ts
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
// Type definitions for esri-leaflet-geocoder 2.2
|
||||
// Project: https://github.com/Esri/esri-leaflet-geocoder
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import * as leaflet from 'leaflet';
|
||||
import { esri as esriLeaflet } from 'esri-leaflet';
|
||||
|
||||
export = L;
|
||||
|
||||
declare global {
|
||||
namespace L.esri.Geocoding {
|
||||
type GeosearchConstructor = new (options?: GeosearchObject) => Geosearch;
|
||||
type Geosearch = GeosearchControl & leaflet.Evented;
|
||||
|
||||
interface GeosearchControl extends leaflet.Control {
|
||||
clear(): this;
|
||||
clearSuggestions(): this;
|
||||
disable(): this;
|
||||
enable(): this;
|
||||
}
|
||||
|
||||
const Geosearch: GeosearchConstructor;
|
||||
|
||||
function geosearch(options?: GeosearchObject): Geosearch;
|
||||
|
||||
interface GeosearchObject {
|
||||
position?: leaflet.ControlPosition;
|
||||
zoomToResult?: boolean;
|
||||
useMapBounds?: boolean | number;
|
||||
collapseAfterResult?: boolean;
|
||||
expanded?: boolean;
|
||||
allowMultipleResults?: boolean;
|
||||
providers?: GeosearchProvider[];
|
||||
placeholder?: string;
|
||||
title?: string;
|
||||
searchBounds?: leaflet.LatLngBoundsExpression | null;
|
||||
}
|
||||
|
||||
class GeocodeService extends esriLeaflet.Service {
|
||||
constructor(options?: GeocodeServiceOptions);
|
||||
geocode(): Geocode;
|
||||
suggest(): Suggest;
|
||||
reverse(): ReverseGeocode;
|
||||
}
|
||||
|
||||
function geocodeService(options?: GeocodeServiceOptions): GeocodeService;
|
||||
|
||||
interface GeocodeServiceOptions extends esriLeaflet.ServiceOptions {
|
||||
supportsSuggest?: boolean;
|
||||
}
|
||||
|
||||
class Geocode extends esriLeaflet.Task {
|
||||
constructor(options?: esriLeaflet.TaskOptions | esriLeaflet.Service);
|
||||
text(text: string): this;
|
||||
address(text: string): this;
|
||||
neighborhood(text: string): this;
|
||||
city(text: string): this;
|
||||
subregion(text: string): this;
|
||||
region(text: string): this;
|
||||
postal(text: string): this;
|
||||
country(text: string): this;
|
||||
category(text: string): this;
|
||||
within(bounds: leaflet.LatLngBoundsExpression): this;
|
||||
nearby(latlng: leaflet.LatLngExpression, distance: number): this;
|
||||
run(callback: (error: any | undefined, results: { results: any[] }, response: any) => void, context?: any): this;
|
||||
}
|
||||
|
||||
function geocode(options?: esriLeaflet.TaskOptions | esriLeaflet.Service): Geocode;
|
||||
|
||||
class Suggest extends esriLeaflet.Task {
|
||||
constructor(options?: esriLeaflet.TaskOptions | esriLeaflet.Service);
|
||||
text(text: string): this;
|
||||
category(text: string): this;
|
||||
within(bounds: leaflet.LatLngBoundsExpression): this;
|
||||
nearby(latlng: leaflet.LatLngExpression, distance: number): this;
|
||||
run(callback: (error: any | undefined, results: any, response: any) => void, context?: any): this;
|
||||
}
|
||||
|
||||
function suggest(options?: esriLeaflet.TaskOptions | esriLeaflet.Service): Suggest;
|
||||
|
||||
class ReverseGeocode extends esriLeaflet.Task {
|
||||
constructor(options?: esriLeaflet.TaskOptions | esriLeaflet.Service);
|
||||
latlng(latlng: leaflet.LatLngExpression): this;
|
||||
distance(distance: number): this;
|
||||
language(language: string): this;
|
||||
run(callback: (error: any | undefined, results: { latlng: leaflet.LatLng; address: string; }, response: any) => void, context?: any): this;
|
||||
}
|
||||
|
||||
function reverseGeocode(options?: esriLeaflet.TaskOptions | esriLeaflet.Service): ReverseGeocode;
|
||||
|
||||
interface GeosearchProvider {
|
||||
suggestions(text: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Task;
|
||||
results(text: string, key: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Task;
|
||||
}
|
||||
type GeosearchCallback = (error: any | undefined, results: any) => void;
|
||||
|
||||
interface BaseProviderOptions {
|
||||
label?: string;
|
||||
maxResults?: number;
|
||||
attribution?: string;
|
||||
token?: string | null;
|
||||
}
|
||||
|
||||
class ArcgisOnlineProvider extends GeocodeService implements GeosearchProvider {
|
||||
constructor(options?: ArcgisOnlineProviderOptions);
|
||||
suggestions(text: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): Suggest;
|
||||
results(text: string, key: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): Geocode;
|
||||
}
|
||||
|
||||
function arcgisOnlineProvider(options?: ArcgisOnlineProviderOptions): ArcgisOnlineProvider;
|
||||
|
||||
interface ArcgisOnlineProviderOptions extends BaseProviderOptions {
|
||||
countries?: string | string[];
|
||||
categories?: string | string[];
|
||||
forStorage?: boolean;
|
||||
}
|
||||
|
||||
class GeocodeServiceProvider extends GeocodeService implements GeosearchProvider {
|
||||
constructor(options?: GeocodeServiceProviderOptions);
|
||||
suggestions(text: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): Suggest;
|
||||
results(text: string, key: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): Geocode;
|
||||
}
|
||||
|
||||
function geocodeServiceProvider(options?: GeocodeServiceProviderOptions): GeocodeServiceProvider;
|
||||
|
||||
interface GeocodeServiceProviderOptions extends BaseProviderOptions {
|
||||
url: string;
|
||||
}
|
||||
|
||||
class FeatureLayerProvider extends esriLeaflet.FeatureLayerService implements GeosearchProvider {
|
||||
constructor(options?: FeatureLayerProviderOptions);
|
||||
suggestions(text: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Query;
|
||||
results(text: string, key: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Query;
|
||||
}
|
||||
|
||||
function featureLayerProvider(options?: FeatureLayerProviderOptions): FeatureLayerProvider;
|
||||
|
||||
interface FeatureLayerProviderOptions extends BaseProviderOptions {
|
||||
url: string;
|
||||
searchFields?: string | string[];
|
||||
bufferRadius?: number;
|
||||
formatSuggestion?(featureInformation: any): string;
|
||||
}
|
||||
|
||||
class MapServiceProvider extends esriLeaflet.MapService implements GeosearchProvider {
|
||||
constructor(options?: MapServiceProviderOptions);
|
||||
suggestions(text: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Find;
|
||||
results(text: string, key: string, bounds: leaflet.LatLngBoundsExpression | undefined | null, callback: GeosearchCallback): esriLeaflet.Query | esriLeaflet.Find;
|
||||
}
|
||||
|
||||
function mapServiceProvider(options?: MapServiceProviderOptions): MapServiceProvider;
|
||||
|
||||
interface MapServiceProviderOptions extends BaseProviderOptions {
|
||||
url: string;
|
||||
searchFields: string | string[];
|
||||
layers: number | number[];
|
||||
bufferRadius: number | number[];
|
||||
formatSuggestion(featureInformation: any): string;
|
||||
}
|
||||
|
||||
interface ResultObject {
|
||||
text?: string;
|
||||
bounds?: leaflet.LatLngBoundsExpression;
|
||||
latlng?: leaflet.LatLngExpression;
|
||||
properties?: any;
|
||||
geojson?: leaflet.GeoJSON;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface Results {
|
||||
bounds: leaflet.LatLngBoundsExpression;
|
||||
latlng: leaflet.LatLngExpression;
|
||||
results: ResultObject[];
|
||||
}
|
||||
}
|
||||
}
|
||||
23
types/esri-leaflet-geocoder/tsconfig.json
Normal file
23
types/esri-leaflet-geocoder/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"esri-leaflet-geocoder-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/esri-leaflet-geocoder/tslint.json
Normal file
1
types/esri-leaflet-geocoder/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user