Added type definitions for leaflet-responsive-popup (#37814)

* Added type definitions for leaflet-responsive-popup

* Added function responsivePopup and capitalized class name to ResponsivePopup. Extended tests to initialize a class and to invoke a function. Strictness turned on (tsconfig).
This commit is contained in:
Stan Kurek
2019-08-22 00:36:52 +02:00
committed by Sheetal Nandi
parent a05485d556
commit cfca13ec2d
4 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
// Type definitions for leaflet-responsive-popup 0.6
// Project: https://github.com/yafred/leaflet-responsive-popup
// Definitions by: Stan Kurek <https://github.com/stankurek>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as L from 'leaflet';
declare module 'leaflet' {
interface ResponsivePopupOptions extends PopupOptions {
hasTip?: boolean;
}
class ResponsivePopup extends Popup {
constructor(options?: ResponsivePopupOptions, source?: Layer);
}
function responsivePopup(options?: ResponsivePopupOptions, source?: Layer): ResponsivePopup;
}

View File

@@ -0,0 +1,37 @@
import * as L from 'leaflet';
import 'leaflet-responsive-popup';
const osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors';
const osmTile = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib });
const map = new L.Map('map', {
layers: [osmTile],
center: new L.LatLng(50.054, 19.933),
zoom: 13,
});
const circle1 = L.circle([50.054, 19.933], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 120,
}).addTo(map);
const popup1 = L.responsivePopup({ hasTip: false, autoPan: false }, circle1)
.setLatLng([50.054, 19.933])
.setContent('Test popup 1');
circle1.bindPopup(popup1);
const circle2 = L.circle([50.154, 20.033], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 120,
}).addTo(map);
const popup2 = new L.ResponsivePopup({ hasTip: false, autoPan: false }, circle2)
.setLatLng([50.154, 20.033])
.setContent('Test popup 2');
circle2.bindPopup(popup2);

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"leaflet-responsive-popup-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }