Browse Source

[3.0] Improvement map (#2706)

* Fix load custom marker image for Firefox

* Fix update polygon color
pull/2729/head
Vladyslav 7 years ago
committed by GitHub
parent
commit
7013377d8c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      ui-ngx/src/app/core/utils.ts
  2. 6
      ui-ngx/src/app/modules/home/components/widget/lib/maps/polygon.ts

31
ui-ngx/src/app/core/utils.ts

@ -15,8 +15,8 @@
/// ///
import _ from 'lodash'; import _ from 'lodash';
import { Observable, Subject, fromEvent, of } from 'rxjs'; import { Observable, Observer, of, Subject } from 'rxjs';
import { finalize, share, map } from 'rxjs/operators'; import { finalize, map, share } from 'rxjs/operators';
import base64js from 'base64-js'; import base64js from 'base64-js';
import { Datasource } from '@app/shared/models/widget.models'; import { Datasource } from '@app/shared/models/widget.models';
@ -224,11 +224,14 @@ function scrollParents(node: Node): Node[] {
function hashCode(str) { function hashCode(str) {
let hash = 0; let hash = 0;
let i, char; let i;
let char;
if (str.length === 0) return hash; if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i); char = str.charCodeAt(i);
// tslint:disable-next-line:no-bitwise
hash = ((hash << 5) - hash) + char; hash = ((hash << 5) - hash) + char;
// tslint:disable-next-line:no-bitwise
hash = hash & hash; // Convert to 32bit integer hash = hash & hash; // Convert to 32bit integer
} }
return hash; return hash;
@ -430,10 +433,24 @@ export function getDescendantProp(obj: any, path: string): any {
} }
export function imageLoader(imageUrl: string): Observable<HTMLImageElement> { export function imageLoader(imageUrl: string): Observable<HTMLImageElement> {
const image = new Image(); return new Observable((observer: Observer<HTMLImageElement>) => {
const imageLoad$ = fromEvent(image, 'load').pipe(map(() => image)); const image = new Image();
image.src = imageUrl; image.style.position = 'absolute';
return imageLoad$; image.style.left = '-99999px';
image.style.top = '-99999px';
image.onload = () => {
observer.next(image);
document.body.removeChild(image);
observer.complete();
};
image.onerror = err => {
observer.error(err);
document.body.removeChild(image);
observer.complete();
};
document.body.appendChild(image)
image.src = imageUrl;
});
} }
export function createLabelFromDatasource(datasource: Datasource, pattern: string) { export function createLabelFromDatasource(datasource: Datasource, pattern: string) {

6
ui-ngx/src/app/modules/home/components/widget/lib/maps/polygon.ts

@ -69,8 +69,8 @@ export class Polygon {
updatePolygonColor(settings) { updatePolygonColor(settings) {
const style: L.PathOptions = { const style: L.PathOptions = {
fill: true, fill: true,
fillColor: settings.color, fillColor: settings.polygonColor,
color: settings.color, color: settings.polygonStrokeColor,
weight: settings.polygonStrokeWeight, weight: settings.polygonStrokeWeight,
fillOpacity: settings.polygonOpacity, fillOpacity: settings.polygonOpacity,
opacity: settings.polygonStrokeOpacity opacity: settings.polygonStrokeOpacity
@ -86,4 +86,4 @@ export class Polygon {
this.leafletPoly.setLatLngs(latLngs); this.leafletPoly.setLatLngs(latLngs);
this.leafletPoly.redraw(); this.leafletPoly.redraw();
} }
} }

Loading…
Cancel
Save