Commit 7013377d8c4138d019936aba57b6fab0ef8ebfa9

Authored by Vladyslav
Committed by GitHub
1 parent 11db772e

[3.0] Improvement map (#2706)

* Fix load custom marker image for Firefox

* Fix update polygon color
@@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
15 /// 15 ///
16 16
17 import _ from 'lodash'; 17 import _ from 'lodash';
18 -import { Observable, Subject, fromEvent, of } from 'rxjs';  
19 -import { finalize, share, map } from 'rxjs/operators'; 18 +import { Observable, Observer, of, Subject } from 'rxjs';
  19 +import { finalize, map, share } from 'rxjs/operators';
20 import base64js from 'base64-js'; 20 import base64js from 'base64-js';
21 import { Datasource } from '@app/shared/models/widget.models'; 21 import { Datasource } from '@app/shared/models/widget.models';
22 22
@@ -224,11 +224,14 @@ function scrollParents(node: Node): Node[] { @@ -224,11 +224,14 @@ function scrollParents(node: Node): Node[] {
224 224
225 function hashCode(str) { 225 function hashCode(str) {
226 let hash = 0; 226 let hash = 0;
227 - let i, char; 227 + let i;
  228 + let char;
228 if (str.length === 0) return hash; 229 if (str.length === 0) return hash;
229 for (i = 0; i < str.length; i++) { 230 for (i = 0; i < str.length; i++) {
230 char = str.charCodeAt(i); 231 char = str.charCodeAt(i);
  232 + // tslint:disable-next-line:no-bitwise
231 hash = ((hash << 5) - hash) + char; 233 hash = ((hash << 5) - hash) + char;
  234 + // tslint:disable-next-line:no-bitwise
232 hash = hash & hash; // Convert to 32bit integer 235 hash = hash & hash; // Convert to 32bit integer
233 } 236 }
234 return hash; 237 return hash;
@@ -430,10 +433,24 @@ export function getDescendantProp(obj: any, path: string): any { @@ -430,10 +433,24 @@ export function getDescendantProp(obj: any, path: string): any {
430 } 433 }
431 434
432 export function imageLoader(imageUrl: string): Observable<HTMLImageElement> { 435 export function imageLoader(imageUrl: string): Observable<HTMLImageElement> {
433 - const image = new Image();  
434 - const imageLoad$ = fromEvent(image, 'load').pipe(map(() => image));  
435 - image.src = imageUrl;  
436 - return imageLoad$; 436 + return new Observable((observer: Observer<HTMLImageElement>) => {
  437 + const image = new Image();
  438 + image.style.position = 'absolute';
  439 + image.style.left = '-99999px';
  440 + image.style.top = '-99999px';
  441 + image.onload = () => {
  442 + observer.next(image);
  443 + document.body.removeChild(image);
  444 + observer.complete();
  445 + };
  446 + image.onerror = err => {
  447 + observer.error(err);
  448 + document.body.removeChild(image);
  449 + observer.complete();
  450 + };
  451 + document.body.appendChild(image)
  452 + image.src = imageUrl;
  453 + });
437 } 454 }
438 455
439 export function createLabelFromDatasource(datasource: Datasource, pattern: string) { 456 export function createLabelFromDatasource(datasource: Datasource, pattern: string) {
@@ -69,8 +69,8 @@ export class Polygon { @@ -69,8 +69,8 @@ export class Polygon {
69 updatePolygonColor(settings) { 69 updatePolygonColor(settings) {
70 const style: L.PathOptions = { 70 const style: L.PathOptions = {
71 fill: true, 71 fill: true,
72 - fillColor: settings.color,  
73 - color: settings.color, 72 + fillColor: settings.polygonColor,
  73 + color: settings.polygonStrokeColor,
74 weight: settings.polygonStrokeWeight, 74 weight: settings.polygonStrokeWeight,
75 fillOpacity: settings.polygonOpacity, 75 fillOpacity: settings.polygonOpacity,
76 opacity: settings.polygonStrokeOpacity 76 opacity: settings.polygonStrokeOpacity
@@ -86,4 +86,4 @@ export class Polygon { @@ -86,4 +86,4 @@ export class Polygon {
86 this.leafletPoly.setLatLngs(latLngs); 86 this.leafletPoly.setLatLngs(latLngs);
87 this.leafletPoly.redraw(); 87 this.leafletPoly.redraw();
88 } 88 }
89 -}  
  89 +}