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,7 +40,6 @@ export default abstract class LeafletMap {
40 markers: Map<string, Marker> = new Map(); 40 markers: Map<string, Marker> = new Map();
41 polylines: Map<string, Polyline> = new Map(); 41 polylines: Map<string, Polyline> = new Map();
42 polygons: Map<string, Polygon> = new Map(); 42 polygons: Map<string, Polygon> = new Map();
43 - dragMode = false;  
44 map: L.Map; 43 map: L.Map;
45 map$: BehaviorSubject<L.Map> = new BehaviorSubject(null); 44 map$: BehaviorSubject<L.Map> = new BehaviorSubject(null);
46 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); 45 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map));
@@ -238,7 +237,7 @@ export default abstract class LeafletMap { @@ -238,7 +237,7 @@ export default abstract class LeafletMap {
238 237
239 convertToCustomFormat(position: L.LatLng): object { 238 convertToCustomFormat(position: L.LatLng): object {
240 return { 239 return {
241 - [this.options.latKeyName]: position.lat % 180, 240 + [this.options.latKeyName]: position.lat % 90,
242 [this.options.lngKeyName]: position.lng % 180 241 [this.options.lngKeyName]: position.lng % 180
243 } 242 }
244 } 243 }
@@ -75,7 +75,7 @@ const imageAspectMap = {}; @@ -75,7 +75,7 @@ const imageAspectMap = {};
75 75
76 function imageLoader(imageUrl: string): Observable<HTMLImageElement> { 76 function imageLoader(imageUrl: string): Observable<HTMLImageElement> {
77 return new Observable((observer: Observer<HTMLImageElement>) => { 77 return new Observable((observer: Observer<HTMLImageElement>) => {
78 - const image = new Image(); 78 + const image = document.createElement('img'); // support IE
79 image.style.position = 'absolute'; 79 image.style.position = 'absolute';
80 image.style.left = '-99999px'; 80 image.style.left = '-99999px';
81 image.style.top = '-99999px'; 81 image.style.top = '-99999px';
@@ -236,3 +236,13 @@ export function safeExecute(func: (...args: any[]) => any, params = []) { @@ -236,3 +236,13 @@ export function safeExecute(func: (...args: any[]) => any, params = []) {
236 } 236 }
237 return res; 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,8 +29,8 @@ export class Marker {
29 data: FormattedData; 29 data: FormattedData;
30 dataSources: FormattedData[]; 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 this.setDataSources(data, dataSources); 34 this.setDataSources(data, dataSources);
35 this.leafletMarker = L.marker(location, { 35 this.leafletMarker = L.marker(location, {
36 draggable: settings.draggableMarker 36 draggable: settings.draggableMarker
@@ -19,7 +19,7 @@ import LeafletMap from '../leaflet-map'; @@ -19,7 +19,7 @@ import LeafletMap from '../leaflet-map';
19 import { UnitedMapSettings } from '../map-models'; 19 import { UnitedMapSettings } from '../map-models';
20 import { Observable } from 'rxjs'; 20 import { Observable } from 'rxjs';
21 import { map, filter, switchMap } from 'rxjs/operators'; 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 const maxZoom = 4;// ? 24 const maxZoom = 4;// ?
25 25
@@ -79,9 +79,10 @@ export class ImageMap extends LeafletMap { @@ -79,9 +79,10 @@ export class ImageMap extends LeafletMap {
79 if (lastCenterPos) { 79 if (lastCenterPos) {
80 lastCenterPos.x *= w; 80 lastCenterPos.x *= w;
81 lastCenterPos.y *= h; 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,7 +98,7 @@ export class ImageMap extends LeafletMap {
97 width *= maxZoom; 98 width *= maxZoom;
98 const prevWidth = this.width; 99 const prevWidth = this.width;
99 const prevHeight = this.height; 100 const prevHeight = this.height;
100 - if (this.width !== width) { 101 + if (this.width !== width || updateImage) {
101 this.width = width; 102 this.width = width;
102 this.height = width / this.aspect; 103 this.height = width / this.aspect;
103 if (!this.map) { 104 if (!this.map) {
@@ -108,6 +109,7 @@ export class ImageMap extends LeafletMap { @@ -108,6 +109,7 @@ export class ImageMap extends LeafletMap {
108 lastCenterPos.y /= prevHeight; 109 lastCenterPos.y /= prevHeight;
109 this.updateBounds(updateImage, lastCenterPos); 110 this.updateBounds(updateImage, lastCenterPos);
110 this.map.invalidateSize(true); 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,7 +135,7 @@ export class ImageMap extends LeafletMap {
133 135
134 convertPosition(expression): L.LatLng { 136 convertPosition(expression): L.LatLng {
135 if (isNaN(expression[this.options.xPosKeyName]) || isNaN(expression[this.options.yPosKeyName])) return null; 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 return this.pointToLatLng( 139 return this.pointToLatLng(
138 expression.x * this.width, 140 expression.x * this.width,
139 expression.y * this.height); 141 expression.y * this.height);
@@ -148,9 +150,10 @@ export class ImageMap extends LeafletMap { @@ -148,9 +150,10 @@ export class ImageMap extends LeafletMap {
148 } 150 }
149 151
150 convertToCustomFormat(position: L.LatLng): object { 152 convertToCustomFormat(position: L.LatLng): object {
  153 + const point = this.latLngToPoint(position);
151 return { 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 }