dx-vector-map SVG elements don't get refreshed when new data is loaded
See original GitHub issuedevexteme 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:
- Created 5 years ago
- Comments:5
Top GitHub Comments
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()?
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.