question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dx-vector-map SVG elements don't get refreshed when new data is loaded

See original GitHub issue

devexteme version: 18.1.4 devextreme-angular version: 18.1.4 [ x] bug Report [x ] support inquiry

Hi, I’m using Angular version of dxvectormaps and couldn’t get the markers to redraw on vector maps when the data is changed. The new data is getting drawn along with previous data. When I look at the svg elements through browser developer options I see that there are bubble markers for both previous and new data. How to get the map to clear the old ones and re-draw new ones as per new data? Initially the map draws bubbles for the sum of all years. Then ideally based on user input it should show data for the selected year only, replacing the previous bubbles on the map. Following is the sample code

Angular .ts component file: mapComponent.ts


        import {Component, OnInit, ViewChild} from '@angular/core';
        import {Feature, FeatureCollection} from '../../../../models/util_classes.model';
        import {MapData1Service} from '../../../../data/map-data1.service';
        import * as maps from 'devextreme/dist/js/vectormap-data/world.js';
        import {DxVectorMapComponent} from 'devextreme-angular';

export class mapComponent implements OnInit {
  @ViewChild('myVectorMap') bubbleMap: DxVectorMapComponent;

  public mapMarkerData: FeatureCollection;
  public slicedData: FeatureCollection;

  constructor(public mapDataService1: MapData1Service) {
    this.getMapData();
  }

//Initially get the data from service 
getMapData(){
    this.mapDataService1.geoMarkersEmit.subscribe(
      (mapData) => this.extractGeoMarkers(mapData));
  }

//This is invoked when a user clicks a button to get a slice of the data used above
  getSlicedMapData(){
    this.mapDataService1.timeDataSetEmit.subscribe(
      (mapData) => this.extractMasterDataSet(mapData) );
  }

//Draws the bubbles in the map initially
  extractGeoMarkers(mData: any){
    this.mapMarkerData = mData;
    this.bubbleMap.instance.option('layers[1].dataSource', this.mapMarkerData);
    this.bubbleMap.instance.option('layers[1].color', '#0f74a8');
  }

//When user clicks a button slice of the data is loaded into a new FeatureCollection object and assigns
// it to the dataSource of the datalayer. But this draws both bubbles from previous dataset as well as the 
// newly assigned dataset 
slicedGeoMarkers(mData: any){
    let markerLayer = this.bubbleMap.instance.getLayerByName('bubbles');

    this.slicedData = null;
    this.slicedData = mData;


   //this is testing code 
   //this.bubbleMap.instance.getLayerByName('bubbles').getDataSource().dispose();

    this.bubbleMap.instance.option('layers[1].dataSource', this.slicedData);
    this.bubbleMap.instance.option('layers[1].color', '#ffd70b');

    this.bubbleMap.instance.render();

     //this is testing code 
    //this.bubbleMap.instance.getLayerByName('bubbles').getDataSource().load();
    //this.bubbleMap.instance.getLayerByName('bubbles').getDataSource().reload();

    
    

}

HTML component: mapComponent.html //here [dataSource] and [color] are not set in <dxi-layer #myDataLayer> tags as it’s set in the typescript code above.

<dx-vector-map
  #myVectorMap
  id="vector-map"
  size="{height:300, width:400}"
  [bounds]="[-144, 80, 170, -60]"
  [center]="{ lat: 40.749825, lng: -73.987963 }">
  <dxo-control-bar
    [enabled]="true"
    [opacity]="0.01"
    [color]="'#D8BFD8'"
    [borderColor]="'#6d6b77'">
  </dxo-control-bar>
  <dxo-tooltip
    [enabled]="true"
    [customizeTooltip]="customizeTooltip">
  </dxo-tooltip>
  <dxo-background
    [borderColor]="'#ffffff'">
  </dxo-background>
  <dxi-layer
    [dataSource]="worldMap"
    [hoverEnabled]="true"
    name="areas"
    [color]="'#d3dfd4'">
    <dxo-label
      [enabled]="true"
      dataField="name"
      [visible]="true">32
    </dxo-label>
  </dxi-layer>
  <dxi-layer #myDataLayer
    [minSize]="2"
    [maxSize]="20"
    [sizeGroups]="[0, 999, 99999, 99999999, 999999999999]"
    name="bubbles"
    elementType="bubble"
    [hoveredColor]="'rgba(255, 194, 21, 0.8)'"
    [hoveredBorderColor]="'#341453'"
    dataField="value">
  </dxi-layer>
  <dxi-legend markerShape="circle" [customizeText]="customizeText" verticalAlignment="top" size="10">
    <dxo-source layer="bubbles" grouping="size"></dxo-source>
  </dxi-legend>
</dx-vector-map>

Please help me how to get the map to show the new bubbles when the dataset is getting changed. Please answer in Angular5 Typescript as I’m not familiar with JS or JQurey.

Many thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hakimiocommented, Jul 26, 2018

Have you tried to simply create third variable bound to “dataSource” and then set it to mapMarkerData or slicedData based on your needs? Also, do you really need to manually call render()?

1reaction
hakimiocommented, Jul 24, 2018

Try to bind second layer dataSource to a variable defined in your component.ts. And when data changes make sure dataSource instance changes as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refresh feature with Openlayers 3 - Stack Overflow
The Add Feature function triggers a change event (for the whole source, but this shouldn't update already drawed features). ol.source.Vector.
Read more >
How to handle SVG elements in Selenium - YouTube
In this video, I have explained how to handle SVG elements in Selenium.Learn:-- What is SVG -- SVG different elements like Circle, Line, ......
Read more >
Libraries to render vector-based maps in the browser
The only library I found was polymaps - but still I would need a server or service which serves the vector SVG data...
Read more >
Azure Maps Web SDK best practices - Microsoft Learn
Reduce the number of canvas refreshes due to data updates​​ There are several ways data in a DataSource class can be added or...
Read more >
Accessible SVGs | CSS-Tricks
Scalable Vector Graphic (SVG) is emerging as the preferred graphic ... Before getting started with accessible SVGs, a few quick things to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found