From 829d1c9e2292a0fabd2ea3a7ada05292d98bc948 Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Wed, 21 Sep 2016 15:12:44 -0600 Subject: [PATCH 01/10] Add mapbox-gl typings --- mapbox-gl/mapbox-gl-tests.ts | 445 +++++++++++++++++ mapbox-gl/mapbox-gl.d.ts | 934 +++++++++++++++++++++++++++++++++++ 2 files changed, 1379 insertions(+) create mode 100644 mapbox-gl/mapbox-gl-tests.ts create mode 100644 mapbox-gl/mapbox-gl.d.ts diff --git a/mapbox-gl/mapbox-gl-tests.ts b/mapbox-gl/mapbox-gl-tests.ts new file mode 100644 index 0000000000..92f72789da --- /dev/null +++ b/mapbox-gl/mapbox-gl-tests.ts @@ -0,0 +1,445 @@ +// These examples are from Mapbox (https://www.mapbox.com/mapbox-gl-js/examples/) and therefore under the copyright of Mapbox Inc. +/// +/// + +/** + * Set API Access Token + */ +mapboxgl.accessToken = 'foo'; + + +/** + * Display a Map + */ +let map = new mapboxgl.Map({ + container: 'map', // container id + style: 'mapbox://styles/mapbox/streets-v8', //stylesheet location + center: [-74.50, 40], // starting position + zoom: 9 // starting zoom +}); + + +/** + * Create and style marker clusters + */ +map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/dark-v8', + center: [-103.59179687498357, 40.66995747013945], + zoom: 3, +}); + +map.on('load', function(){ + + // Add a new source from our GeoJSON data and set the + // 'cluster' option to true. + map.addSource("earthquakes", { + type: "geojson", + // Point to GeoJSON data. This example visualizes all M1.0+ earthquakes + // from 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program. + data: "/mapbox-gl-js/assets/earthquakes.geojson", + cluster: true, + clusterMaxZoom: 14, // Max zoom to cluster points on + clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50) + }); + + // Use the earthquakes source to create five layers: + // One for non-clustered markers, three for each cluster category, + // and one for cluster labels. + map.addLayer({ + "id": "non-cluster-markers", + "type": "symbol", + "source": "earthquakes", + "layout": { + "icon-image": "marker-15" + } + }); + + // Display the earthquake data in three layers, each filtered to a range of + // count values. Each range gets a different fill color. + var layers = [ + [150, '#f28cb1'], + [20, '#f1f075'], + [0, '#51bbd6'] + ]; + + layers.forEach(function (layer, i) { + map.addLayer({ + "id": "cluster-" + i, + "type": "circle", + "source": "earthquakes", + "paint": { + "circle-color": layer[1], + "circle-radius": 18 + }, + "filter": i == 0 ? + [">=", "point_count", layer[0]] : + ["all", + [">=", "point_count", layer[0]], + ["<", "point_count", layers[i - 1][0]]] + }); + }); + + // Add a layer for the clusters' count labels + map.addLayer({ + "id": "cluster-count", + "type": "symbol", + "source": "earthquakes", + "layout": { + "text-field": "{point_count}", + "text-font": [ + "DIN Offc Pro Medium", + "Arial Unicode MS Bold" + ], + "text-size": 12 + } + }); +}); + +/** + * Add a GeoJSON line + */ +map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/streets-v8', + center: [-122.486052, 37.830348], + zoom: 15 +}); + +map.on('load', function () { + map.addSource("route", { + "type": "geojson", + "data": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [-122.48369693756104, 37.83381888486939], + [-122.48348236083984, 37.83317489144141], + [-122.48339653015138, 37.83270036637107], + [-122.48356819152832, 37.832056363179625], + [-122.48404026031496, 37.83114119107971], + [-122.48404026031496, 37.83049717427869], + [-122.48348236083984, 37.829920943955045], + [-122.48356819152832, 37.82954808664175], + [-122.48507022857666, 37.82944639795659], + [-122.48610019683838, 37.82880236636284], + [-122.48695850372314, 37.82931081282506], + [-122.48700141906738, 37.83080223556934], + [-122.48751640319824, 37.83168351665737], + [-122.48803138732912, 37.832158048267786], + [-122.48888969421387, 37.83297152392784], + [-122.48987674713133, 37.83263257682617], + [-122.49043464660643, 37.832937629287755], + [-122.49125003814696, 37.832429207817725], + [-122.49163627624512, 37.832564787218985], + [-122.49223709106445, 37.83337825839438], + [-122.49378204345702, 37.83368330777276] + ] + } + } + }); + + map.addLayer({ + "id": "route", + "type": "line", + "source": "route", + "layout": { + "line-join": "round", + "line-cap": "round" + }, + "paint": { + "line-color": "#888", + "line-width": 8 + } + }); +}); + +/** + * Display a Popup + */ + +map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/streets-v8', + center: [-96, 37.8], + zoom: 3 +}); + +map.flyTo({center: [0, 0], zoom: 9}); + +map.flyTo({ + center: [0, 0], + zoom: 9, + speed: 0.2, + curve: 1, + easing: function(t: any) { + return t; + } +}); + +/** + * GeoJSONSource + */ +var geoJSONSourceObj = new mapboxgl.GeoJSONSource({ + data: { + "type": "FeatureCollection", + "features": [{ + "type": "Feature", + "properties": null, + "geometry": { + "type": "Point", + "coordinates": [ + -76.53063297271729, + 39.18174077994108 + ] + } + }] + } +}); +map.addSource('some id', geoJSONSourceObj); // add +map.removeSource('some id'); // remove + +/** + * ImageSource + */ +var imageSourceObj = new mapboxgl.ImageSource({ + url: 'https://www.mapbox.com/images/foo.png', + coordinates: [ + [-76.54335737228394, 39.18579907229748], + [-76.52803659439087, 39.1838364847587], + [-76.5295386314392, 39.17683392507606], + [-76.54520273208618, 39.17876344106642] + ] +}); +map.addSource('some id', imageSourceObj); // add +map.removeSource('some id'); // remove + +/** + * Video Source + */ +var videoSourceObj = new mapboxgl.VideoSource({ + urls: [ + 'https://www.mapbox.com/videos/baltimore-smoke.mp4', + 'https://www.mapbox.com/videos/baltimore-smoke.webm' + ], + coordinates: [ + [-76.54335737228394, 39.18579907229748], + [-76.52803659439087, 39.1838364847587], + [-76.5295386314392, 39.17683392507606], + [-76.54520273208618, 39.17876344106642] + ] +}); +map.addSource('some id', videoSourceObj); // add +map.removeSource('some id'); // remove + +/** + * Tooltip + */ +var tooltip = new mapboxgl.Popup({closeOnClick: false}) + .setLngLat([-96, 37.8]) + .setHTML('

Hello World!

') + .addTo(map); + +/** + * Add an image + */ +var mapStyle = { + "version": 8, + "name": "Dark", + "sources": { + "mapbox": { + "type": "vector", + "url": "mapbox://mapbox.mapbox-streets-v6" + }, + "overlay": { + "type": "image", + "url": "/mapbox-gl-js/assets/radar.gif", + "coordinates": [ + [-80.425, 46.437], + [-71.516, 46.437], + [-71.516, 37.936], + [-80.425, 37.936] + ] + } + }, + "sprite": "mapbox://sprites/mapbox/dark-v8", + "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", + "layers": [ + { + "id": "background", + "type": "background", + "paint": {"background-color": "#111"} + }, + { + "id": "water", + "source": "mapbox", + "source-layer": "water", + "type": "fill", + "paint": {"fill-color": "#2c2c2c"} + }, + { + "id": "boundaries", + "source": "mapbox", + "source-layer": "admin", + "type": "line", + "paint": {"line-color": "#797979", "line-dasharray": [2, 2, 6, 2]}, + "filter": ["all", ["==", "maritime", 0]], + }, + { + "id": "overlay", + "source": "overlay", + "type": "raster", + "paint": {"raster-opacity": 0.85} + }, + { + "id": "cities", + "source": "mapbox", + "source-layer": "place_label", + "type": "symbol", + "layout": { + "text-field": "{name_en}", + "text-font": ["DIN Offc Pro Bold", "Arial Unicode MS Bold"], + "text-size": {"stops": [[4, 9], [6, 12]]} + }, + "paint": { + "text-color": "#969696", + "text-halo-width": 2, + "text-halo-color": "rgba(0, 0, 0, 0.85)" + } + }, + { + "id": "states", + "source": "mapbox", + "source-layer": "state_label", + "type": "symbol", + "layout": { + "text-transform": "uppercase", + "text-field": "{name_en}", + "text-font": ["DIN Offc Pro Bold", "Arial Unicode MS Bold"], + "text-letter-spacing": 0.15, + "text-max-width": 7, + "text-size": {"stops": [[4, 10], [6, 14]]} + }, + "filter": [">=", "area", 80000], + "paint": { + "text-color": "#969696", + "text-halo-width": 2, + "text-halo-color": "rgba(0, 0, 0, 0.85)" + } + } + ] +}; + +map = new mapboxgl.Map({ + container: 'map', + maxZoom: 5.99, + minZoom: 4, + zoom: 5, + center: [-75.789, 41.874], + style: mapStyle, + hash: false +}); + +/** + * Add video + */ +var videoStyle = { + "version": 8, + "sources": { + "satellite": { + "type": "raster", + "url": "mapbox://mapbox.satellite", + "tileSize": 256 + }, + "video": { + "type": "video", + "urls": ["https://www.mapbox.com/drone/video/drone.mp4", "https://www.mapbox.com/drone/video/drone.webm"], + "coordinates": [ + [-122.51596391201019, 37.56238816766053], + [-122.51467645168304, 37.56410183312965], + [-122.51309394836426, 37.563391708549425], + [-122.51423120498657, 37.56161849366671] + ] + } + }, + "layers": [{ + "id": "background", + "type": "background", + "paint": { + "background-color": "rgb(4,7,14)" + } + }, { + "id": "satellite", + "type": "raster", + "source": "satellite" + }, { + "id": "video", + "type": "raster", + "source": "video" + }] +}; + +map = new mapboxgl.Map({ + container: 'map', + minZoom: 14, + zoom: 17, + center: [-122.514426, 37.562984], + bearing: -96, + style: videoStyle, + hash: false +}); + +/** + * Add GeoJSON Markers + */ +map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/streets-v8', + center: [-96, 37.8], + zoom: 3 +}); + +map.on('load', function () { + map.addSource("markers", { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [{ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [-77.03238901390978, 38.913188059745586] + }, + "properties": { + "title": "Mapbox DC", + "marker-symbol": "monument" + } + }, { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [-122.414, 37.776] + }, + "properties": { + "title": "Mapbox SF", + "marker-symbol": "harbor" + } + }] + } + }); + + map.addLayer({ + "id": "markers", + "type": "symbol", + "source": "markers", + "layout": { + "icon-image": "{marker-symbol}-15", + "text-field": "{title}", + "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], + "text-offset": [0, 0.6], + "text-anchor": "top" + } + }); +}); \ No newline at end of file diff --git a/mapbox-gl/mapbox-gl.d.ts b/mapbox-gl/mapbox-gl.d.ts new file mode 100644 index 0000000000..6ea2ec5c71 --- /dev/null +++ b/mapbox-gl/mapbox-gl.d.ts @@ -0,0 +1,934 @@ +// Type definitions for Mapbox GL JS v0.24.0 +// Project: https://github.com/mapbox/mapbox-gl-js +// Definitions by: Dominik Bruderer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace mapboxgl { + let accessToken: string; + let version: string; + export function supported(options?: {failIfMajorPerformanceCaveat?: boolean}): boolean; + + /** + * Map + */ + export class Map extends Evented { + constructor(options?: MapboxOptions); + + addControl(control: Control): this; + + addClass(klass: string, options?: mapboxgl.StyleOptions): this; + + removeClass(klass: string, options?: mapboxgl.StyleOptions): this; + + setClasses(klasses: string[], options?: mapboxgl.StyleOptions): this; + + hasClass(klass: string): boolean; + + getClasses(): string[]; + + resize(): this; + + getBounds(): mapboxgl.LngLatBounds; + + setMaxBounds(lnglatbounds?: mapboxgl.LngLatBounds | number[][]): this; + + setMinZoom(minZoom?: number): this; + + setMaxZoom(maxZoom?: number): this; + + project(lnglat: mapboxgl.LngLat | number[]): mapboxgl.Point; + + unproject(point: mapboxgl.Point | number[]): mapboxgl.LngLat; + + queryRenderedFeatures(pointOrBox?: mapboxgl.Point|number[]|mapboxgl.Point[]|number[][], parameters?: {layers?: string[], filter?: any[]}): GeoJSON.Feature[]; + + querySourceFeatures(sourceID: string, parameters: {sourceLayer?: string, filter?: any[]}): GeoJSON.Feature[]; + + setStyle(style: mapboxgl.Style | string): this; + + getStyle(): mapboxgl.Style; + + addSource(id: string, source: VectorSource | RasterSource | GeoJSONSource | ImageSource | VideoSource | GeoJSONSourceRaw): this; + + removeSource(id: string): this; + + getSource(id: string): VectorSource | RasterSource | GeoJSONSource | ImageSource | VideoSource; + + addLayer(layer: mapboxgl.Layer, before?: string): this; + + removeLayer(id: string): this; + + getLayer(id: string): mapboxgl.Layer; + + setFilter(layer: string, filter: any[]): this; + + setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number): this; + + getFilter(layer: string): any[]; + + setPaintProperty(layer: string, name: string, value: any, klass?: string): this; + + getPaintProperty(layer: string, name: string, klass?: string): any; + + setLayoutProperty(layer: string, name: string, value: any): this; + + getLayoutProperty(layer: string, name: string, klass?: string): any; + + getContainer(): HTMLElement; + + getCanvasContainer(): HTMLElement; + + getCanvas(): HTMLCanvasElement; + + loaded(): boolean; + + remove(): void; + + onError(): void; + + showTileBoundaries: boolean; + + showCollisionBoxes: boolean; + + repaint: boolean; + + getCenter(): mapboxgl.LngLat; + + setCenter(center: LngLat|number[], eventData?: mapboxgl.EventData): this; + + panBy(offset: number[], options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + panTo(lnglat: mapboxgl.LngLat, options?: mapboxgl.AnimationOptions, eventdata?: mapboxgl.EventData): this; + + getZoom(): number; + + setZoom(zoom: number, eventData?: mapboxgl.EventData): this; + + zoomTo(zoom: number, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + zoomIn(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + zoomOut(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + getBearing(): number; + + setBearing(bearing: number, eventData?: mapboxgl.EventData): this; + + rotateTo(bearing: number, options?: mapboxgl.AnimationOptions, eventData?: EventData): this; + + resetNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + snapToNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + getPitch(): number; + + setPitch(pitch: number, eventData?: EventData): this; + + fitBounds(bounds: mapboxgl.LngLatBounds | number[][], options?: { linear?: boolean, easing?: Function, padding?: number, offset?: Point|number[],maxZoom?: number }): this; + + jumpTo(options: mapboxgl.CameraOptions, eventData?: mapboxgl.EventData): this; + + easeTo(options: mapboxgl.CameraOptions | mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; + + flyTo(options: mapboxgl.FlyToOptions, eventData?: mapboxgl.EventData): this; + + stop(): this; + + scrollZoom: ScrollZoomHandler; + + boxZoom: BoxZoomHandler; + + dragRotate: DragRotateHandler; + + dragPan: DragPanHandler; + + keyboard: KeyboardHandler; + + doublClickZoom: DoubleClickZoomHandler; + + touchZoomRotate: TouchZoomRotateHandler; + } + + export interface MapboxOptions { + /** If true, an attribution control will be added to the map. */ + attributionControl?: boolean; + + bearing?: number; + + /** Snap to north threshold in degrees. */ + bearingSnap?: number; + + /** If true, enable the "box zoom" interaction (see BoxZoomHandler) */ + boxZoom?: boolean; + + /** initial map center */ + center?: mapboxgl.LngLat | number[]; + + /** Style class names with which to initialize the map */ + classes?: string[]; + + /** ID of the container element */ + container?: string | Element; + + /** If true, enable the "drag to pan" interaction (see DragPanHandler). */ + dragPan?: boolean; + + /** If true, enable the "drag to rotate" interaction (see DragRotateHandler). */ + dragRotate?: boolean; + + /** If true, enable the "double click to zoom" interaction (see DoubleClickZoomHandler). */ + doubleClickZoom?: boolean; + + /** If true, the map will track and update the page URL according to map position */ + hash?: boolean; + + /** If true, map creation will fail if the implementation determines that the performance of the created WebGL context would be dramatically lower than expected. */ + failIfMayorPerformanceCaveat?: boolean; + + /** If false, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input */ + interactive?: boolean; + + /** If true, enable keyboard shortcuts (see KeyboardHandler). */ + keyboard?: boolean; + + /** If set, the map is constrained to the given bounds. */ + maxBounds?: mapboxgl.LngLatBounds | number[][]; + + /** Maximum zoom of the map */ + maxZoom?: number; + + /** Minimum zoom of the map */ + minZoom?: number; + + /** If true, The maps canvas can be exported to a PNG using map.getCanvas().toDataURL();. This is false by default as a performance optimization. */ + preserveDrawingBuffer?: boolean; + + pitch?: number; + + /** If true, enable the "scroll to zoom" interaction */ + scrollZoom?: boolean; + + /** stylesheet location */ + style?: mapboxgl.Style | string; + + /** If true, the map will automatically resize when the browser window resizes */ + trackResize?: boolean; + + /** If true, enable the "pinch to rotate and zoom" interaction (see TouchZoomRotateHandler). */ + touchZoomRotate?: boolean; + + /** Initial zoom level */ + zoom?: number; + } + + /** + * BoxZoomHandler + */ + export class BoxZoomHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + isActive(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * ScrollZoomHandler + */ + export class ScrollZoomHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * DragPenHandler + */ + export class DragPanHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + isActive(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * DragRotateHandler + */ + export class DragRotateHandler { + constructor(map: mapboxgl.Map, options?: {bearingSnap?: number, pitchWithRotate?: boolean}); + + isEnabled(): boolean; + + isActive(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * KeyboardHandler + */ + export class KeyboardHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * DoubleClickZoomHandler + */ + export class DoubleClickZoomHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + enable(): void; + + disable(): void; + } + + /** + * TouchZoomRotateHandler + */ + export class TouchZoomRotateHandler { + constructor(map: mapboxgl.Map); + + isEnabled(): boolean; + + enable(): void; + + disable(): void; + + disableRotation(): void; + + enableRotation(): void; + } + + /** + * Control + */ + export class Control extends Evented { + addTo(map: mapboxgl.Map): this; + + remove(): this; + } + + /** + * ControlOptions + */ + export interface ControlOptions { + position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'; + } + + /** + * Navigation + */ + export class Navigation extends Control { + constructor(options?: mapboxgl.ControlOptions); + } + + /** + * Geolocate + */ + export class Geolocate extends Control { + constructor(options?: mapboxgl.ControlOptions); + } + + /** + * Attribution + */ + export class Attribution extends Control { + constructor(options?: mapboxgl.ControlOptions); + } + + /** + * Scale + */ + export class Scale extends Control { + constructor(options?: {position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left', maxWidth?: number, unit?: string}) + } + + /** + * Popup + */ + export class Popup extends Evented { + constructor(options?: mapboxgl.PopupOptions); + + addTo(map: mapboxgl.Map): this; + + isOpen(): boolean; + + remove(): this; + + getLngLat(): mapboxgl.LngLat; + + setLngLat(lnglat: mapboxgl.LngLat | number[]): this; + + setText(text: string): this; + + setHTML(html: string): this; + + setDOMContent(htmlNode: Node): this; + } + + export interface PopupOptions { + closeButton?: boolean; + + closeOnClick?: boolean; + + anchor?: 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; + + offset?: number | Point | number[] | { [key:string]: Point | number[];}; + } + + export interface Style { + bearing?: number; + center?: number[]; + glyphs?: string; + layers?: Layer[]; + metadata?: any; + name?: string; + pitch?: number; + sources?: any; + sprite?: string; + transition?: Transition; + version: number; + zoom?: number; + } + + export interface Transition { + delay?: number; + duration?: number; + } + + export interface Source { + type: "vector" | "raster" | "geojson" | "image" | "video"; + } + + /** + * GeoJSONSource + */ + + export interface GeoJSONSourceRaw extends Source, GeoJSONSourceOptions { + type: "geojson"; + } + + export class GeoJSONSource implements GeoJSONSourceRaw { + type: "geojson"; + + constructor(options?: mapboxgl.GeoJSONSourceOptions); + + setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; + } + + export interface GeoJSONSourceOptions { + data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string; + + maxzoom?: number; + + buffer?: number; + + tolerance?: number; + + cluster?: number | boolean; + + clusterRadius?: number; + + clusterMaxZoom?: number; + } + + /** + * VideoSource + */ + export class VideoSource implements Source, VideoSourceOptions { + type: "video"; + + constructor(options?: mapboxgl.VideoSourceOptions); + + getVideo(): HTMLVideoElement; + + setCoordinates(coordinates: number[][]): this; + } + + export interface VideoSourceOptions { + urls?: string[]; + + coordinates?: number[][]; + } + + /** + * ImageSource + */ + export class ImageSource implements Source, ImageSourceOptions { + type: "image"; + + constructor(options?: mapboxgl.ImageSourceOptions); + + setCoordinates(coordinates: number[][]): this; + } + + export interface ImageSourceOptions { + url?: string; + + coordinates?: number[][]; + } + + interface VectorSource extends Source { + type: "vector"; + url?: string; + tiles?: string[]; + minzoom?: number; + maxzoom?: number; + } + + interface RasterSource extends Source { + type: "raster"; + url: string; + tiles?: string[]; + minzoom?: number; + maxzoom?: number; + tileSize?: number; + } + + /** + * LngLat + */ + export class LngLat { + lng: number; + lat: number; + + constructor(lng: number, lat: number); + + /** Return a new LngLat object whose longitude is wrapped to the range (-180, 180). */ + wrap(): mapboxgl.LngLat; + + /** Return a LngLat as an array */ + toArray(): number[]; + + /** Return a LngLat as a string */ + toString(): string; + + static convert(input: number[]|mapboxgl.LngLat): mapboxgl.LngLat; + } + + /** + * LngLatBounds + */ + export class LngLatBounds { + sw: LngLat | number[]; + ne: LngLat | number[]; + constructor(sw?: LngLat, ne?: LngLat); + + /** Extend the bounds to include a given LngLat or LngLatBounds. */ + extend(obj: mapboxgl.LngLat | mapboxgl.LngLatBounds): this; + + /** Get the point equidistant from this box's corners */ + getCenter(): mapboxgl.LngLat; + + /** Get southwest corner */ + getSouthWest(): mapboxgl.LngLat; + + /** Get northeast corner */ + getNorthEast(): mapboxgl.LngLat; + + /** Get northwest corner */ + getNorthWest(): mapboxgl.LngLat; + + /** Get southeast corner */ + getSouthEast(): mapboxgl.LngLat; + + /** Get west edge longitude */ + getWest(): number; + + /** Get south edge latitude */ + getSouth(): number; + + /** Get east edge longitude */ + getEast(): number; + + /** Get north edge latitude */ + getNorth(): number; + + /** Returns a LngLatBounds as an array */ + toArray(): number[][]; + + /** Return a LngLatBounds as a string */ + toString(): string; + + /** Convert an array to a LngLatBounds object, or return an existing LngLatBounds object unchanged. */ + static convert(input: mapboxgl.LngLatBounds | number[] | number[][]): mapboxgl.LngLatBounds; + } + + /** + * Point + */ + // Todo: Pull out class to seperate definition for Module "point-geometry" + export class Point { + constructor(options?: Object); + + clone(): Point; + + add(p: number): Point; + + sub(p: number): Point; + + mult(k: number): Point; + + div(k: number): Point; + + rotate(a: number): Point; + + matMult(m: number): Point; + + unit(): Point; + + perp(): Point; + + round(): Point; + + mag(): number; + + equals(): boolean; + + dist(): number; + + distSqr(): number; + + angle(): number; + + angleTo(): number; + + angleWidth(): number; + + angleWidthSep(): number; + } + + export class Marker { + constructor(element?: HTMLElement, options?: { offset?: Point | number[] }); + + addTo(map: Map): this; + + remove(): this; + + getLngLat(): LngLat; + + setLngLat(lngLat: LngLat | number[]): this; + + setPopup(popup?: Popup): this; + + getPopup(): Popup; + + togglePopup(): this; + } + + /** + * Evented + */ + export class Evented { + on(type: string, listener: Function): this; + + off(type?: string | any, listener?: Function): this; + + once(type: string, listener: Function): this; + + fire(type: string, data?: mapboxgl.EventData | Object): this; + + listens(type: string): boolean; + } + + /** + * StyleOptions + */ + export interface StyleOptions { + transition?: boolean; + } + + /** + * EventData + */ + export class EventData { + type: string; + target: Map; + originalEvent: Event; + point: mapboxgl.Point; + lngLat: mapboxgl.LngLat; + } + + export class MapMouseEvent { + type: string; + target: Map; + originalEvent: MouseEvent; + point: mapboxgl.Point; + lngLat: mapboxgl.LngLat; + } + + export class MapTouchEvent { + type: string; + target: Map; + originalEvent: TouchEvent; + point: mapboxgl.Point; + lngLat: mapboxgl.LngLat; + points: Array; + lngLats: Array; + } + + export class MapBoxZoomEvent { + originalEvent: MouseEvent; + boxZoomBounds: LngLatBounds; + } + + /** + * AnimationOptions + */ + export interface AnimationOptions { + /** Number in milliseconds */ + duration?: number; + easing?: Function; + /** point, origin of movement relative to map center */ + offset?: Point | number[]; + /** When set to false, no animation happens */ + animate?: boolean; + } + + /** + * CameraOptions + */ + export interface CameraOptions { + /** Map center */ + center?: mapboxgl.LngLat | number[]; + /** Map zoom level */ + zoom?: number; + /** Map rotation bearing in degrees counter-clockwise from north */ + bearing?: number; + /** Map angle in degrees at which the camera is looking at the ground */ + pitch?: number; + /** If zooming, the zoom center (defaults to map center) */ + around?: mapboxgl.LngLat | number[]; + } + + /** + * FlyToOptions + */ + export interface FlyToOptions extends AnimationOptions, CameraOptions { + curve?: number; + minZoom?: number; + speed?: number; + screenSpeed?: number; + easing?: Function; + } + + /** + * MapEvent + */ + export interface MapEvent { + webglcontextlost?: {originalEvent: WebGLContextEvent}; + webglcontextrestored?: {originalEvent: WebGLContextEvent}; + render?: void; + contextmenu?: {data: mapboxgl.MapMouseEvent}; + dblclick?: {data: mapboxgl.MapMouseEvent}; + click?: {data: mapboxgl.MapMouseEvent}; + touchcancel?: {data: mapboxgl.MapTouchEvent}; + touchmove?: {data: mapboxgl.MapTouchEvent}; + touchend?: {data: mapboxgl.MapTouchEvent}; + touchstart?: {data: mapboxgl.MapTouchEvent}; + mousemove?: {data: mapboxgl.MapMouseEvent}; + mouseup?: {data: mapboxgl.MapMouseEvent}; + mousedown?: {data: mapboxgl.MapMouseEvent}; + moveend?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + move?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + movestart?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + mouseout?:{data: mapboxgl.MapMouseEvent}; + load?: void; + zoomend?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + zoom?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + zoomstart?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + boxzoomcancel?: {data: mapboxgl.MapBoxZoomEvent}; + boxzoomstart?: {data: mapboxgl.MapBoxZoomEvent}; + boxzoomend?: {data: mapboxgl.MapBoxZoomEvent}; + rotate?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + rotatestart?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + rotateend?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + drag?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + dragend?: {data: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent}; + pitch?: {data: mapboxgl.EventData}; + } + + export interface Layer { + id: string; + type?: "fill" | "line" | "symbol" | "circle" | "raster" | "background" | string; //TODO: Ideally we wouldn't accept string here, just these specific strings + + metadata?: any; + ref?: string; + + source?: string; + + "source-layer"?: string; + + minzoom?: number; + maxzoom?: number; + + interactive?: boolean; + + filter?: Array; + layout?: BackgroundLayout | FillLayout | LineLayout | SymbolLayout | RasterLayout | CircleLayout; + paint?: BackgroundPaint | FillPaint | LinePaint | SymbolPaint | RasterPaint | CirclePaint; + } + + export interface StyleFunction { + stops: Array>; + property?: string; + base?: number; + type?: "continuous" | "interval" | "categorical"; + } + + export interface BackgroundLayout { + visibility?: "visible" | "none"; + } + export interface BackgroundPaint { + "background-color"?: string; + "background-pattern"?: string; + "background-opacity"?: number; + } + + export interface FillLayout { + visibility?: "visible" | "none"; + } + export interface FillPaint { + "fill-antialias"?: boolean; + "fill-opacity"?: number | StyleFunction; + "fill-color"?: string | StyleFunction; + "fill-outline-color": string | StyleFunction; + "fill-translate"?: Array; + "fill-translate-anchor"?: "map" | "viewport"; + "fill-pattern"?: "string"; + } + + export interface LineLayout { + visibility?: "visible" | "none"; + + "line-cap"?: "butt" | "round" | "square"; + "line-join"?: "bevel" | "round" | "miter"; + "line-miter-limit"?: number; + "line-round-limit"?: number; + } + export interface LinePaint { + "line-opacity"?: number; + "line-color"?: string| StyleFunction; + "line-translate"?: Array; + "line-translate-anchor"?: "map" | "viewport"; + "line-width"?: number; + "line-gap-width"?: number; + "line-offset"?: number; + "line-blur"?: number; + "line-dasharray"?: Array; + "line-dasharray-transition"?: Transition; + "line-pattern"?: string; + } + + export interface SymbolLayout { + visibility?: "visible" | "none"; + + "symbol-placement"?: "point" | "line"; + "symbol-spacing"?: number; + "symbol-avoid-edges"?: boolean; + "icon-allow-overlap"?: boolean; + "icon-ignore-placement"?: boolean; + "icon-optional"?: boolean; + "icon-rotation-alignment"?: "map" | "viewport" | "auto"; + "icon-size"?: number; + "icon-text-fit"?: "none" | "both" | "width" | "height"; + "icon-text-fit-padding"?: Array; + "icon-image"?: string; + "icon-rotate"?: number | StyleFunction; + "icon-padding"?: number; + "icon-keep-upright"?: boolean; + "icon-offset"?: Array; + "text-pitch-alignment"?: "map" | "viewport" | "auto"; + "text-rotation-alignment"?: "map" | "viewport" | "auto"; + "text-field"?: string; + "text-font"?: string | string[]; + "text-size"?: number; + "text-max-width"?: number; + "text-line-height"?: number; + "text-letter-spacing"?: number; + "text-justify"?: "left" | "center" | "right"; + "text-anchor"?: "center" | "left" | "right" | "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right"; + "text-max-angle"?: number; + "text-rotate"?: number; + "text-padding"?: number; + "text-keep-upright"?: boolean; + "text-transform"?: "none" | "uppercase" | "lowercase"; + "text-offset"?: Array; + "text-allow-overlap"?: boolean; + "text-ignore-placement"?: boolean; + "text-optional"?: boolean; + + } + export interface SymbolPaint { + "icon-opacity"?: number; + "icon-color"?: string; + "icon-halo-color"?: string; + "icon-halo-width"?: number; + "icon-halo-blur"?: number; + "icon-translate"?: Array; + "icon-translate-anchor"?: "map" | "viewport"; + "text-opacity"?: number; + "text-color"?: "string"; + "text-halo-color"?: "string"; + "text-halo-width"?: number; + "text-halo-blur"?: number; + "text-translate"?: Array; + "text-translate-anchor"?: "map" | "viewport"; + } + + export interface RasterLayout { + visibility?: "visible" | "none"; + } + + export interface RasterPaint { + "raster-opacity"?: number; + "raster-hue-rotate"?: number; + "raster-brightness-min"?: number; + "raster-brightness-max"?: number; + "raster-saturation"?: number; + "raster-contrast"?: number; + "raster-fade-duration"?: number; + } + + export interface CircleLayout { + visibility?: "visible" | "none"; + } + + export interface CirclePaint { + "circle-radius"?: number | StyleFunction; + "circle-radius-transition"?: Transition; + "circle-color"?: number | StyleFunction; + "circle-blur"?: number | StyleFunction; + "circle-opacity"?: number | StyleFunction; + "circle-translate"?: Array; + "circle-translate-anchor"?: "map" | "viewport"; + "circle-pitch-scale"?: "map" | "viewport"; + } +} + +declare module 'mapbox-gl' { + export = mapboxgl; +} From 1c02488e759f747cf31d268ca55db83b1be1c787 Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Wed, 21 Sep 2016 15:18:46 -0600 Subject: [PATCH 02/10] Fixes to get the tests working --- mapbox-gl/mapbox-gl-tests.ts | 2 +- mapbox-gl/mapbox-gl.d.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mapbox-gl/mapbox-gl-tests.ts b/mapbox-gl/mapbox-gl-tests.ts index 92f72789da..90cb9ff580 100644 --- a/mapbox-gl/mapbox-gl-tests.ts +++ b/mapbox-gl/mapbox-gl-tests.ts @@ -1,6 +1,6 @@ // These examples are from Mapbox (https://www.mapbox.com/mapbox-gl-js/examples/) and therefore under the copyright of Mapbox Inc. /// -/// +/// /** * Set API Access Token diff --git a/mapbox-gl/mapbox-gl.d.ts b/mapbox-gl/mapbox-gl.d.ts index 6ea2ec5c71..50f9fca505 100644 --- a/mapbox-gl/mapbox-gl.d.ts +++ b/mapbox-gl/mapbox-gl.d.ts @@ -3,6 +3,8 @@ // Definitions by: Dominik Bruderer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + declare namespace mapboxgl { let accessToken: string; let version: string; From 137e01e335610c54507009de39399e9d8643483f Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Thu, 22 Sep 2016 11:47:14 -0600 Subject: [PATCH 03/10] Switch Array<> to [] --- mapbox-gl/mapbox-gl.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mapbox-gl/mapbox-gl.d.ts b/mapbox-gl/mapbox-gl.d.ts index 50f9fca505..2ee8d30949 100644 --- a/mapbox-gl/mapbox-gl.d.ts +++ b/mapbox-gl/mapbox-gl.d.ts @@ -688,8 +688,8 @@ declare namespace mapboxgl { originalEvent: TouchEvent; point: mapboxgl.Point; lngLat: mapboxgl.LngLat; - points: Array; - lngLats: Array; + points: Point[]; + lngLats: LngLat[]; } export class MapBoxZoomEvent { @@ -789,13 +789,13 @@ declare namespace mapboxgl { interactive?: boolean; - filter?: Array; + filter?: any[]; layout?: BackgroundLayout | FillLayout | LineLayout | SymbolLayout | RasterLayout | CircleLayout; paint?: BackgroundPaint | FillPaint | LinePaint | SymbolPaint | RasterPaint | CirclePaint; } export interface StyleFunction { - stops: Array>; + stops: any[][]; property?: string; base?: number; type?: "continuous" | "interval" | "categorical"; @@ -818,7 +818,7 @@ declare namespace mapboxgl { "fill-opacity"?: number | StyleFunction; "fill-color"?: string | StyleFunction; "fill-outline-color": string | StyleFunction; - "fill-translate"?: Array; + "fill-translate"?: number[]; "fill-translate-anchor"?: "map" | "viewport"; "fill-pattern"?: "string"; } @@ -834,13 +834,13 @@ declare namespace mapboxgl { export interface LinePaint { "line-opacity"?: number; "line-color"?: string| StyleFunction; - "line-translate"?: Array; + "line-translate"?: number[]; "line-translate-anchor"?: "map" | "viewport"; "line-width"?: number; "line-gap-width"?: number; "line-offset"?: number; "line-blur"?: number; - "line-dasharray"?: Array; + "line-dasharray"?: number[]; "line-dasharray-transition"?: Transition; "line-pattern"?: string; } @@ -857,12 +857,12 @@ declare namespace mapboxgl { "icon-rotation-alignment"?: "map" | "viewport" | "auto"; "icon-size"?: number; "icon-text-fit"?: "none" | "both" | "width" | "height"; - "icon-text-fit-padding"?: Array; + "icon-text-fit-padding"?: number[]; "icon-image"?: string; "icon-rotate"?: number | StyleFunction; "icon-padding"?: number; "icon-keep-upright"?: boolean; - "icon-offset"?: Array; + "icon-offset"?: number[]; "text-pitch-alignment"?: "map" | "viewport" | "auto"; "text-rotation-alignment"?: "map" | "viewport" | "auto"; "text-field"?: string; @@ -878,7 +878,7 @@ declare namespace mapboxgl { "text-padding"?: number; "text-keep-upright"?: boolean; "text-transform"?: "none" | "uppercase" | "lowercase"; - "text-offset"?: Array; + "text-offset"?: number[]; "text-allow-overlap"?: boolean; "text-ignore-placement"?: boolean; "text-optional"?: boolean; @@ -890,14 +890,14 @@ declare namespace mapboxgl { "icon-halo-color"?: string; "icon-halo-width"?: number; "icon-halo-blur"?: number; - "icon-translate"?: Array; + "icon-translate"?: number[]; "icon-translate-anchor"?: "map" | "viewport"; "text-opacity"?: number; "text-color"?: "string"; "text-halo-color"?: "string"; "text-halo-width"?: number; "text-halo-blur"?: number; - "text-translate"?: Array; + "text-translate"?: number[]; "text-translate-anchor"?: "map" | "viewport"; } @@ -925,7 +925,7 @@ declare namespace mapboxgl { "circle-color"?: number | StyleFunction; "circle-blur"?: number | StyleFunction; "circle-opacity"?: number | StyleFunction; - "circle-translate"?: Array; + "circle-translate"?: number[]; "circle-translate-anchor"?: "map" | "viewport"; "circle-pitch-scale"?: "map" | "viewport"; } From a05e0e04092c9ee51f69e9b4b5e6a8c86d7dc109 Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Thu, 22 Sep 2016 12:19:42 -0600 Subject: [PATCH 04/10] modify tests --- mapbox-gl/mapbox-gl-tests.ts | 166 ++++++++++------------------------- 1 file changed, 47 insertions(+), 119 deletions(-) diff --git a/mapbox-gl/mapbox-gl-tests.ts b/mapbox-gl/mapbox-gl-tests.ts index 90cb9ff580..6102b5c270 100644 --- a/mapbox-gl/mapbox-gl-tests.ts +++ b/mapbox-gl/mapbox-gl-tests.ts @@ -1,4 +1,3 @@ -// These examples are from Mapbox (https://www.mapbox.com/mapbox-gl-js/examples/) and therefore under the copyright of Mapbox Inc. /// /// @@ -12,51 +11,47 @@ mapboxgl.accessToken = 'foo'; * Display a Map */ let map = new mapboxgl.Map({ - container: 'map', // container id - style: 'mapbox://styles/mapbox/streets-v8', //stylesheet location - center: [-74.50, 40], // starting position - zoom: 9 // starting zoom + container: 'map', + style: 'mapbox://styles/mapbox/streets-v8', + center: [-50, 50], + zoom: 10, + minZoom: 1, + maxZoom: 2, + interactive: true, + attributionControl: false, + bearingSnap: 7, + scrollZoom: true, + maxBounds: [[-100,-90],[100,90]], + boxZoom: true, + dragRotate: false, + dragPan: true, }); /** * Create and style marker clusters */ -map = new mapboxgl.Map({ - container: 'map', - style: 'mapbox://styles/mapbox/dark-v8', - center: [-103.59179687498357, 40.66995747013945], - zoom: 3, -}); - map.on('load', function(){ // Add a new source from our GeoJSON data and set the // 'cluster' option to true. - map.addSource("earthquakes", { + map.addSource("data", { type: "geojson", - // Point to GeoJSON data. This example visualizes all M1.0+ earthquakes - // from 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program. - data: "/mapbox-gl-js/assets/earthquakes.geojson", + data: "/data.geojson", cluster: true, clusterMaxZoom: 14, // Max zoom to cluster points on clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50) }); - // Use the earthquakes source to create five layers: - // One for non-clustered markers, three for each cluster category, - // and one for cluster labels. map.addLayer({ - "id": "non-cluster-markers", + "id": "layer", "type": "symbol", - "source": "earthquakes", + "source": "data", "layout": { "icon-image": "marker-15" } }); - // Display the earthquake data in three layers, each filtered to a range of - // count values. Each range gets a different fill color. var layers = [ [150, '#f28cb1'], [20, '#f1f075'], @@ -67,7 +62,7 @@ map.on('load', function(){ map.addLayer({ "id": "cluster-" + i, "type": "circle", - "source": "earthquakes", + "source": "data", "paint": { "circle-color": layer[1], "circle-radius": 18 @@ -84,7 +79,7 @@ map.on('load', function(){ map.addLayer({ "id": "cluster-count", "type": "symbol", - "source": "earthquakes", + "source": "data", "layout": { "text-field": "{point_count}", "text-font": [ @@ -94,19 +89,10 @@ map.on('load', function(){ "text-size": 12 } }); -}); /** * Add a GeoJSON line */ -map = new mapboxgl.Map({ - container: 'map', - style: 'mapbox://styles/mapbox/streets-v8', - center: [-122.486052, 37.830348], - zoom: 15 -}); - -map.on('load', function () { map.addSource("route", { "type": "geojson", "data": { @@ -156,24 +142,13 @@ map.on('load', function () { }); }); -/** - * Display a Popup - */ - -map = new mapboxgl.Map({ - container: 'map', - style: 'mapbox://styles/mapbox/streets-v8', - center: [-96, 37.8], - zoom: 3 -}); - -map.flyTo({center: [0, 0], zoom: 9}); - +// FlyTo map.flyTo({ center: [0, 0], - zoom: 9, - speed: 0.2, + zoom: 10, + speed: 0.5, curve: 1, + screenSpeed: 1, easing: function(t: any) { return t; } @@ -190,10 +165,7 @@ var geoJSONSourceObj = new mapboxgl.GeoJSONSource({ "properties": null, "geometry": { "type": "Point", - "coordinates": [ - -76.53063297271729, - 39.18174077994108 - ] + "coordinates": [-50, 0] } }] } @@ -205,7 +177,7 @@ map.removeSource('some id'); // remove * ImageSource */ var imageSourceObj = new mapboxgl.ImageSource({ - url: 'https://www.mapbox.com/images/foo.png', + url: '/foo.png', coordinates: [ [-76.54335737228394, 39.18579907229748], [-76.52803659439087, 39.1838364847587], @@ -221,8 +193,8 @@ map.removeSource('some id'); // remove */ var videoSourceObj = new mapboxgl.VideoSource({ urls: [ - 'https://www.mapbox.com/videos/baltimore-smoke.mp4', - 'https://www.mapbox.com/videos/baltimore-smoke.webm' + '/blah.mp4', + '/blah.webm' ], coordinates: [ [-76.54335737228394, 39.18579907229748], @@ -235,10 +207,10 @@ map.addSource('some id', videoSourceObj); // add map.removeSource('some id'); // remove /** - * Tooltip + * Popup */ -var tooltip = new mapboxgl.Popup({closeOnClick: false}) - .setLngLat([-96, 37.8]) +var popup = new mapboxgl.Popup({closeOnClick: false, closeButton: true, anchor: 'top-right', offset: {'top': [0,0], 'bottom': [25,-50]} }) + .setLngLat([-50, 50]) .setHTML('

Hello World!

') .addTo(map); @@ -257,10 +229,10 @@ var mapStyle = { "type": "image", "url": "/mapbox-gl-js/assets/radar.gif", "coordinates": [ - [-80.425, 46.437], - [-71.516, 46.437], - [-71.516, 37.936], - [-80.425, 37.936] + [-50, 40], + [0, 40], + [0, 0], + [-50, 0] ] } }, @@ -334,18 +306,18 @@ var mapStyle = { map = new mapboxgl.Map({ container: 'map', - maxZoom: 5.99, - minZoom: 4, - zoom: 5, - center: [-75.789, 41.874], - style: mapStyle, + minZoom: 14, + zoom: 17, + center: [-122.514426, 37.562984], + bearing: -96, + style: videoStyle, hash: false }); /** * Add video */ -var videoStyle = { +var videoStyle: mapboxgl.Style = { "version": 8, "sources": { "satellite": { @@ -355,7 +327,7 @@ var videoStyle = { }, "video": { "type": "video", - "urls": ["https://www.mapbox.com/drone/video/drone.mp4", "https://www.mapbox.com/drone/video/drone.webm"], + "urls": ["drone.mp4", "drone.webm"], "coordinates": [ [-122.51596391201019, 37.56238816766053], [-122.51467645168304, 37.56410183312965], @@ -392,54 +364,10 @@ map = new mapboxgl.Map({ }); /** - * Add GeoJSON Markers + * Marker */ -map = new mapboxgl.Map({ - container: 'map', - style: 'mapbox://styles/mapbox/streets-v8', - center: [-96, 37.8], - zoom: 3 -}); +let marker = new mapboxgl.Marker(null,{offset: [10, 0]}) + .setLngLat([-50,50]) + .addTo(map); -map.on('load', function () { - map.addSource("markers", { - "type": "geojson", - "data": { - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [-77.03238901390978, 38.913188059745586] - }, - "properties": { - "title": "Mapbox DC", - "marker-symbol": "monument" - } - }, { - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [-122.414, 37.776] - }, - "properties": { - "title": "Mapbox SF", - "marker-symbol": "harbor" - } - }] - } - }); - - map.addLayer({ - "id": "markers", - "type": "symbol", - "source": "markers", - "layout": { - "icon-image": "{marker-symbol}-15", - "text-field": "{title}", - "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], - "text-offset": [0, 0.6], - "text-anchor": "top" - } - }); -}); \ No newline at end of file +marker.remove(); \ No newline at end of file From bd1771e4a21d0fdd298f2562bcaf9fc7b962e57e Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 22 Sep 2016 11:18:07 -0700 Subject: [PATCH 05/10] Typings for imap-simple. --- imap-simple/imap-simple-tests.ts | 85 ++++++++++++++++++++++++++++++++ imap-simple/imap-simple.d.ts | 69 ++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 imap-simple/imap-simple-tests.ts create mode 100644 imap-simple/imap-simple.d.ts diff --git a/imap-simple/imap-simple-tests.ts b/imap-simple/imap-simple-tests.ts new file mode 100644 index 0000000000..d54c16254e --- /dev/null +++ b/imap-simple/imap-simple-tests.ts @@ -0,0 +1,85 @@ +/// + +import * as imaps from "imap-simple"; + +let config = { + imap: { + user: "your@email.address", + password: "yourpassword", + host: "imap.gmail.com", + port: 993, + tls: true, + authTimeout: 3000 + } +}; + +imaps.connect(config).then(function (connection) { + + return connection.openBox("INBOX").then(function () { + let searchCriteria = [ + "UNSEEN" + ]; + + let fetchOptions = { + bodies: ["HEADER", "TEXT"], + markSeen: false + }; + + return connection.search(searchCriteria, fetchOptions).then(function (results) { + let subjects = results.map(function (res) { + return res.parts.filter(function (part) { + return part.which === "HEADER"; + })[0].body.subject[0]; + }); + + console.log(subjects); + // => + // [ "Hey Chad, long time no see!", + // "Your amazon.com monthly statement", + // "Hacker Newsletter Issue #445" ] + }); + }); +}); + +imaps.connect(config).then(function (connection) { + + connection.openBox("INBOX").then(function () { + + // Fetch emails from the last 24h + let delay = 24 * 3600 * 1000; + let yesterday = new Date(); + yesterday.setTime(Date.now() - delay); + let yesterdayString = yesterday.toISOString(); + let searchCriteria = ["UNSEEN", ["SINCE", yesterdayString]]; + let fetchOptions = { bodies: ["HEADER.FIELDS (FROM TO SUBJECT DATE)"], struct: true }; + + // retrieve only the headers of the messages + return connection.search(searchCriteria, fetchOptions); + }).then(function (messages) { + + let attachments: Promise<{filename: string, data: any}>[] = []; + + messages.forEach(function (message) { + let parts = imaps.getParts(message.attributes.struct); + attachments = attachments.concat(parts.filter(function (part) { + return part.disposition && part.disposition.type === "ATTACHMENT"; + }).map(function (part) { + // retrieve the attachments only of the messages with attachments + return connection.getPartData(message, part) + .then(function (partData) { + return { + filename: part.disposition.params.filename, + data: partData + }; + }); + })); + }); + + return Promise.all(attachments); + }).then(function (attachments: {filename: string, data: any}[]) { + console.log(attachments); + // => + // [ { filename: "cats.jpg", data: Buffer() }, + // { filename: "pay-stub.pdf", data: Buffer() } ] + }); +}); diff --git a/imap-simple/imap-simple.d.ts b/imap-simple/imap-simple.d.ts new file mode 100644 index 0000000000..6123a7e806 --- /dev/null +++ b/imap-simple/imap-simple.d.ts @@ -0,0 +1,69 @@ +// Type definitions for imap-simple v1.6.3 +// Project: https://github.com/chadxz/imap-simple +// Definitions by: Jeffery Grajkowski +// Definitions: https://github.com/psnider/DefinitelyTyped/imap-simple + +/// + +declare namespace IMAPS { + + export interface ImapSimpleOptions { + /** Options to pass to node-imap constructor. */ + imap: IMAP.Config; + + /** Time in milliseconds to wait before giving up on a connection attempt. (Deprecated: please use options.imap.authTimeout instead) */ + connectTimeout?: number; + } + + export interface MessageBodyPart extends IMAP.ImapMessageBodyInfo { + /** string type where which=='TEXT', complex Object where which=='HEADER' */ + body: any; + } + + export interface Message { + attributes: IMAP.ImapMessageAttributes; + parts: MessageBodyPart[]; + } + + export class ImapSimple { + constructor(imap: IMAP.Connection); + + /** Open a mailbox, calling the provided callback with signature (err, boxName), or resolves the returned promise with boxName. */ + openBox(boxName: string, callback?: (err: Error, boxName: string) => void): Promise; + + /** Search for and retrieve mail in the previously opened mailbox. */ + search(searchCriteria: any[], fetchOptions: IMAP.FetchOptions, callback?: (err: Error, messages: Message[]) => void): Promise; + + /** Close the connection to the imap server. */ + end(): void; + + /** Downloads part data (which is either part of the message body, or an attachment). Upon success, either the provided callback will be called with signature (err, data), or the returned promise will be resolved with data. The data will be automatically decoded based on its encoding. If the encoding of the part is not supported, an error will occur. */ + getPartData(message: Message, part: any, callback?: (err: Error, data: any) => void): Promise; + + /** Adds the provided label(s) to the specified message(s). source corresponds to a node-imap MessageSource which specifies the messages to be moved. label is either a string or array of strings indicating the labels to add. When completed, either calls the provided callback with signature (err), or resolves the returned promise. */ + addMessageLabel(source: string | string[], label: string | string[], callback?: (err: Error) => void): Promise; + + /** Moves the specified message(s) in the currently open mailbox to another mailbox. source corresponds to a node-imap MessageSource which specifies the messages to be moved. When completed, either calls the provided callback with signature (err), or resolves the returned promise. */ + moveMessage(source: string | string[], boxName: string, callback?: (err: Error) => void): Promise; + } + + /** Error thrown when a connection attempt has timed out. */ + export class ConnectionTimeoutError extends Error { + timeout: number; + constructor(timeout: number); + } +} + +declare module "imap-simple" { + /** Main entry point. Connect to an Imap server. */ + export const connect: (options: IMAPS.ImapSimpleOptions, callback?: Function) => Promise; + + export namespace errors { + export import ConnectionTimeoutError = IMAPS.ConnectionTimeoutError; + } + + export import ImapSimple = IMAPS.ImapSimple; + + /** Given the message.attributes.struct, retrieve a flattened array of parts objects that describe the structure of the different parts of the message's body. Useful for getting a simple list to iterate for the purposes of, for example, finding all attachments. */ + export const getParts: (struct: any[]) => any[]; +} From 5f5622fead1b6ca463529cab5d0e6844b3ff617a Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Thu, 22 Sep 2016 14:10:29 -0600 Subject: [PATCH 06/10] include link to mapbox gl examples --- mapbox-gl/mapbox-gl-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/mapbox-gl/mapbox-gl-tests.ts b/mapbox-gl/mapbox-gl-tests.ts index 6102b5c270..f77a9f4af7 100644 --- a/mapbox-gl/mapbox-gl-tests.ts +++ b/mapbox-gl/mapbox-gl-tests.ts @@ -1,3 +1,4 @@ +// These examples adapted from Mapbox's examples (https://www.mapbox.com/mapbox-gl-js/examples) /// /// From cb93e5fc4d6f539be1bc631fcaa823aed7b24f96 Mon Sep 17 00:00:00 2001 From: James Bracy Date: Thu, 22 Sep 2016 13:00:53 -0700 Subject: [PATCH 07/10] Adding rrule definition --- rrule/rrule-test.ts | 62 +++++++++++ rrule/rrule.d.ts | 249 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 311 insertions(+) create mode 100644 rrule/rrule-test.ts create mode 100644 rrule/rrule.d.ts diff --git a/rrule/rrule-test.ts b/rrule/rrule-test.ts new file mode 100644 index 0000000000..11a48c5126 --- /dev/null +++ b/rrule/rrule-test.ts @@ -0,0 +1,62 @@ +/// + +import * as RRule from 'rrule'; + +// Create a rule: +let rule: RRule = new RRule({ + freq: RRule.WEEKLY, + interval: 5, + byweekday: [RRule.MO, RRule.FR], + dtstart: new Date(2012, 1, 1, 10, 30), + until: new Date(2012, 12, 31) +}); + +let x: Date[]; +let y: string[]; + +// Get all occurrence dates (Date instances): +x = rule.all(); + +// Get a slice: +x = rule.between(new Date(2012, 7, 1), new Date(2012, 8, 1)) + +// Get an iCalendar RRULE string representation: +// The output can be used with RRule.fromString(). +y.push(rule.toString()); + +// Get a human-friendly text representation: +// The output can be used with RRule.fromText(). +y.push(rule.toText()); + +// Get full a string representation of all options, +// including the default and inferred ones. +y.push(RRule.optionsToString(rule.options)) + + +// Cherry-pick only some options from an rrule: +y.push(RRule.optionsToString({ + freq: rule.options.freq, + dtstart: rule.options.dtstart, +})) + +rule = RRule.fromString("FREQ=WEEKLY;DTSTART=20120201T093000Z") + +// This is equivalent +rule = new RRule(RRule.parseString("FREQ=WEEKLY;DTSTART=20120201T093000Z")) + +var options = RRule.parseString('FREQ=DAILY;INTERVAL=6') +options.dtstart = new Date(2000, 1, 1) +rule = new RRule(options) + +rule = new RRule({ + freq: RRule.WEEKLY, + count: 23 +}) +y.push(rule.toText()) + +rule = RRule.fromText('every day for 3 times') + +options = RRule.parseText('every day for 3 times') +// {freq: 3, count: "3"} +options.dtstart = new Date(2000, 1, 1) +rule = new RRule(options) \ No newline at end of file diff --git a/rrule/rrule.d.ts b/rrule/rrule.d.ts new file mode 100644 index 0000000000..d7e38129a0 --- /dev/null +++ b/rrule/rrule.d.ts @@ -0,0 +1,249 @@ +// Type definitions for rrule 2.1.0 +// Project: https://github.com/jkbrzt/rrule +// Definitions by: James Bracy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'rrule' { + export = RRule; +} + +declare namespace RRule { + + /** + * see + * The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ... + */ + interface Options { + freq: any; // Should be enum + dtstart?: Date; + interval?: number; + wkst?: number // | day enum + count?: number; + until?: Date; + bysetpos?: number; + bymonth?: number; + bymonthday?: number; + byyearday?: number; + byweekno?: number; + byweekday?: Weekday[]; + byhour?: number; + byminute?: number; + bysecond?: number; + } + + interface Weekday { + new (n: number): Weekday; + nth(n: number): Weekday; + equals(other: Weekday): boolean; + toString(): string; + getJsWeekday(): number; + } + +} + +declare class RRule { + + /** + * @param {Object?} options - see + * The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ... + * @constructor + */ + constructor(options: RRule.Options, noCache?: boolean); + + options: RRule.Options; + + origOptions: RRule.Options; + + /** + * Returns the first recurrence after the given datetime instance. + * The inc keyword defines what happens if dt is an occurrence. + * With inc == True, if dt itself is an occurrence, it will be returned. + * @return Date or null + */ + after(dt: Date, inc?: boolean): Date; + + /** + * @param {Function} iterator - optional function that will be called + * on each date that is added. It can return false + * to stop the iteration. + * @return Array containing all recurrences. + */ + all(iterator?: (date: Date) => void): Date[]; + + /** + * Returns all the occurrences of the rrule between after and before. + * The inc keyword defines what happens if after and/or before are + * themselves occurrences. With inc == True, they will be included in the + * list, if they are found in the recurrence set. + * @return Array + */ + between(a: Date, b: Date, iterator?: (date: Date) => void): Date[]; + + /** + * Returns the last recurrence before the given datetime instance. + * The inc keyword defines what happens if dt is an occurrence. + * With inc == True, if dt itself is an occurrence, it will be returned. + * @return Date or null + */ + before(dt: Date, inc?: boolean): Date; + + /** + * Returns the number of recurrences in this set. It will have go trough + * the whole recurrence, if this hasn't been done before. + */ + count(): number; + + /** + * Converts the rrule into its string representation + * @see + * @return String + */ + toString(): string; + + /** + * Will convert all rules described in nlp:ToText + * to text. + */ + toText(gettext?: (str: string) => string, language?: any): string; + + isFullyConvertibleToText(): boolean; + + clone(): RRule; + +} + +declare namespace RRule { + + const FREQUENCIES: ['YEARLY' | 'MONTHLY' | 'WEEKLY' | 'DAILY' | 'HOURLY' | 'MINUTELY' | 'SECONDLY']; + + const YEARLY: number; + const MONTHLY: number; + const WEEKLY: number; + const DAILY: number; + const HOURLY: number; + const MINUTELY: number; + const SECONDLY: number; + + const MO: Weekday; + const TU: Weekday; + const WE: Weekday; + const TH: Weekday; + const FR: Weekday; + const SA: Weekday; + const SU: Weekday; + + const DEFAULT_OPTIONS: RRule.Options; + + function parseText(text: string, language?: any): RRule.Options; + + function fromText(text: string, language?: any): RRule; + + function optionsToString(options: RRule.Options): string; + + function parseString(rfcString: string): RRule.Options; + + function fromString(value: string): RRule; + + class RRuleSet { + constructor(noCache?: boolean); + + /** + * @param {RRule} + */ + rrule(rrule: RRule): void; + + /** + * @param {Date} + */ + rdate(date: Date): void; + + /** + * @param {RRule} + */ + exrule(rrule: RRule): void; + + /** + * @param {Date} + */ + exdate(date: Date): void; + + valueOf(): string; + + /** + * to generate recurrence field sush as: + * ["RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU;DTSTART=19970902T010000Z","RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH;DTSTART=19970902T010000Z"] + */ + toString(): string; + + /** + * Create a new RRuleSet Object completely base on current instance + */ + clone(): RRuleSet; + + /** + * Returns the first recurrence after the given datetime instance. + * The inc keyword defines what happens if dt is an occurrence. + * With inc == True, if dt itself is an occurrence, it will be returned. + * @return Date or null + */ + after(dt: Date, inc?: boolean): Date; + + /** + * @param {Function} iterator - optional function that will be called + * on each date that is added. It can return false + * to stop the iteration. + * @return Array containing all recurrences. + */ + all(iterator?: (date: Date) => void): Date[] + + /** + * Returns all the occurrences of the rrule between after and before. + * The inc keyword defines what happens if after and/or before are + * themselves occurrences. With inc == True, they will be included in the + * list, if they are found in the recurrence set. + * @return Array + */ + between(a: Date, b: Date, iterator?: (date: Date) => void): Date[]; + + /** + * Returns the last recurrence before the given datetime instance. + * The inc keyword defines what happens if dt is an occurrence. + * With inc == True, if dt itself is an occurrence, it will be returned. + * @return Date or null + */ + before(dt: Date, inc?: boolean): Date; + + /** + * Returns the number of recurrences in this set. It will have go trough + * the whole recurrence, if this hasn't been done before. + */ + count(): number; + + } + + /** + * RRuleStr + * To parse a set of rrule strings + */ + class RRuleString { + constructor(); + parse(s: string, options: RRuleString.Options): RRuleSet | RRule; + } + + namespace RRuleString { + interface Options { + dtstart: Date; + cache: boolean; + unfold: boolean; + forceset: boolean; + compatible: boolean; + ignoretz: boolean; + tzinfos: any; + } + + const DEFAULT_OPTIONS: Options; + } + + const rrulestr: RRuleString; + +} From 91228f638f78912fa259eb7eb48ca5a4e7919684 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 22 Sep 2016 14:08:06 -0700 Subject: [PATCH 08/10] Updated imap-simple from code review feedback. --- imap-simple/imap-simple-tests.ts | 2 +- imap-simple/imap-simple.d.ts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/imap-simple/imap-simple-tests.ts b/imap-simple/imap-simple-tests.ts index d54c16254e..c4d0dee1d3 100644 --- a/imap-simple/imap-simple-tests.ts +++ b/imap-simple/imap-simple-tests.ts @@ -75,7 +75,7 @@ imaps.connect(config).then(function (connection) { })); }); - return Promise.all(attachments); + return Promise.all<{filename: string, data: any}>(attachments); }).then(function (attachments: {filename: string, data: any}[]) { console.log(attachments); // => diff --git a/imap-simple/imap-simple.d.ts b/imap-simple/imap-simple.d.ts index 6123a7e806..c7e66c4997 100644 --- a/imap-simple/imap-simple.d.ts +++ b/imap-simple/imap-simple.d.ts @@ -29,22 +29,27 @@ declare namespace IMAPS { constructor(imap: IMAP.Connection); /** Open a mailbox, calling the provided callback with signature (err, boxName), or resolves the returned promise with boxName. */ - openBox(boxName: string, callback?: (err: Error, boxName: string) => void): Promise; + openBox(boxName: string, callback: (err: Error, boxName: string) => void): void; + openBox(boxName: string): Promise; /** Search for and retrieve mail in the previously opened mailbox. */ - search(searchCriteria: any[], fetchOptions: IMAP.FetchOptions, callback?: (err: Error, messages: Message[]) => void): Promise; + search(searchCriteria: any[], fetchOptions: IMAP.FetchOptions, callback: (err: Error, messages: Message[]) => void): void; + search(searchCriteria: any[], fetchOptions: IMAP.FetchOptions): Promise; /** Close the connection to the imap server. */ end(): void; /** Downloads part data (which is either part of the message body, or an attachment). Upon success, either the provided callback will be called with signature (err, data), or the returned promise will be resolved with data. The data will be automatically decoded based on its encoding. If the encoding of the part is not supported, an error will occur. */ - getPartData(message: Message, part: any, callback?: (err: Error, data: any) => void): Promise; + getPartData(message: Message, part: any, callback: (err: Error, data: any) => void): void; + getPartData(message: Message, part: any): Promise; /** Adds the provided label(s) to the specified message(s). source corresponds to a node-imap MessageSource which specifies the messages to be moved. label is either a string or array of strings indicating the labels to add. When completed, either calls the provided callback with signature (err), or resolves the returned promise. */ - addMessageLabel(source: string | string[], label: string | string[], callback?: (err: Error) => void): Promise; + addMessageLabel(source: string | string[], label: string | string[], callback: (err: Error) => void): void; + addMessageLabel(source: string | string[], label: string | string[]): Promise; /** Moves the specified message(s) in the currently open mailbox to another mailbox. source corresponds to a node-imap MessageSource which specifies the messages to be moved. When completed, either calls the provided callback with signature (err), or resolves the returned promise. */ - moveMessage(source: string | string[], boxName: string, callback?: (err: Error) => void): Promise; + moveMessage(source: string | string[], boxName: string, callback: (err: Error) => void): void; + moveMessage(source: string | string[], boxName: string): Promise; } /** Error thrown when a connection attempt has timed out. */ @@ -56,7 +61,8 @@ declare namespace IMAPS { declare module "imap-simple" { /** Main entry point. Connect to an Imap server. */ - export const connect: (options: IMAPS.ImapSimpleOptions, callback?: Function) => Promise; + export function connect(options: IMAPS.ImapSimpleOptions, callback: (err: Error, connection: IMAPS.ImapSimple) => void): void; + export function connect(options: IMAPS.ImapSimpleOptions): Promise; export namespace errors { export import ConnectionTimeoutError = IMAPS.ConnectionTimeoutError; @@ -65,5 +71,5 @@ declare module "imap-simple" { export import ImapSimple = IMAPS.ImapSimple; /** Given the message.attributes.struct, retrieve a flattened array of parts objects that describe the structure of the different parts of the message's body. Useful for getting a simple list to iterate for the purposes of, for example, finding all attachments. */ - export const getParts: (struct: any[]) => any[]; + export function getParts(struct: any[]): any[]; } From ce1a37bd62e84bbf196308df8351815745e58024 Mon Sep 17 00:00:00 2001 From: James Bracy Date: Thu, 22 Sep 2016 14:24:48 -0700 Subject: [PATCH 09/10] Requested Revisions --- rrule/rrule.d.ts | 138 +++++++++-------------------------------------- 1 file changed, 25 insertions(+), 113 deletions(-) diff --git a/rrule/rrule.d.ts b/rrule/rrule.d.ts index d7e38129a0..a86a37c8c7 100644 --- a/rrule/rrule.d.ts +++ b/rrule/rrule.d.ts @@ -17,7 +17,7 @@ declare namespace RRule { freq: any; // Should be enum dtstart?: Date; interval?: number; - wkst?: number // | day enum + wkst?: number | Weekday count?: number; until?: Date; bysetpos?: number; @@ -31,11 +31,15 @@ declare namespace RRule { bysecond?: number; } - interface Weekday { - new (n: number): Weekday; + class Weekday { + constructor(weekday: number, n: number); + nth(n: number): Weekday; + equals(other: Weekday): boolean; + toString(): string; + getJsWeekday(): number; } @@ -114,15 +118,25 @@ declare class RRule { declare namespace RRule { - const FREQUENCIES: ['YEARLY' | 'MONTHLY' | 'WEEKLY' | 'DAILY' | 'HOURLY' | 'MINUTELY' | 'SECONDLY']; + const FREQUENCIES: "YEARLY" | "MONTHLY" | "WEEKLY" | "DAILY" | "HOURLY" | "MINUTELY" | "SECONDLY"; - const YEARLY: number; - const MONTHLY: number; - const WEEKLY: number; - const DAILY: number; - const HOURLY: number; - const MINUTELY: number; - const SECONDLY: number; + enum Frequency { + YEARLY = 0, + MONTHLY = 1, + WEEKLY = 2, + DAILY = 3, + HOURLY = 4, + MINUTELY = 5, + SECONDLY = 6 + } + + const YEARLY: Frequency; + const MONTHLY: Frequency; + const WEEKLY: Frequency; + const DAILY: Frequency; + const HOURLY: Frequency; + const MINUTELY: Frequency; + const SECONDLY: Frequency; const MO: Weekday; const TU: Weekday; @@ -144,106 +158,4 @@ declare namespace RRule { function fromString(value: string): RRule; - class RRuleSet { - constructor(noCache?: boolean); - - /** - * @param {RRule} - */ - rrule(rrule: RRule): void; - - /** - * @param {Date} - */ - rdate(date: Date): void; - - /** - * @param {RRule} - */ - exrule(rrule: RRule): void; - - /** - * @param {Date} - */ - exdate(date: Date): void; - - valueOf(): string; - - /** - * to generate recurrence field sush as: - * ["RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU;DTSTART=19970902T010000Z","RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH;DTSTART=19970902T010000Z"] - */ - toString(): string; - - /** - * Create a new RRuleSet Object completely base on current instance - */ - clone(): RRuleSet; - - /** - * Returns the first recurrence after the given datetime instance. - * The inc keyword defines what happens if dt is an occurrence. - * With inc == True, if dt itself is an occurrence, it will be returned. - * @return Date or null - */ - after(dt: Date, inc?: boolean): Date; - - /** - * @param {Function} iterator - optional function that will be called - * on each date that is added. It can return false - * to stop the iteration. - * @return Array containing all recurrences. - */ - all(iterator?: (date: Date) => void): Date[] - - /** - * Returns all the occurrences of the rrule between after and before. - * The inc keyword defines what happens if after and/or before are - * themselves occurrences. With inc == True, they will be included in the - * list, if they are found in the recurrence set. - * @return Array - */ - between(a: Date, b: Date, iterator?: (date: Date) => void): Date[]; - - /** - * Returns the last recurrence before the given datetime instance. - * The inc keyword defines what happens if dt is an occurrence. - * With inc == True, if dt itself is an occurrence, it will be returned. - * @return Date or null - */ - before(dt: Date, inc?: boolean): Date; - - /** - * Returns the number of recurrences in this set. It will have go trough - * the whole recurrence, if this hasn't been done before. - */ - count(): number; - - } - - /** - * RRuleStr - * To parse a set of rrule strings - */ - class RRuleString { - constructor(); - parse(s: string, options: RRuleString.Options): RRuleSet | RRule; - } - - namespace RRuleString { - interface Options { - dtstart: Date; - cache: boolean; - unfold: boolean; - forceset: boolean; - compatible: boolean; - ignoretz: boolean; - tzinfos: any; - } - - const DEFAULT_OPTIONS: Options; - } - - const rrulestr: RRuleString; - } From 22f99d0af39750cfbbc5d3f90967483d48386870 Mon Sep 17 00:00:00 2001 From: James Bracy Date: Thu, 22 Sep 2016 14:47:00 -0700 Subject: [PATCH 10/10] Add Freq option type --- rrule/rrule.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrule/rrule.d.ts b/rrule/rrule.d.ts index a86a37c8c7..247defc92b 100644 --- a/rrule/rrule.d.ts +++ b/rrule/rrule.d.ts @@ -14,7 +14,7 @@ declare namespace RRule { * The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ... */ interface Options { - freq: any; // Should be enum + freq: RRule.Frequency; dtstart?: Date; interval?: number; wkst?: number | Weekday