Skip to content

Commit

Permalink
Merge branch 'release/1.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Dubrava committed Nov 27, 2019
2 parents 38092a6 + 76ea70c commit 63b66b3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes from v1.0.0 will be documented in this file.

## [1.10.1] - 2019-11-27
### Fixed
- Lazy loading of YMaps script

## [1.10.0] - 2019-11-22
### Changed
- IEvent - ymaps: any is added
Expand Down Expand Up @@ -87,6 +91,7 @@ All notable changes from v1.0.0 will be documented in this file.
## [1.0.0] - 2019-09-14
- Release without changes

[1.10.1]: https://github.com/ddubrava/angular-yandex-maps/compare/v1.10.0...v1.10.1
[1.10.0]: https://github.com/ddubrava/angular-yandex-maps/compare/v1.9.0...v1.10.0
[1.9.0]: https://github.com/ddubrava/angular-yandex-maps/compare/v1.8.0...v1.9.0
[1.8.0]: https://github.com/ddubrava/angular-yandex-maps/compare/v1.7.3...v1.8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![npm version](https://badge.fury.io/js/angular8-yandex-maps.svg)](https://badge.fury.io/js/angular8-yandex-maps) ![npm bundle size](https://img.shields.io/bundlephobia/min/angular8-yandex-maps) ![GitHub stars](https://img.shields.io/github/stars/ddubrava/angular-yandex-maps?style=social)
[![npm version](https://badge.fury.io/js/angular8-yandex-maps.svg)](https://badge.fury.io/js/angular8-yandex-maps) ![npm bundle size](https://img.shields.io/bundlephobia/min/angular8-yandex-maps) ![npm](https://img.shields.io/npm/dm/angular8-yandex-maps) ![GitHub stars](https://img.shields.io/github/stars/ddubrava/angular-yandex-maps?style=social)

# Angular8-yandex-maps
Angular 6+ module for Yandex.Maps
Expand Down
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "angular-yandex-maps",
"version": "1.10.0",
"version": "1.10.1",
"scripts": {
"start": "ng serve",
"build": "ng build",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular8-yandex-maps/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![npm version](https://badge.fury.io/js/angular8-yandex-maps.svg)](https://badge.fury.io/js/angular8-yandex-maps) ![npm bundle size](https://img.shields.io/bundlephobia/min/angular8-yandex-maps) ![GitHub stars](https://img.shields.io/github/stars/ddubrava/angular-yandex-maps?style=social)
[![npm version](https://badge.fury.io/js/angular8-yandex-maps.svg)](https://badge.fury.io/js/angular8-yandex-maps) ![npm bundle size](https://img.shields.io/bundlephobia/min/angular8-yandex-maps) ![npm](https://img.shields.io/npm/dm/angular8-yandex-maps) ![GitHub stars](https://img.shields.io/github/stars/ddubrava/angular-yandex-maps?style=social)

# Angular8-yandex-maps
Angular 6+ module for Yandex.Maps
Expand Down
2 changes: 1 addition & 1 deletion projects/angular8-yandex-maps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular8-yandex-maps",
"version": "1.10.0",
"version": "1.10.1",
"description": "Angular module for Yandex.Maps",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { Injectable, Injector } from '@angular/core';
import { Subject } from 'rxjs';
import { Inject, Injectable, Injector } from '@angular/core';
import { from, fromEvent, Observable } from 'rxjs';
import { IYandexMapService } from './yandex-service.type';
import { DOCUMENT } from '@angular/common';
import { map, switchMap } from 'rxjs/operators';

declare const ymaps: any;

/** @dynamic */
@Injectable({
providedIn: 'root'
})
export class YandexMapService implements IYandexMapService {
private _ymaps$ = new Subject<any>();
private _scriptYmaps: HTMLScriptElement;
private _apiKey: string;

constructor(private _injector: Injector) {
constructor(private _injector: Injector, @Inject(DOCUMENT) private document: Document) {
this._apiKey = this._injector.get('API_KEY');
}

/**
* Init ymaps script if it's not initiated
* Return ymaps subject
*/
public initScript(): Subject<any> {
public initScript(): Observable<any> {
if (!this._scriptYmaps) {
this._loadScript();

this._scriptYmaps.onload = () => {
ymaps.ready(() => this._ymaps$.next(ymaps));
};
const ymapScript = this.document.createElement('script');
ymapScript.src = `https://api-maps.yandex.ru/2.1/?apikey=${this._apiKey}&lang=ru_RU`;
this._scriptYmaps = this.document.body.appendChild(ymapScript);
}

return this._ymaps$;
}
if ('ymaps' in window) {
return from(ymaps.ready()).pipe(map(() => ymaps));
}

private _loadScript(): void {
this._scriptYmaps = document.createElement('script');
this._scriptYmaps.src = `https://api-maps.yandex.ru/2.1/?apikey=${this._apiKey}&lang=ru_RU`;
document.body.appendChild(this._scriptYmaps);
return fromEvent(this._scriptYmaps, 'load').pipe(
switchMap(() => from(ymaps.ready()).pipe(map(() => ymaps)))
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subject } from 'rxjs';
import { Observable } from 'rxjs';

export interface IYandexMapService {
initScript(): Subject<any>;
initScript(): Observable<any>;
}

0 comments on commit 63b66b3

Please sign in to comment.