Skip to content

Commit

Permalink
Added GeoJSON types (DefinitelyTyped#11795)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejo90 authored and mhegazy committed Oct 6, 2016
1 parent b29fcd9 commit 5f742ae
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions leaflet/leaflet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Definitions by: Alejandro Sánchez <https://github.com/alejo90>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference path="../geojson/geojson.d.ts" />

declare namespace L {
export interface CRS {
latLngToPoint(latlng: LatLng, zoom: number): Point;
Expand Down Expand Up @@ -523,8 +525,7 @@ declare namespace L {
noClip?: boolean;
}

export interface Polyline extends Path {
toGeoJSON(): Object; // should import GeoJSON typings
interface InternalPolyline extends Path {
getLatLngs(): Array<LatLng>;
setLatLngs(latlngs: Array<LatLng>): this;
setLatLngs(latlngs: Array<LatLngLiteral>): this;
Expand All @@ -540,6 +541,10 @@ declare namespace L {
addLatLng(latlng: Array<LatLngTuple>): this;
}

export interface Polyline extends InternalPolyline {
toGeoJSON(): GeoJSON.LineString | GeoJSON.MultiLineString;
}

export function polyline(latlngs: Array<LatLng>, options?: PolylineOptions): Polyline;

export function polyline(latlngs: Array<LatLngLiteral>, options?: PolylineOptions): Polyline;
Expand All @@ -552,8 +557,8 @@ declare namespace L {

export function polyline(latlngs: Array<Array<LatLngTuple>>, options?: PolylineOptions): Polyline;

export interface Polygon extends Polyline {
toGeoJSON(): Object; // should import GeoJSON typings
export interface Polygon extends InternalPolyline {
toGeoJSON(): GeoJSON.Polygon | GeoJSON.MultiPolygon;
}

export function polygon(latlngs: Array<LatLng>, options?: PolylineOptions): Polygon;
Expand Down Expand Up @@ -582,7 +587,7 @@ declare namespace L {
}

export interface CircleMarker extends Path {
toGeoJSON(): Object; // should import GeoJSON typings
toGeoJSON(): GeoJSON.Point;
setLatLng(latLng: LatLng): this;
setLatLng(latLng: LatLngLiteral): this;
setLatLng(latLng: LatLngTuple): this;
Expand Down Expand Up @@ -650,7 +655,7 @@ declare namespace L {
/**
* Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection).
*/
toGeoJSON(): Object; // should import GeoJSON typings
toGeoJSON(): GeoJSON.GeometryCollection;

/**
* Adds the given layer to the group.
Expand Down Expand Up @@ -747,7 +752,7 @@ declare namespace L {
*/
export function featureGroup(layers?: Array<Layer>): FeatureGroup;

type StyleFunction = (feature: any) => PathOptions;
type StyleFunction = (feature: GeoJSON.Feature<GeoJSON.GeometryObject>) => PathOptions;

export interface GeoJSONOptions extends LayerOptions {
/**
Expand All @@ -763,7 +768,7 @@ declare namespace L {
* }
* ```
*/
pointToLayer?: (geoJsonPoint: Object, latlng: LatLng) => Layer; // should import GeoJSON typings
pointToLayer?: (geoJsonPoint: GeoJSON.Point, latlng: LatLng) => Layer; // should import GeoJSON typings

/**
* A Function defining the Path options for styling GeoJSON lines and polygons,
Expand All @@ -777,7 +782,7 @@ declare namespace L {
* }
* ```
*/
style?: (geoJsonFeature: Object) => PathOptions;
style?: StyleFunction;

/**
* A Function that will be called once for each created Feature, after it
Expand All @@ -789,7 +794,7 @@ declare namespace L {
* function (feature, layer) {}
* ```
*/
onEachFeature?: (feature: Object, layer: Layer) => void;
onEachFeature?: (feature: GeoJSON.Feature<GeoJSON.GeometryObject>, layer: Layer) => void;

/**
* A Function that will be used to decide whether to show a feature or not.
Expand All @@ -802,7 +807,7 @@ declare namespace L {
* }
* ```
*/
filter?: (geoJsonFeature: Object) => boolean;
filter?: (geoJsonFeature: GeoJSON.Feature<GeoJSON.GeometryObject>) => boolean;

/**
* A Function that will be used for converting GeoJSON coordinates to LatLngs.
Expand All @@ -819,7 +824,7 @@ declare namespace L {
/**
* Adds a GeoJSON object to the layer.
*/
addData(data: Object): Layer;
addData(data: GeoJSON.GeoJsonObject): Layer;

/**
* Resets the given vector layer's style to the original GeoJSON style,
Expand All @@ -830,19 +835,21 @@ declare namespace L {
/**
* Changes styles of GeoJSON vector layers with the given style function.
*/
setStyle(style: PathOptions | StyleFunction): this;
setStyle(style: StyleFunction): this;

/**
* Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer
* and/or coordsToLatLng functions if provided as options.
*/
geometryToLayer(featureData: Object, options?: GeoJSONOptions): Layer;
geometryToLayer(featureData: GeoJSON.Feature<GeoJSON.GeometryObject>, options?: GeoJSONOptions): Layer;

/**
* Creates a LatLng object from an array of 2 numbers (longitude, latitude) or
* 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.
*/
coordsToLatLng(coords: [number, number] | [number, number, number]): LatLng;
coordsToLatLng(coords: [number, number]): LatLng;

coordsToLatLng(coords: [number, number, number]): LatLng;

/**
* Creates a multidimensional array of LatLngs from a GeoJSON coordinates array.
Expand All @@ -867,7 +874,9 @@ declare namespace L {
/**
* Normalize GeoJSON geometries/features into GeoJSON features.
*/
asFeature(geojson: Object): Object;
asFeature(geojson: GeoJSON.GeometryObject): GeoJSON.Feature<GeoJSON.GeometryObject>;

asFeature(geojson: GeoJSON.Feature<GeoJSON.GeometryObject>): GeoJSON.Feature<GeoJSON.GeometryObject>;
}

/**
Expand All @@ -877,7 +886,7 @@ declare namespace L {
* map (you can alternatively add it later with addData method) and
* an options object.
*/
export function geoJSON(geojson?: Object, options?: GeoJSONOptions): GeoJSON;
export function geoJSON(geojson?: GeoJSON.GeoJsonObject, options?: GeoJSONOptions): GeoJSON;

type Zoom = boolean | 'center';

Expand Down

0 comments on commit 5f742ae

Please sign in to comment.