Commit 65015bfd732c3702abd7b8273c189b11d0cc99b3

Authored by Vladyslav
Committed by GitHub
1 parent e8ee8cb6

[3.0] Improvement image map (#2740)

* Fixed not correct center image map
Fixed update position marker for image map

* Add support IE and clear code

* Fix not correct update image for datasource

* Update marker position
... ... @@ -40,7 +40,6 @@ export default abstract class LeafletMap {
40 40 markers: Map<string, Marker> = new Map();
41 41 polylines: Map<string, Polyline> = new Map();
42 42 polygons: Map<string, Polygon> = new Map();
43   - dragMode = false;
44 43 map: L.Map;
45 44 map$: BehaviorSubject<L.Map> = new BehaviorSubject(null);
46 45 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map));
... ... @@ -238,7 +237,7 @@ export default abstract class LeafletMap {
238 237
239 238 convertToCustomFormat(position: L.LatLng): object {
240 239 return {
241   - [this.options.latKeyName]: position.lat % 180,
  240 + [this.options.latKeyName]: position.lat % 90,
242 241 [this.options.lngKeyName]: position.lng % 180
243 242 }
244 243 }
... ...
... ... @@ -75,7 +75,7 @@ const imageAspectMap = {};
75 75
76 76 function imageLoader(imageUrl: string): Observable<HTMLImageElement> {
77 77 return new Observable((observer: Observer<HTMLImageElement>) => {
78   - const image = new Image();
  78 + const image = document.createElement('img'); // support IE
79 79 image.style.position = 'absolute';
80 80 image.style.left = '-99999px';
81 81 image.style.top = '-99999px';
... ... @@ -236,3 +236,13 @@ export function safeExecute(func: (...args: any[]) => any, params = []) {
236 236 }
237 237 return res;
238 238 }
  239 +
  240 +export function calculateNewPointCoordinate(coordinate: number, imageSize: number): number {
  241 + let pointCoordinate = coordinate / imageSize;
  242 + if (pointCoordinate < 0) {
  243 + pointCoordinate = 0;
  244 + } else if (pointCoordinate > 1) {
  245 + pointCoordinate = 1;
  246 + }
  247 + return pointCoordinate;
  248 +}
... ...
... ... @@ -29,8 +29,8 @@ export class Marker {
29 29 data: FormattedData;
30 30 dataSources: FormattedData[];
31 31
32   - constructor(location: L.LatLngExpression, public settings: MarkerSettings,
33   - data?: FormattedData, dataSources?, onDragendListener?) {
  32 + constructor(location: L.LatLngExpression, public settings: MarkerSettings,
  33 + data?: FormattedData, dataSources?, onDragendListener?) {
34 34 this.setDataSources(data, dataSources);
35 35 this.leafletMarker = L.marker(location, {
36 36 draggable: settings.draggableMarker
... ...
... ... @@ -19,7 +19,7 @@ import LeafletMap from '../leaflet-map';
19 19 import { UnitedMapSettings } from '../map-models';
20 20 import { Observable } from 'rxjs';
21 21 import { map, filter, switchMap } from 'rxjs/operators';
22   -import { aspectCache, parseFunction } from '@home/components/widget/lib/maps/maps-utils';
  22 +import { aspectCache, calculateNewPointCoordinate, parseFunction } from '@home/components/widget/lib/maps/maps-utils';
23 23
24 24 const maxZoom = 4;// ?
25 25
... ... @@ -79,9 +79,10 @@ export class ImageMap extends LeafletMap {
79 79 if (lastCenterPos) {
80 80 lastCenterPos.x *= w;
81 81 lastCenterPos.y *= h;
82   - /* this.ctx.$scope.$injector.get('$mdUtil').nextTick(() => {
83   - this.map.panTo(center, { animate: false });
84   - });*/
  82 + const center = this.pointToLatLng(lastCenterPos.x, lastCenterPos.y);
  83 + setTimeout(() => {
  84 + this.map.panTo(center, { animate: false });
  85 + }, 0);
85 86 }
86 87 }
87 88
... ... @@ -97,7 +98,7 @@ export class ImageMap extends LeafletMap {
97 98 width *= maxZoom;
98 99 const prevWidth = this.width;
99 100 const prevHeight = this.height;
100   - if (this.width !== width) {
  101 + if (this.width !== width || updateImage) {
101 102 this.width = width;
102 103 this.height = width / this.aspect;
103 104 if (!this.map) {
... ... @@ -108,6 +109,7 @@ export class ImageMap extends LeafletMap {
108 109 lastCenterPos.y /= prevHeight;
109 110 this.updateBounds(updateImage, lastCenterPos);
110 111 this.map.invalidateSize(true);
  112 + // TODO: need add update marker position
111 113 }
112 114 }
113 115 }
... ... @@ -133,7 +135,7 @@ export class ImageMap extends LeafletMap {
133 135
134 136 convertPosition(expression): L.LatLng {
135 137 if (isNaN(expression[this.options.xPosKeyName]) || isNaN(expression[this.options.yPosKeyName])) return null;
136   - Object.assign(expression, this.posFunction(expression[this.options.xPosKeyName], expression[this.options.yPosKeyName]))
  138 + Object.assign(expression, this.posFunction(expression[this.options.xPosKeyName], expression[this.options.yPosKeyName]));
137 139 return this.pointToLatLng(
138 140 expression.x * this.width,
139 141 expression.y * this.height);
... ... @@ -148,9 +150,10 @@ export class ImageMap extends LeafletMap {
148 150 }
149 151
150 152 convertToCustomFormat(position: L.LatLng): object {
  153 + const point = this.latLngToPoint(position);
151 154 return {
152   - [this.options.xPosKeyName]: (position.lng + 180) / 360,
153   - [this.options.yPosKeyName]: (position.lat + 180) / 360
  155 + [this.options.xPosKeyName]: calculateNewPointCoordinate(point.x, this.width),
  156 + [this.options.yPosKeyName]: calculateNewPointCoordinate(point.y, this.height)
154 157 }
155 158 }
156 159 }
... ...