Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
feat: Support for @types/google.maps (#694)
Browse files Browse the repository at this point in the history
Fixes #690
  • Loading branch information
piotter121 authored Jun 15, 2021
1 parent 3fca406 commit e78e58c
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 52 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"plugins": [
"license-header"
],
"plugins": ["license-header"],
"rules": {
"license-header/header": [
"error",
"../../header.js"
]
"license-header/header": ["error", "../../header.js"]
},
"parserOptions": {
"ecmaVersion": 6,
Expand All @@ -27,4 +22,4 @@
"env": {
"browser": true
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The following packages have never been officially published and are not maintain
## Other Resources
- [Google Maps JS Documentation](https://developers.google.com/maps/documentation/javascript/tutorial)
- [Google Maps JS Reference Documenations](https://developers.google.com/maps/documentation/javascript/reference/)
- [Google Maps Typings](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/googlemaps) - Community supported `npm i -D @types/googlemaps`
- [Google Maps Typings](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google.maps) - Community supported `npm i -D @types/google.maps`
- [Google Maps JS Samples](https://github.com/googlemaps/js-samples)

## Support
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@babel/preset-env": "^7.7.6",
"@babel/runtime-corejs3": "^7.8.7",
"@types/googlemaps": "^3.38.1",
"@types/google.maps": "^3.45.2",
"@types/jest": "^24.0.19",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-mocks/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export class Map_ extends MVCObject implements google.maps.Map {
getProjection = jest
.fn()
.mockImplementation((): google.maps.Projection | null => jest.fn() as null);
getRenderingType = jest
.fn()
.mockImplementation(
(): google.maps.RenderingType => google.maps.RenderingType.RASTER
);
getStreetView = jest
.fn()
.mockImplementation(
Expand All @@ -68,6 +73,9 @@ export class Map_ extends MVCObject implements google.maps.Map {
);
getTilt = jest.fn().mockImplementation((): number => 0);
getZoom = jest.fn().mockImplementation((): number => 0);
moveCamera = jest
.fn()
.mockImplementation((cameraOptions: google.maps.CameraOptions): void => {});
panBy = jest.fn().mockImplementation((x: number, y: number): void => {});
panTo = jest
.fn()
Expand Down
34 changes: 9 additions & 25 deletions packages/jest-mocks/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { LatLng } from "./index";

export class Marker extends MVCObject implements google.maps.Marker {
static readonly MAX_ZINDEX: number;
constructor(opts?: google.maps.ReadonlyMarkerOptions) {
constructor(opts?: google.maps.MarkerOptions | null) {
super();
}
getAnimation = jest
Expand All @@ -35,18 +35,12 @@ export class Marker extends MVCObject implements google.maps.Marker {
getIcon = jest
.fn()
.mockImplementation(
():
| string
| google.maps.ReadonlyIcon
| google.maps.ReadonlySymbol
| null
| undefined => null
(): string | google.maps.Icon | google.maps.Symbol | null | undefined =>
null
);
getLabel = jest
.fn()
.mockImplementation(
(): google.maps.ReadonlyMarkerLabel | null | undefined => null
);
.mockImplementation((): google.maps.MarkerLabel | null | undefined => null);
getMap = jest
.fn()
.mockImplementation(
Expand Down Expand Up @@ -83,18 +77,12 @@ export class Marker extends MVCObject implements google.maps.Marker {
setIcon = jest
.fn()
.mockImplementation(
(
icon:
| string
| google.maps.ReadonlyIcon
| google.maps.ReadonlySymbol
| null
): void => {}
(icon: string | google.maps.Icon | google.maps.Symbol | null): void => {}
);
setLabel = jest
.fn()
.mockImplementation(
(label: string | google.maps.ReadonlyMarkerLabel | null): void => {}
(label: string | google.maps.MarkerLabel | null): void => {}
);
setMap = jest
.fn()
Expand All @@ -106,14 +94,12 @@ export class Marker extends MVCObject implements google.maps.Marker {
.mockImplementation((opacity: number | null): void => {});
setOptions = jest
.fn()
.mockImplementation(
(options: google.maps.ReadonlyMarkerOptions): void => {}
);
.mockImplementation((options: google.maps.MarkerOptions): void => {});
setPosition = jest
.fn()
.mockImplementation(
(
latlng: google.maps.LatLng | google.maps.ReadonlyLatLngLiteral | null
latlng: google.maps.LatLng | google.maps.LatLngLiteral | null
): void => {}
);
setShape = jest
Expand All @@ -126,9 +112,7 @@ export class Marker extends MVCObject implements google.maps.Marker {
.fn()
.mockImplementation(
(
eventName:
| google.maps.MarkerChangeOptionEventNames
| google.maps.MarkerMouseEventNames,
eventName: string,
handler: (this: Marker, event: MouseEvent) => void
): google.maps.MapsEventListener =>
(jest.fn() as unknown) as google.maps.MapsEventListener
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

/// <reference types="@types/googlemaps" />
/// <reference types="@types/google.maps" />
/* eslint-disable @typescript-eslint/no-explicit-any */

export interface LoaderOptions {
Expand Down
12 changes: 8 additions & 4 deletions packages/markerclustererplus/src/cluster-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,16 @@ export class ClusterIcon extends OverlayViewSafe {
// But it doesn't work with earlier releases so do a version check.
if (gmVersion >= 332) {
// Ugly version-dependent code
google.maps.event.addDomListener(this.div_, "touchstart", e => {
e.stopPropagation();
});
google.maps.event.addDomListener(
this.div_,
"touchstart",
(e: TouchEvent) => {
e.stopPropagation();
}
);
}

google.maps.event.addDomListener(this.div_, "click", e => {
google.maps.event.addDomListener(this.div_, "click", (e: MouseEvent) => {
cMouseDownInCluster = false;
if (!cDraggingMapByCluster) {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/markerclustererplus/src/markerclusterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class MarkerClusterer extends OverlayViewSafe {

public ariaLabelFn = this.options.ariaLabelFn || ((): string => "");

private zIndex_ = this.options.zIndex || google.maps.Marker.MAX_ZINDEX + 1;
private zIndex_ = this.options.zIndex || +google.maps.Marker.MAX_ZINDEX + 1;
private gridSize_ = this.options.gridSize || 60;
private minClusterSize_ = this.options.minimumClusterSize || 2;
private maxZoom_ = this.options.maxZoom || null;
Expand Down
2 changes: 1 addition & 1 deletion packages/markermanager/src/markermanager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/// <reference types="@types/jest" />
/// <reference types="@types/googlemaps" />
/// <reference types="@types/google.maps" />
/* eslint-disable @typescript-eslint/no-explicit-any */

import { MarkerManager } from "./markermanager";
Expand Down
16 changes: 12 additions & 4 deletions packages/markermanager/src/markermanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

/// <reference types="@types/googlemaps" />
/// <reference types="@types/google.maps" />

import { latLngToPixel } from "./utils";
import { GridBounds } from "./gridbounds";
Expand Down Expand Up @@ -210,9 +210,17 @@ class MarkerManager {
// Tracking markers is expensive, so we do this only if the
// user explicitly requested it when creating marker manager.
if (this._trackMarkers) {
google.maps.event.addListener(marker, "changed", function(a, b, c) {
this._onMarkerMoved(a, b, c);
});
google.maps.event.addListener(
marker,
"changed",
(
marker: google.maps.Marker,
oldPoint: google.maps.LatLng,
newPoint: google.maps.LatLng
) => {
this._onMarkerMoved(marker, oldPoint, newPoint);
}
);
}

const gridPoint = this._getTilePoint(
Expand Down
2 changes: 1 addition & 1 deletion packages/ogc/src/wmsmaptype.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/// <reference types="@types/jest" />
/// <reference types="@types/googlemaps" />
/// <reference types="@types/google.maps" />

import { initialize } from "@googlemaps/jest-mocks";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/ogc/src/wmsmaptype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

/// <reference types="@types/googlemaps" />
/// <reference types="@types/google.maps" />
import { stringify } from "query-string";

/**
Expand Down

0 comments on commit e78e58c

Please sign in to comment.