Commit 0fa92850295a3ae7c61a4f93122b072c413a0cc2

Authored by Sergey Tarnavskiy
1 parent 5b0784f2

fixed label/tooltip updating

... ... @@ -221,7 +221,7 @@ export default class TbGoogleMap {
221 221 /* eslint-enable no-undef */
222 222
223 223 /* eslint-disable no-undef */
224   - createMarker(location, settings, onClickListener, markerArgs) {
  224 + createMarker(location, dsIndex, settings, onClickListener, markerArgs) {
225 225 var marker;
226 226 if (settings.showLabel) {
227 227 marker = new MarkerWithLabel({
... ... @@ -244,7 +244,7 @@ export default class TbGoogleMap {
244 244 });
245 245
246 246 if (settings.displayTooltip) {
247   - this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo, settings.autocloseTooltip, markerArgs);
  247 + this.createTooltip(marker, dsIndex, settings, markerArgs);
248 248 }
249 249
250 250 if (onClickListener) {
... ... @@ -261,13 +261,13 @@ export default class TbGoogleMap {
261 261 /* eslint-enable no-undef */
262 262
263 263 /* eslint-disable no-undef */
264   - createTooltip(marker, pattern, replaceInfo, autoClose, markerArgs) {
  264 + createTooltip(marker, dsIndex, settings, markerArgs) {
265 265 var popup = new google.maps.InfoWindow({
266 266 content: ''
267 267 });
268 268 var map = this;
269 269 marker.addListener('click', function() {
270   - if (autoClose) {
  270 + if (settings.autocloseTooltip) {
271 271 map.tooltips.forEach((tooltip) => {
272 272 tooltip.popup.close();
273 273 });
... ... @@ -277,8 +277,8 @@ export default class TbGoogleMap {
277 277 this.tooltips.push( {
278 278 markerArgs: markerArgs,
279 279 popup: popup,
280   - pattern: pattern,
281   - replaceInfo: replaceInfo
  280 + locationSettings: settings,
  281 + dsIndex: dsIndex
282 282 });
283 283 }
284 284 /* eslint-enable no-undef */
... ...
... ... @@ -298,7 +298,7 @@ export default class TbImageMap {
298 298 onMarkerIconReady(iconInfo);
299 299 }
300 300
301   - createMarker(position, settings, onClickListener, markerArgs) {
  301 + createMarker(position, dsIndex, settings, onClickListener, markerArgs) {
302 302 var pos = this.posFunction(position.x, position.y);
303 303 var x = pos.x * this.width;
304 304 var y = pos.y * this.height;
... ... @@ -319,7 +319,7 @@ export default class TbImageMap {
319 319 });
320 320
321 321 if (settings.displayTooltip) {
322   - this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo, settings.autocloseTooltip, markerArgs);
  322 + this.createTooltip(marker, dsIndex, settings, markerArgs);
323 323 }
324 324
325 325 if (onClickListener) {
... ... @@ -348,15 +348,15 @@ export default class TbImageMap {
348 348 }
349 349 }
350 350
351   - createTooltip(marker, pattern, replaceInfo, autoClose, markerArgs) {
  351 + createTooltip(marker, dsIndex, settings, markerArgs) {
352 352 var popup = L.popup();
353 353 popup.setContent('');
354   - marker.bindPopup(popup, {autoClose: autoClose, closeOnClick: false});
  354 + marker.bindPopup(popup, {autoClose: settings.autocloseTooltip, closeOnClick: false});
355 355 this.tooltips.push( {
356 356 markerArgs: markerArgs,
357 357 popup: popup,
358   - pattern: pattern,
359   - replaceInfo: replaceInfo
  358 + locationSettings: settings,
  359 + dsIndex: dsIndex
360 360 });
361 361 }
362 362
... ...
... ... @@ -210,14 +210,30 @@ export default class TbMapWidgetV2 {
210 210
211 211 var tbMap = this;
212 212
213   - function updateLocationLabel(location) {
214   - if (location.settings.showLabel && location.settings.labelReplaceInfo.variables.length) {
215   - location.settings.labelText = fillPattern(location.settings.label,
216   - location.settings.labelReplaceInfo, tbMap.subscription.data);
  213 + function updateLocationLabel(location, dataMap) {
  214 + if (location.settings.showLabel) {
  215 + if (location.settings.useLabelFunction && location.settings.labelFunction) {
  216 + try {
  217 + location.settings.label = location.settings.labelFunction(dataMap.dataMap, dataMap.dsDataMap, location.dsIndex);
  218 + } catch (e) {
  219 + location.settings.label = null;
  220 + }
  221 + if (location.settings.label) {
  222 + var datasources = tbMap.subscription.datasources;
  223 + location.settings.label = tbMap.utils.createLabelFromDatasource(datasources[location.dsIndex], location.settings.label);
  224 + location.settings.labelReplaceInfo = processPattern(location.settings.label, datasources, location.dsIndex);
  225 + location.settings.labelText = location.settings.label;
  226 + }
  227 + }
  228 + if (location.settings.labelReplaceInfo.variables.length) {
  229 + location.settings.labelText = fillPattern(location.settings.label,
  230 + location.settings.labelReplaceInfo, tbMap.subscription.data);
  231 + }
217 232 tbMap.map.updateMarkerLabel(location.marker, location.settings);
218 233 }
219 234 }
220 235
  236 +
221 237 function calculateLocationColor(location, dataMap) {
222 238 if (location.settings.useColorFunction && location.settings.colorFunction) {
223 239 var color;
... ... @@ -267,7 +283,7 @@ export default class TbMapWidgetV2 {
267 283 }
268 284
269 285 function updateLocationStyle(location, dataMap) {
270   - updateLocationLabel(location);
  286 + updateLocationLabel(location, dataMap);
271 287 var color = calculateLocationColor(location, dataMap);
272 288 var image = calculateLocationMarkerImage(location, dataMap);
273 289 updateLocationColor(location, color, image);
... ... @@ -281,7 +297,7 @@ export default class TbMapWidgetV2 {
281 297 if (image && (!location.settings.currentImage || !angular.equals(location.settings.currentImage, image))) {
282 298 location.settings.currentImage = image;
283 299 }
284   - location.marker = tbMap.map.createMarker(markerLocation, location.settings,
  300 + location.marker = tbMap.map.createMarker(markerLocation, location.dsIndex, location.settings,
285 301 function (event) {
286 302 tbMap.callbacks.onLocationClick(location);
287 303 locationRowClick(event, location);
... ... @@ -401,25 +417,11 @@ export default class TbMapWidgetV2 {
401 417 settings: angular.copy(tbMap.locationSettings)
402 418 };
403 419 if (location.settings.showLabel) {
404   - if (location.settings.useLabelFunction && location.settings.labelFunction) {
405   - try {
406   - location.settings.label = location.settings.labelFunction(dataMap.dataMap, dataMap.dsDataMap, location.dsIndex);
407   - } catch (e) {
408   - location.settings.label = null;
409   - }
410   - }
411 420 location.settings.label = tbMap.utils.createLabelFromDatasource(currentDatasource, location.settings.label);
412 421 location.settings.labelReplaceInfo = processPattern(location.settings.label, datasources, currentDatasourceIndex);
413 422 location.settings.labelText = location.settings.label;
414 423 }
415 424 if (location.settings.displayTooltip) {
416   - if (location.settings.useTooltipFunction && location.settings.tooltipFunction) {
417   - try {
418   - location.settings.tooltipPattern = location.settings.tooltipFunction(dataMap.dataMap, dataMap.dsDataMap, location.dsIndex);
419   - } catch (e) {
420   - location.settings.tooltipPattern = null;
421   - }
422   - }
423 425 location.settings.tooltipPattern = tbMap.utils.createLabelFromDatasource(currentDatasource, location.settings.tooltipPattern);
424 426 location.settings.tooltipReplaceInfo = processPattern(location.settings.tooltipPattern, datasources, currentDatasourceIndex);
425 427 }
... ... @@ -457,6 +459,25 @@ export default class TbMapWidgetV2 {
457 459 }
458 460 }
459 461
  462 + function createTooltipContent(tooltip, data, datasources) {
  463 + var content;
  464 + var settings = tooltip.locationSettings;
  465 + if (settings.useTooltipFunction && settings.tooltipFunction) {
  466 + var dataMap = toLabelValueMap(data, datasources);
  467 + try {
  468 + settings.tooltipPattern = settings.tooltipFunction(dataMap.dataMap, dataMap.dsDataMap, tooltip.dsIndex);
  469 + } catch (e) {
  470 + settings.tooltipPattern = null;
  471 + }
  472 + if (settings.tooltipPattern) {
  473 + settings.tooltipPattern = tbMap.utils.createLabelFromDatasource(datasources[tooltip.dsIndex], settings.tooltipPattern);
  474 + settings.tooltipReplaceInfo = processPattern(settings.tooltipPattern, datasources, tooltip.dsIndex);
  475 + }
  476 + }
  477 + content = fillPattern(settings.tooltipPattern, settings.tooltipReplaceInfo, data);
  478 + return fillPatternWithActions(content, 'onTooltipAction', tooltip.markerArgs);
  479 + }
  480 +
460 481 if (this.map && this.map.inited() && this.subscription) {
461 482 if (this.subscription.data) {
462 483 if (!this.locations) {
... ... @@ -465,10 +486,9 @@ export default class TbMapWidgetV2 {
465 486 updateLocations(this.subscription.data, this.subscription.datasources);
466 487 }
467 488 var tooltips = this.map.getTooltips();
468   - for (var t=0; t < tooltips.length; t++) {
  489 + for (var t = 0; t < tooltips.length; t++) {
469 490 var tooltip = tooltips[t];
470   - var text = fillPattern(tooltip.pattern, tooltip.replaceInfo, this.subscription.data);
471   - text = fillPatternWithActions(text, 'onTooltipAction', tooltip.markerArgs);
  491 + var text = createTooltipContent(tooltip, this.subscription.data, this.subscription.datasources);
472 492 tooltip.popup.setContent(text);
473 493 }
474 494 }
... ...
... ... @@ -126,7 +126,7 @@ export default class TbOpenStreetMap {
126 126 onMarkerIconReady(iconInfo);
127 127 }
128 128
129   - createMarker(location, settings, onClickListener, markerArgs) {
  129 + createMarker(location, dsIndex, settings, onClickListener, markerArgs) {
130 130 var marker = L.marker(location, {});
131 131 var opMap = this;
132 132 this.createMarkerIcon(marker, settings, (iconInfo) => {
... ... @@ -140,7 +140,7 @@ export default class TbOpenStreetMap {
140 140 });
141 141
142 142 if (settings.displayTooltip) {
143   - this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo, settings.autocloseTooltip, markerArgs);
  143 + this.createTooltip(marker, dsIndex, settings, markerArgs);
144 144 }
145 145
146 146 if (onClickListener) {
... ... @@ -154,15 +154,15 @@ export default class TbOpenStreetMap {
154 154 this.map.removeLayer(marker);
155 155 }
156 156
157   - createTooltip(marker, pattern, replaceInfo, autoClose, markerArgs) {
  157 + createTooltip(marker, dsIndex, settings, markerArgs) {
158 158 var popup = L.popup();
159 159 popup.setContent('');
160   - marker.bindPopup(popup, {autoClose: autoClose, closeOnClick: false});
  160 + marker.bindPopup(popup, {autoClose: settings.autocloseTooltip, closeOnClick: false});
161 161 this.tooltips.push( {
162 162 markerArgs: markerArgs,
163 163 popup: popup,
164   - pattern: pattern,
165   - replaceInfo: replaceInfo
  164 + locationSettings: settings,
  165 + dsIndex: dsIndex
166 166 });
167 167 }
168 168
... ...
... ... @@ -224,7 +224,7 @@ export default class TbTencentMap {
224 224 /* eslint-enable no-undef */
225 225
226 226 /* eslint-disable no-undef */
227   - createMarker(location, settings, onClickListener, markerArgs) {
  227 + createMarker(location, dsIndex, settings, onClickListener, markerArgs) {
228 228 var marker = new qq.maps.Marker({
229 229 position: location
230 230 });
... ... @@ -247,7 +247,7 @@ export default class TbTencentMap {
247 247 });
248 248
249 249 if (settings.displayTooltip) {
250   - this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo, settings.autocloseTooltip, markerArgs);
  250 + this.createTooltip(marker, dsIndex, settings, markerArgs);
251 251 }
252 252
253 253 if (onClickListener) {
... ... @@ -268,13 +268,13 @@ export default class TbTencentMap {
268 268 /* eslint-enable no-undef */
269 269
270 270 /* eslint-disable no-undef */
271   - createTooltip(marker, pattern, replaceInfo, autoClose, markerArgs) {
  271 + createTooltip(marker, dsIndex, settings, markerArgs) {
272 272 var popup = new qq.maps.InfoWindow({
273 273 map :this.map
274 274 });
275 275 var map = this;
276 276 qq.maps.event.addListener(marker, 'click', function() {
277   - if (autoClose) {
  277 + if (settings.autocloseTooltip) {
278 278 map.tooltips.forEach((tooltip) => {
279 279 tooltip.popup.close();
280 280 });
... ... @@ -285,8 +285,8 @@ export default class TbTencentMap {
285 285 this.tooltips.push( {
286 286 markerArgs: markerArgs,
287 287 popup: popup,
288   - pattern: pattern,
289   - replaceInfo: replaceInfo
  288 + locationSettings: settings,
  289 + dsIndex: dsIndex
290 290 });
291 291 }
292 292 /* eslint-enable no-undef */
... ...