VectorMapViewerClientSideEvents.BeforeInitialize Property

Specifies the name of the JavaScript function or the entire code which is executed before vector map is initialized.

Namespace: DevExpress.ExpressApp.Maps.Web.Helpers

Assembly: DevExpress.ExpressApp.Maps.Web.v18.2.dll

Declaration

public string BeforeInitialize { get; set; }
Public Property BeforeInitialize As String

Property Value

Type Default Description
String

String.Empty

A string which is the name of the JavaScript function or the entire code which is executed before vector map is initialized.

Remarks

The event's args contains the vectorMapSettings arguments that allows you to access Vector Map widget settings.

You can handle this event to change vector map layers to prevent a widget's flickering on its reinitialize. The following example demonstrates how to replace an existing Layer with a new one, using the vectorMapSettings argument in a simple scenario:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Maps.Web;
// ... 
public class MyController : ViewController {
    // ...
    protected override void OnViewControlsCreated() {
        base.OnViewControlsCreated();
        WebVectorMapsListEditor vectorMapsListEditor = ((ListView)View).Editor as WebVectorMapsListEditor;
        vectorMapsListEditor.VectorMapViewer.ClientSideEvents.BeforeInitialize = @"
            function(sender, args) {
                args.vectorMapSettings.layers[0].name = 'NewLayerName';
            }
        ";
    }
}

If you need to perform a long asynchronous operation to get data, you should create a new Promise object that returns an object with Vector Map settings, and set args.promise to this returned value. The code snippet below demonstrates how to do this:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Maps.Web;
// ... 
public class MyController : ViewController {
    // ...
    protected override void OnViewControlsCreated() {
        base.OnViewControlsCreated();
        WebVectorMapsListEditor vectorMapsListEditor = ((ListView)View).Editor as WebVectorMapsListEditor;
        vectorMapsListEditor.VectorMapViewer.ClientSideEvents.BeforeInitialize = @"
            function(sender, args) {
                var vectorMapSettings = args.vectorMapSettings;
                args.promise = new Promise(function(resolve) {
                    DevExpress.viz.vectormaputils.parse('ShapeFiles/gis.osm_buildings_a_free_1', { precision: 2 }, 
                    function(data) {                                                       
                        vectorMapSettings.layers[0].dataSource = data;
                        resolve(vectorMapSettings);
                    });                        
                });
            }
        ";
    }
}

Refer to the Using a Binary Source topic from the DevExtreme documentation to learn mode about methods used in the example above.

See Also