VectorMap Methods

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

beginUpdate()

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

The beginUpdate and endUpdate methods allow you to apply several modifications to the widget at once. After the beginUpdate method is called, the widget does not rerender itself until the endUpdate method is called. The usage of these methods prevents excessive widget updating when changing multiple widget settings at once.

NOTE: It is recommended that you do not perform any actions on a widget within the updating transaction other than changing widget options.

center()

Gets the current coordinates of the map center.

Return Value: Array
The current coordinates of the map center.

This method returns the center coordinates as an array of two values in the [longitude, latitude] format.

center(centerCoordinates)

Sets the coordinates of the map center.

Parameters:
centerCoordinates: Array
New coordinates for the map center.

To change the coordinates of the map center, pass an array of two values in the [longitude, latitude] form as the argument to the center(centerCoordinates) method.

In addition, you can get the current coordinates of the map center by calling the same method without arguments. Moreover, you can perform specific actions when the center coordinates are changed. For this purpose, implement a callback function and assign it to the centerChanged option.

clearAreaSelection()

Deselects all the selected areas on a map. The areas are displayed in their initial style after.

To select/deselect a certain area, use the selected(state) method of an area.

Show Example:
jQuery

In this example, you can select several areas on the map by clicking them. To clear the selection, click the Deselect the Areas button under the map. This button calls the clearAreaSelection() method of the widget instance, which deselects all the map areas.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="clearAreaSelectionButton" value="Deselect the Areas" />
</div>
var i = 0;

$(function () {
    $('#mapContainer').dxVectorMap({
        areaSettings: {
            palette: 'Pastel',
            paletteSize: 10,
            customize: function () {
                return { paletteIndex: i++ % 10 };
            },
            click: function () {
                this.selected(true);
            },
            selectedBorderColor: 'white',
            selectedColor: 'powderblue',
            selectionMode: 'multiple'
        },
        mapData: '/Content/data/vectorMap-sources/world.txt'
    });

    $('#clearAreaSelectionButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.clearAreaSelection();
    });
});

clearMarkerSelection()

Deselects all the selected markers on a map. The markers are displayed in their initial style after.

To select/deselect a certain marker, use the selected(state) method of a marker.

Show Example:
jQuery

In this example, you can select several markers on the map by clicking. To clear the selection, click the Deselect the Markers button under the map. This button calls the clearMarkerSelection() method of the widget instance, which deselects all the map markers.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="clearMarkerSelectionButton" value="Deselect the Markers" />
</div>
var i = 0;

var markers = [
    {
        coordinates: [-121.2808, 38.3320],
        text: 'Sacramento'
    }, {
        coordinates: [-97.75, 30.25],
        text: 'Austin'
    }, {
        coordinates: [-73.7572, 42.6525],
        text: 'Albany'
    }, {
        coordinates: [-84.2533, 30.455],
        text: 'Tallahassee'
    }, {
        coordinates: [-89.65, 39.783],
        text: 'Springfield'
    }
];

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/usa.txt',
        bounds: [-135, 60, -65, 20],
        zoomFactor: 1.25,
        areaSettings: {
            palette: 'Bright',
            paletteSize: 10,
            customize: function () {
                return { paletteIndex: i++ % 10 };
            },
            hoverEnabled: false
        },
        markerSettings: {
            click: function () {
                this.selected(true);
            },
            selectedColor: 'powderblue',
            selectionMode: 'multiple'
        },
        markers: markers
    });

    $('#clearMarkerSelectionButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.clearMarkerSelection();
    });
});

clearSelection()

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

Show Example:
jQuery

In this example, you can select several areas and markers on the map by clicking. To clear the selection, click the Deselect the Map Elements button under the map. This button calls the clearSelection() method of the widget instance, which deselects all the map areas and markers.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="clearSelectionButton" value="Deselect the Map Elements" />
</div>
var i = 0;

var markers = [
    {
        coordinates: [-121.2808, 38.3320],
        text: 'Sacramento'
    }, {
        coordinates: [-97.75, 30.25],
        text: 'Austin'
    }, {
        coordinates: [-73.7572, 42.6525],
        text: 'Albany'
    }, {
        coordinates: [-84.2533, 30.455],
        text: 'Tallahassee'
    }, {
        coordinates: [-89.65, 39.783],
        text: 'Springfield'
    }
];

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/usa.txt',
        markers: markers,
        bounds: [-135, 60, -65, 20],
        zoomFactor: 1.25,
        areaSettings: {
            palette: 'Ocean',
            paletteSize: 10,
            customize: function () {
                return { paletteIndex: i++ % 10 };
            },
            click: function () {
                this.selected(true);
            },
            selectedBorderColor: 'white',
            selectedColor: 'powderblue',
            selectionMode: 'multiple'
        },
        markerSettings: {
            click: function () {
                this.selected(true);
            },
            selectedColor: 'deepskyblue',
            selectionMode: 'multiple'
        }
    });

    $('#clearSelectionButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.clearSelection();
    });
});

convertCoordinates(x, y)

Converts client area coordinates into map coordinates.

Parameters:
x: Number
An X coordinate of the client area.
y: Number
An Y coordinate of the client area.
Return Value: Array
Map coordinates.

endUpdate()

Enables the widget to refresh after the beginUpdate method call.

The beginUpdate and endUpdate methods allow you to apply several modifications to the widget at once. After the beginUpdate method is called, the widget does not rerender itself until the endUpdate method is called. The usage of these methods prevents excessive widget updating when changing multiple widget settings at once.

NOTE: It is recommended that you do not perform any actions on a widget within the updating transaction other than changing widget options.

getAreas()

Returns an array with all the map areas.

Return Value: Array
An array of the map areas.

Discover which methods and fields of a map area you can use within the Area class description.

Show Example:
jQuery

In this example, click the button under the map to select an area. The area to be selected is chosen randomly from a pool of all the map areas. The array of the map areas is obtained using the getAreas() method.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="selectRandomAreaButton" value="Select a Random Area" />
</div>
var i = 0;

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/usa.txt',
        bounds: [-135, 60, -65, 20],
        zoomFactor: 1.25,
        areaSettings: {
            palette: 'Soft',
            paletteSize: 10,
            customize: function () {
                return { paletteIndex: i++ % 10 };
            },
            selectedBorderColor: 'white',
            selectedColor: 'red'
        }
    });

    $('#selectRandomAreaButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        var areas = map.getAreas();
        var random = Math.floor(Math.random() * areas.length);
        areas[random].selected(true);
    });
});

getMarkers()

Returns an array with all the map markers.

Return Value: Array
An array of the map markers.

Discover which methods and fields of a map marker you can use within the Marker class description.

Show Example:
jQuery

In this example, click the button under the map to select a marker. The marker to be selected is chosen randomly from a pool of all the map markers. The array of the map markers is obtained using the getMarkers() method.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="selectRandomMarkerButton" value="Select a Random Marker" />
</div>
var i = 0;

var markers = [
    {
        coordinates: [-121.2808, 38.3320],
        text: 'Sacramento'
    }, {
        coordinates: [-97.75, 30.25],
        text: 'Austin'
    }, {
        coordinates: [-73.7572, 42.6525],
        text: 'Albany'
    }, {
        coordinates: [-84.2533, 30.455],
        text: 'Tallahassee'
    }, {
        coordinates: [-89.65, 39.783],
        text: 'Springfield'
    }
];

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/usa.txt',
        markers: markers,
        bounds: [-135, 60, -65, 20],
        zoomFactor: 1.25,
        areaSettings: {
            palette: 'Soft',
            paletteSize: 10,
            customize: function () {
                return { paletteIndex: i++ % 10 };
            }
        },
        markerSettings: {
            selectedColor: 'red',
        }
    });

    $('#selectRandomMarkerButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        var markers = map.getMarkers();
        var random = Math.floor(Math.random() * markers.length);
        markers[random].selected(true);
    });
});

hideLoadingIndicator()

Conceals the loading indicator.

Although the loading indicator hides automatically when a map is ready, you can hide it from code at the required time using the hideLoadingIndicator() method.

To show the loading indicator, invoke the showLoadingIndicator() method.

Show Example:
jQuery

In this example, the map options are assigned five seconds after the example is loaded. You can show/hide the loading indicator using the buttons under the map. Note that the loading indicator can be displayed or concealed manually at any time regardless of whether the map is ready or not.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="showLoadingIndicatorButton" value="showLoadingIndicator()" />
    <input type="button" id="hideLoadingIndicatorButton" value="hideLoadingIndicator()" />
</div>
var i = 0;

var mapOptions = {
    areaSettings: {
        palette: 'Bright',
        paletteSize: 10,
        customize: function () {
            return { paletteIndex: i++ % 10 };
        }
    },
    tooltip: {
        enabled: true,
        customizeTooltip: function () {
            return {
                text: this.attribute('name')
            };
        }
    },
    mapData: '/Content/data/vectorMap-sources/world.txt'
};

$(function () {
    $("#mapContainer").dxVectorMap().dxVectorMap('instance').showLoadingIndicator();

    $('#showLoadingIndicatorButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.showLoadingIndicator();
    });

    $('#hideLoadingIndicatorButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.hideLoadingIndicator();
    });
});

var configureMap = function () {
    var map = $("#mapContainer").dxVectorMap('instance');
    map.option(mapOptions);
};

setTimeout(configureMap, 5000);

instance()

Returns an instance of the widget.

Return Value: Object
An instance of the widget.

Use this method to access the widget.

Show Example:
jQuery

In the following example, the instance() method is used to get access to the map options. This method is called not like the other methods. To call the instance() method, the following construction is used.

<!--JavaScript -->$('#mapContainer').dxVectorMap('instance')

Use the drop-down menu below to choose which palette to use for coloring the map.

<div id="mapContainer" style="height:500px; max-width:800px; margin: 0 auto"></div>
<div id="selectContainer" style="height:20px;max-width:350px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    Choose a Palette:
    <select id="dropdownListSelector">
        <option value="Default">Default</option>
        <option value="Soft Pastel">Soft Pastel</option>
        <option value="Harmony Light">Harmony Light</option>
        <option value="Pastel">Pastel</option>
        <option value="Bright">Bright</option>
        <option value="Soft">Soft</option>
        <option value="Ocean">Ocean</option>
        <option value="Vintage">Vintage</option>
        <option value="Violet">Violet</option>
    </select>
</div>
var i = 0;

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt',
        areaSettings: {
            palette: 'Default',
            paletteSize: 9,
            customize: function () {
                return {
                    paletteIndex: i++ % 9
                };
            }
        }
    });

    $('#dropdownListSelector').change(function () {
        var vectorMap = $('#mapContainer').dxVectorMap('instance');
        vectorMap.option({
            areaSettings: {
                palette: this.value
            }
        });
    });
});

option()

Returns the object representing explicitly specified widget options.

Return Value: Object
Explicitly specified widget options.

Use this method to obtain the object of explicitly specified widget options. To change the value of one widget option, call the option(optionName, optionValue) method. To change values of several options, call the option(options) method.

Show Example:
jQuery

In this example, the option() method is used to obtain the value of the tooltip | enabled option and display it under the map. To change this value, use the check box below.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div id="checkboxContainer" style="height:35px;max-width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="checkbox" id="enableTooltipCheckbox" checked> Enable Tooltip <br />
    <span id="replySpan" />
</div>
$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt',
        tooltip: {
            enabled: true,
            customizeTooltip: function () {
                return {
                    text: this.attribute('name')
                };
            }
        }
    });

    $('#enableTooltipCheckbox').change(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.option({
            tooltip: {
                enabled: this.checked
            }
        });
        $('#replySpan').html('tooltip | enabled: ' + map.option().tooltip.enabled);
    });
});

option(optionName)

Gets the value of an explicitly specified widget option.

Parameters:
optionName: String
The name of the option to get.
Return Value: any
The value of the specified option.

To get the value of a configuration option, specify the path to the field representing this option in the configuration object. For example, pass the "tooltip.enabled" value as the optionName parameter to get the value of the tooltip | enabled option.

NOTE: If the requested option was not specified explicitly, this method returns undefined.

Show Example:
jQuery

In this example, the option() method is used to obtain the value of the tooltip | enabled option and display it under the map. To change this value, use the check box below.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div id="checkboxContainer" style="height:35px;max-width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="checkbox" id="enableTooltipCheckbox" checked> Enable Tooltip <br />
    <span id="replySpan" />
</div>
$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt',
        tooltip: {
            enabled: true,
            customizeTooltip: function () {
                return {
                    text: this.attribute('name')
                };
            }
        }
    });

    $('#enableTooltipCheckbox').change(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.option({
            tooltip: {
                enabled: this.checked
            }
        });
        $('#replySpan').html('tooltip | enabled: ' + map.option('tooltip.enabled'));
    });
});

option(optionName, optionValue)

Sets a value to the specified configuration option of the widget.

Parameters:
optionName: String
The name of the required option.
optionValue: any
The value to be assigned to the required option.

To set a value to the configuration option, specify the path to the field representing this option in the configuration object. For example, to set the tooltip | enabled option to true, pass the "tooltip.enabled" value as the optionName parameter and the "true" value as the optionValue parameter.

Show Example:
jQuery

In this example, the option(optionName, optionValue) method is used to set the value of the tooltip | enabled option at runtime. To change this value, use the check box below.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div id="checkboxContainer" style="height:30px;max-width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="checkbox" id="enableTooltipCheckbox" checked> Enable Tooltip
</div>
$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt',
        tooltip: {
            enabled: true,
            customizeTooltip: function () {
                return {
                    text: this.attribute('name')
                };
            }
        }
    });

    $('#enableTooltipCheckbox').change(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.option('tooltip.enabled', this.checked);
    });
});

option(options)

Sets one or more widget options.

Parameters:
options: Object
An object containing required configuration options.

To set one or more widget options, pass the object that contains fields representing these options as the options parameter.

This method is useful if you need to configure several widget options at once.

Show Example:
jQuery

In this example, the option(options) method is used to set the value of the tooltip | enabled and controlBar | eanbled options at runtime. To change these values, use the check box below.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div id="checkboxContainer" style="height:30px;max-width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="checkbox" id="enableControlBarAndTooltipCheckbox" checked> Enable the Control Bar and Tooltip
</div>
$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt',
        tooltip: {
            enabled: true,
            customizeTooltip: function () {
                return {
                    text: this.attribute('name')
                };
            }
        }
    });

    $('#enableControlBarAndTooltipCheckbox').change(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.option({
            controlBar: {
                enabled: this.checked
            },
            tooltip: {
                enabled: this.checked
            }
        });
    });
});

render()

Redraws a widget.

By default, a widget rerenders when the size of the parent window is changed. But there may be situations when a widget should be rerendered manually, e.g., when the size of the widget container is changed. To make a widget rerender, call the render() method.

Show Example:
jQuery

Click the 'Change the container size' button to switch between two sizes of the map container. You can set the size either to 500x800 or 400x700 pixels. The render() method is used to redraw the map after the container size changes.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div id="controlContainer" style="height:20px;max-width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="changeContainerSizeButton" value="Change the container size">
</div>
$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/world.txt'
    });

    $('#changeContainerSizeButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        if ($('#mapContainer').height() > 400 || $('#mapContainer').width() > 700) {
            $('#mapContainer').height(400);
            $('#mapContainer').width(700);
        } else {
            $('#mapContainer').height(500);
            $('#mapContainer').width(800);
        }
        map.render();
    });
});

showLoadingIndicator()

Displays the loading indicator.

The loading indicator does not appear automatically. In order to display it, the showLoadingIndicator() method should be invoked.

To hide the loading indicator from code, use the hideLoadingIndicator() method.

Show Example:
jQuery

In this example, the map options are assigned five seconds after the example is loaded. You can show/hide the loading indicator using the buttons under the map. Note that the loading indicator can be displayed or concealed manually at any time regardless of whether the map is ready or not.

<div id="mapContainer" style="height:500px;max-width:800px;margin:0px auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="showLoadingIndicatorButton" value="showLoadingIndicator()" />
    <input type="button" id="hideLoadingIndicatorButton" value="hideLoadingIndicator()" />
</div>
var i = 0;

var mapOptions = {
    areaSettings: {
        palette: 'Bright',
        paletteSize: 10,
        customize: function () {
            return { paletteIndex: i++ % 10 };
        }
    },
    tooltip: {
        enabled: true,
        customizeTooltip: function () {
            return {
                text: this.attribute('name')
            };
        }
    },
    mapData: '/Content/data/vectorMap-sources/world.txt'
};

$(function () {
    $("#mapContainer").dxVectorMap().dxVectorMap('instance').showLoadingIndicator();

    $('#showLoadingIndicatorButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.showLoadingIndicator();
    });

    $('#hideLoadingIndicatorButton').click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        map.hideLoadingIndicator();
    });
});

var configureMap = function () {
    var map = $("#mapContainer").dxVectorMap('instance');
    map.option(mapOptions);
};

setTimeout(configureMap, 5000);

svg()

Returns the widget's SVG markup.

Return Value: String
The widget's SVG markup.

NOTE: This method does not support Internet Explorer 8.

Show Example:
jQuery

Click the Get SVG below the map and the SVG copy of this map will appear.

<div style="display:inline-block">
    <div id="mapContainer" style="height:300px;width:450px;margin:5px auto;display:inline-block"></div>
    <div id="widgetSVG" style="height:300px;width:450px;margin: 5px auto;display:inline-block"></div>
</div>
<div style="height:30px; max-width:900px;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center;">
    <input type='button' id='getSVG' value='Get SVG' />
</div>
var i = 0;

$(function () {
    $('#mapContainer').dxVectorMap({
        mapData: '/Content/data/vectorMap-sources/usa.txt',
        bounds: [-135, 60, -65, 20],
        zoomFactor: 1.25,
        areaSettings: {
            palette: 'Bright',
            paletteSize: 5,
            customize: function () {
                return {
                    paletteIndex: i++ % 5
                };
            }
        },
        controlBar: { enabled: false }
    });

    $("#getSVG").click(function () {
        var map = $('#mapContainer').dxVectorMap('instance');
        $('#widgetSVG').html(map.svg());
    });
});

viewport()

Gets the current coordinates of the map viewport.

Return Value: Array
The current coordinates of the map viewport.

This method returns the viewport coordinates as an array of four values in the [minLongitude, maxLatitude, maxLongitude, minLatitude] form.

viewport(viewportCoordinates)

Sets the coordinates of the map viewport.

Parameters:
viewportCoordinates: Array
New coordinates for the map viewport.

To change the coordinates of the map viewport, pass an array of four values in the [minLongitude, maxLatitude, maxLongitude, minLatitude] form as the argument to the viewport(viewportCoordinates) method. If the passed coordinates do not fit the aspect ratio of the widget container precisely, either the latitude or longitude will be applied depending on the largest range.

In addition, you can get the current coordinates of the map viewport by calling the same method without arguments.

If you have implemented the centerChanged or zoomFactorChanged callback functions, they will be triggered when the viewport coordinates are changed using the viewport(viewportCoordinates) method.

zoomFactor()

Gets the current value of the map zoom factor.

Return Value: Number
The current value of the zoom factor.

zoomFactor(zoomFactor)

Sets the value of the map zoom factor.

Parameters:
zoomFactor: Number
A new value of the zoom factor.

To change the zoom factor, pass an numeric value as the argument to the zoomFactor(zoomFactor) method.

In addition, you can get the current value of the map zoom factor by calling the same method without arguments. Moreover, you can perform specific actions when the zoom factor is changed. For this purpose, implement a callback function and assign it to the zoomFactorChanged option.