React VectorMap API

The VectorMap is a widget that visualizes geographical locations. This widget represents a geographical map that contains areas and markers. Areas embody continents and countries. Markers flag specific points on the map, for example, towns, cities or capitals.

import VectorMap from "devextreme-react/vector-map"
Type: VectorMapTypes.default

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the VectorMap widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
$(function() {
    $("#vectorMap").dxVectorMap({
        layers: [{
            type: 'area',
            dataSource: DevExpress.viz.map.sources.world,
            label: {
                enabled: true,
                dataField: 'name'
            }
        }]
    });
});
<div id="vectorMap"></div>
Angular
HTML
TypeScript
<dx-vector-map>
    <dxi-layer
        type="area"
        [dataSource]="worldMap">
        <dxo-label
            [enabled]="true"
            dataField="name">
        </dxo-label>
    </dxi-layer>
</dx-vector-map>
import { DxVectorMapModule } from "devextreme-angular";
import * as maps from "vectormap-data/world.js";
// ...
export class AppComponent {
    worldMap: any = maps.world;
}
@NgModule({
    imports: [
        // ...
        DxVectorMapModule
    ],
    // ...
})
AngularJS
HTML
<div dx-vector-map="{
    layers: [{
        type: 'area',
        dataSource: DevExpress.viz.map.sources.world,
        label: {
            enabled: true,
            dataField: 'name'
        }
    }]
}"></div>
Knockout
HTML
<div data-bind="dxVectorMap: {
    layers: [{
        type: 'area',
        dataSource: DevExpress.viz.map.sources.world,
        label: {
            enabled: true,
            dataField: 'name'
        }
    }],
}"></div>
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().VectorMap()
    .Layers(layers => {
        layers.Add()
            .DataSource(new JS("DevExpress.viz.map.sources.world"))
            .Label(l => l
                .Enabled(true)
                .DataField("name")
            );
    })
)
@(Html.DevExtreme().VectorMap() _
    .Layers(Sub(layers)
        layers.Add() _
            .DataSource(New JS("DevExpress.viz.map.sources.world")) _
            .Label(Sub(l)
                l.Enabled(true) _
                    .DataField("name")
            End Sub)
    End Sub)
)

View Demo Watch Video

See Also

Configuration

An object that specifies configuration options for the widget.

Name Description
background

Specifies the options for the map background.

bounds

Specifies the positioning of a map in geographical coordinates.

center

Specifies the geographical coordinates of the center for a map.

controlBar

Specifies the options of the control bar.

disabled

Specifies whether the widget responds to the user interaction.

elementAttr

Specifies the attributes to be attached to the widget's root element.

export

Configures the exporting and printing features.

layers

Specifies options for VectorMap widget layers.

legends

Configures map legends.

loadingIndicator

Configures the loading indicator.

maxZoomFactor

Specifies a map's maximum zoom factor.

onCenterChanged

A function that is executed each time the center coordinates are changed.

onClick

A function that is executed when any location on the map is clicked or tapped.

onDisposing

A function that is executed before the widget is disposed of.

onDrawn

A function that is executed when the widget's rendering has finished.

onExported

A function that is executed after the widget is exported.

onExporting

A function that is executed before the widget is exported.

onFileSaving

A function that is executed before a file with exported widget is saved to the user's local storage.

onIncidentOccurred

A function that is executed when an error or warning occurs.

onInitialized

A function that is executed only once, after the widget is initialized.

onOptionChanged

A function that is executed after a widget option is changed.

onSelectionChanged

A function that is executed when a layer element is selected or the selection is canceled.

onTooltipHidden

A function that is executed when a tooltip becomes hidden.

onTooltipShown

A function that is executed when a tooltip appears.

onZoomFactorChanged

A function that is executed each time the zoom factor is changed.

panningEnabled

Disables the panning capability.

pathModified

Notifies the widget that it is embedded into an HTML page that uses a tag modifying the path.

projection

Specifies the map projection.

redrawOnResize

Specifies whether to redraw the widget when the size of the parent browser window changes or a mobile device rotates.

rtlEnabled

Switches the widget to a right-to-left representation.

size

Specifies the widget's size in pixels.

theme

Sets the name of the theme the widget uses.

title

Configures the widget's title.

tooltip

Configures tooltips.

touchEnabled

Specifies whether the map should respond to touch gestures.

wheelEnabled

Specifies whether or not the map should respond when a user rolls the mouse wheel.

zoomFactor

Specifies a number that is used to zoom a map initially.

zoomingEnabled

Disables the zooming capability.

Methods

This section describes the methods that can be used in code to manipulate objects related to the widget.

Name Description
beginUpdate()

Prevents the widget from refreshing until the endUpdate() method is called.

center()

Gets the current map center coordinates.

center(centerCoordinates)

Sets the map center coordinates.

clearSelection()

Deselects all the selected area and markers on a map at once. The areas and markers are displayed in their initial style after.

convertCoordinates(x, y)

Converts client area coordinates into map coordinates.

dispose()

Disposes of all the resources allocated to the VectorMap instance.

element()

Gets the root widget element.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

exportTo(fileName, format)

Exports the widget.

getInstance(element)

Gets the instance of a widget found using its DOM node.

getLayerByIndex(index)

Gets a layer with a specific index.

getLayerByName(name)

Gets a layer with a specific name.

getLayers()

Gets all layers.

getSize()

Gets the current widget size.

hideLoadingIndicator()

Hides the loading indicator.

instance()

Gets the widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from a single event.

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

on(eventName, eventHandler)

Subscribes to an event.

on(events)

Subscribes to events.

option()

Gets all widget options.

option(optionName)

Gets the value of a single option.

option(optionName, optionValue)

Updates the value of a single option.

option(options)

Updates the values of several options.

print()

Opens the browser's print window.

render()

Redraws the widget.

showLoadingIndicator()

Shows the loading indicator.

svg()

Gets the widget's SVG markup.

viewport()

Gets the current map viewport coordinates.

viewport(viewportCoordinates)

Sets the map viewport coordinates.

zoomFactor()

Gets the current zoom factor value.

zoomFactor(zoomFactor)

Sets the zoom factor value.

Events

This section describes events fired by this widget.

Name Description
centerChanged

Raised each time the center coordinates are changed.

click

Raised when any location on the map is clicked or tapped.

disposing

Raised before the widget is disposed of.

drawn

Raised when the widget's rendering has finished.

exported

Raised after the widget is exported.

exporting

Raised before the widget is exported.

fileSaving

Raised before a file with exported widget is saved to the user's local storage.

incidentOccurred

Raised when an error or warning occurs.

initialized

Raised only once, after the widget is initialized.

optionChanged

Raised after a widget option is changed.

selectionChanged

Raised when a layer element is selected or the selection is canceled.

tooltipHidden

Raised when a tooltip becomes hidden.

tooltipShown

Raised when a tooltip appears.

zoomFactorChanged

Raised each time the zoom factor is changed.

See Also

Map Elements

This section describes vector map elements.