Search results

User Interactions in React Maps component

03 Dec 2021 / 15 minutes to read

Zooming

The zooming feature is used to zoom in and out of Maps to show in-depth information. It is controlled by the zoomFactor property of the zoomSettings of the Maps. The Map is zoomed in when the zoomFactor is increased. The zoomFactor is increased or decrease dynamically based on zoom in and out interaction.

Enable zooming

Zooming of Maps is enabled by setting the enable property of zoomSettings to true.

Enable panning

To enable the panning feature, set the enablePanning property of zoomSettings to true.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps" zoomSettings={ { enable: true, enablePanning: true } }>
            <Inject services={[Zoom]}/>
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps" zoomSettings={{ enable: true, enablePanning: true }}>
            <Inject services={[Zoom]}/>
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Various type of zooming

Zooming can be performed in following types:

Zooming toolbar

By default, the toolbar is rendered with zoom-in, zoom-out, and reset options when it is set to true in the enable property of zoomSettings.

The following options are available in toolbar.

  1. Zoom - Provides rectangular zoom support.
  2. ZoomIn - Zooms in the Maps.
  3. ZoomOut - Zooms out the Maps.
  4. Pan - Switches to panning if rectangular zoom is activated.
  5. Reset - Restores the Maps to the default view.

The following properties are available in toolbars to customize the zooming toolbars.

  • color - To apply the color for toolbars in Maps.
  • highlightColor - To apply the color for the zooming toolbar when the mouse has hovered on the toolbar element in Maps.
  • horizontalAlignment - To customize the position type of toolbar when it is placed horizontally.
  • selectionColor - To apply the color for the zooming toolbar when clicking the zooming toolbar in Maps.
  • toolBarOrientation - To customize the orientation of the zooming toolbar.
  • toolbars - To customize the items that are to be shown in the zooming toolbar in Maps.
  • verticalAlignment - To customize the position type of toolbar when it is placed vertically.
Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ {
                                    enable: true,
                                    color: 'green',
                                    highlightColor: 'blue',
                                    selectionColor: 'orange',
                                    horizontalAlignment: 'Center',
                                    toolbars: ['ZoomIn', 'ZoomOut', 'Pan', 'Reset']} }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps" zoomSettings={{
    enable: true,
    color: 'green',
    highlightColor: 'blue',
    selectionColor: 'orange',
    horizontalAlignment: 'Center',
    toolbars: ['ZoomIn', 'ZoomOut', 'Pan', 'Reset']
}}>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Pinch zooming

To enable or disable the pinch zooming, use the pinchZooming property in zoomSettings.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, pinchZooming: true } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Single-click zooming

To enable or disable the single-click zooming, use the zoomOnClick property in zoomSettings.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, zoomOnClick: true } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Double-click zooming

To enable or disable the double-click zooming, use the doubleClickZoom property in zoomSettings.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, doubleClickZoom: true } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Mouse wheel zooming

To enable or disable mouse wheel zooming, use the mouseWheelZoom property in zoomSettings.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, mouseWheelZoom: true } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Selection zooming

To enable or disable selection zooming, use the enableSelectionZooming property in zoomSettings. The enablePanning property must be set to false to enable the selection zooming in Maps.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, enableSelectionZooming: true,
                                                  enablePanning: false } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Setting minimum and maximum values for zoom factor

The zooming range can be adjusted using the minZoom and maxZoom properties in zoomSettings. The minZoom value is set to 1 by default, and the maxZoom value is set to 10.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true, minZoom: 2,
                                                  maxZoom: 12 } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Zooming with animation

To zoom in or zoom out the Maps with animation, use the animationDuration property in layers.

Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" zoomSettings={ { enable: true } }>
        <Inject services={[Zoom]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} animationDuration={500}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);

Selection

Each shape in the Maps can be selected and deselected during interaction with the shapes. Selection is enabled by setting the enable property of selectionSettings to true.

The following properties are available to customize the selection of Maps elements such as shapes, bubbles, markers and legends.

  • border - To customize the color, width and opacity of the border of which element is selected in Maps.
  • fill - Applies the color for the element that is selected.
  • opacity - To customize the transparency for the element that is selected.
  • enableMultiSelect - To enable or disable the selection for multiple shapes or markers or bubbles in the Maps.

By tapping on the specific legend, the shapes which are bounded to the selected legend is also selected and vice versa.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Selection, Inject, Legend  } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" legendSettings={{visible: true}}>
        <Inject services={[Selection, Legend]} />
            <LayersDirective>
                <LayerDirective shapeData={world_map} selectionSettings={ {
                    enable: true,
                    fill: 'blue',
                    border: { color: 'white', width: 2 }
                } } dataSource={[
                    {"Country": "China", "Membership": "Permanent"},
                    {"Country": "France","Membership": "Permanent" },
                    { "Country": "Russia","Membership": "Permanent"},
                    {"Country": "Kazakhstan","Membership": "Non-Permanent"},
                    { "Country": "Poland","Membership": "Non-Permanent"},
                    {"Country": "Sweden","Membership": "Non-Permanent"}
                   ]} shapePropertyPath="name" shapeDataPath="Country"
                    shapeSettings={{
                       colorValuePath: 'Membership',
                       colorMapping: [
                           { value: 'Permanent', color: '#D84444' },
                           { value: 'Non-Permanent', color: '#316DB5'}]
                    }}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Selection, Inject, Legend } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps" legendSettings={{ visible: true }}>
        <Inject services={[Selection, Legend]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} selectionSettings={{
    enable: true,
    fill: 'blue',
    border: { color: 'white', width: 2 }
}} dataSource={[
    { "Country": "China", "Membership": "Permanent" },
    { "Country": "France", "Membership": "Permanent" },
    { "Country": "Russia", "Membership": "Permanent" },
    { "Country": "Kazakhstan", "Membership": "Non-Permanent" },
    { "Country": "Poland", "Membership": "Non-Permanent" },
    { "Country": "Sweden", "Membership": "Non-Permanent" }
]} shapePropertyPath="name" shapeDataPath="Country" shapeSettings={{
    colorValuePath: 'Membership',
    colorMapping: [
        { value: 'Permanent', color: '#D84444' },
        { value: 'Non-Permanent', color: '#316DB5' }
    ]
}}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Enable selection for bubbles

To enable the selection for bubbles in Maps, set the selectionSettings in bubbleSettings and set the enable property of selectionSettings as true.

To use the bubble feature, the Bubble module must be injected.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Inject } from '@syncfusion/ej2-react-maps';
import { BubblesDirective, BubbleDirective, Bubble, Selection } from '@syncfusion/ej2-react-maps';


ReactDOM.render(
        <MapsComponent id="maps">
        <Inject services={[Bubble, Selection]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} shapeDataPath="name" shapePropertyPath="name">
                    <BubblesDirective>
                        <BubbleDirective visible={true} valuePath="population"
                                         dataSource={[
                                            { name: 'India', population: '38332521' },
                                            { name: 'Pakistan', population: '3090416' },
                                            { name: 'New Zealand', population: '19651127' }
                                         ]}
                                         selectionSettings={{
                                            enable: true,
                                            fill: 'green',
                                            border: { color: 'white', width: 2}
                                         }} />
                    </BubblesDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
        document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Inject } from '@syncfusion/ej2-react-maps';
import { BubblesDirective, BubbleDirective, Bubble, Selection } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
        <Inject services={[Bubble, Selection]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} shapeDataPath="name" shapePropertyPath="name">
                    <BubblesDirective>
                        <BubbleDirective visible={true} valuePath="population" dataSource={[
    { name: 'India', population: '38332521' },
    { name: 'Pakistan', population: '3090416' },
    { name: 'New Zealand', population: '19651127' }
]} selectionSettings={{
    enable: true,
    fill: 'green',
    border: { color: 'white', width: 2 }
}}/>
                    </BubblesDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Enable selection for markers

To enable the selection for markers in Maps, set the selectionSettings in the markerSettings and set the enable property of the selectionSettings as true.

To use the marker feature, the Marker module must be injected.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Selection, Marker, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps">
            <Inject services={[Marker, Selection]} />
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true}
                                        height={20}
                                        width={20}
                                        animationDuration={0}
                                        fill="green"
                                        shape="Balloon"
                                        dataSource={[
                                            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
                                            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
                                            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
                                        ]}
                                        selectionSettings={{
                                            enable: true,
                                            fill: 'blue',
                                            border: { color: 'white', width: 2}
                                        }}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
        document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Selection, Marker, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
            <Inject services={[Marker, Selection]}/>
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true} height={20} width={20} animationDuration={0} fill="green" shape="Balloon" dataSource={[
    { latitude: 49.95121990866204, longitude: 18.468749999999998, name: 'Europe' },
    { latitude: 59.88893689676585, longitude: -109.3359375, name: 'North America' },
    { latitude: -6.64607562172573, longitude: -55.54687499999999, name: 'South America' }
]} selectionSettings={{
    enable: true,
    fill: 'blue',
    border: { color: 'white', width: 2 }
}}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Public method for the shape selection

The shapeSelection method can be used to select each shape in the Maps. LayerIndex, propertyName, country name, and selected value as a boolean state(true / false) are the input parameters for this method.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Selection, Inject } from '@syncfusion/ej2-react-maps';

class App extends React.Component<{}, {}>{

  public mapsInstance: MapsComponent;
  public selectclickHandler() {
this.mapsInstance.shapeSelection(0, "continent", "Asia", true);
  }
  public unselectclickHandler() {
this.mapsInstance.shapeSelection(0, "continent", "Asia", false);
  }
  render() {
return (<div>
  <MapsComponent id="maps" ref={maps => this.mapsInstance = maps}>
        <Inject services={[Selection]} />
            <LayersDirective>
                <LayerDirective shapeData={world_map} selectionSettings={ {
                    enable: true,
                    fill: 'green',
                    border: { color: 'white', width: 2 }
                } }>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>
        <button value='select' onClick={this.selectclickHandler.bind(this)}>select</button>
        <button value='unselect' onClick={this.unselectclickHandler.bind(this)}>unselect</button></div>)
  }
};
ReactDOM.render(<App />, document.getElementById('maps'));
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Selection, Inject } from '@syncfusion/ej2-react-maps';
class App extends React.Component {
    selectclickHandler() {
        this.mapsInstance.shapeSelection(0, "continent", "Asia", true);
    }
    unselectclickHandler() {
        this.mapsInstance.shapeSelection(0, "continent", "Asia", false);
    }
    render() {
        return (<div>
  <MapsComponent id="maps" ref={maps => this.mapsInstance = maps}>
        <Inject services={[Selection]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} selectionSettings={{
            enable: true,
            fill: 'green',
            border: { color: 'white', width: 2 }
        }}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>
        <button value='select' onClick={this.selectclickHandler.bind(this)}>select</button>
        <button value='unselect' onClick={this.unselectclickHandler.bind(this)}>unselect</button></div>);
    }
}
;
ReactDOM.render(<App />, document.getElementById('maps'));

Initial shape selection

The shape is initially selected using the initialShapeSelection, and the values are mapped to the shapePath and shapeValue.

initialShapeSelection is an Array property.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, InitialShapeSelectionsDirective, InitialShapeSelectionDirective, LayerDirective, Selection, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps">
        <Inject services={[Selection]} />
            <LayersDirective>
                <LayerDirective shapeData={world_map}  selectionSettings={{
                    enable: true,
                    fill: 'green',
                    border: { color: 'white', width: 2 }
                }}>
    <InitialShapeSelectionsDirective>
        <InitialShapeSelectionDirective shapePath={'continent'} shapeValue={'Africa'}>
        </InitialShapeSelectionDirective>
        <InitialShapeSelectionDirective shapePath={'name'} shapeValue={'India'}>
        </InitialShapeSelectionDirective>
    </InitialShapeSelectionsDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, InitialShapeSelectionsDirective, InitialShapeSelectionDirective, LayerDirective, Selection, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
        <Inject services={[Selection]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} selectionSettings={{
    enable: true,
    fill: 'green',
    border: { color: 'white', width: 2 }
}}>
    <InitialShapeSelectionsDirective>
        <InitialShapeSelectionDirective shapePath={'continent'} shapeValue={'Africa'}>
        </InitialShapeSelectionDirective>
        <InitialShapeSelectionDirective shapePath={'name'} shapeValue={'India'}>
        </InitialShapeSelectionDirective>
    </InitialShapeSelectionsDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Initial marker selection

Using the initialMarkerSelection, the marker shape can be selected initially. Markers render based on the latitude and longitude values.

initialMarkerSelection is an Array property.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Selection, Marker, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps">
            <Inject services={[Marker, Selection]} />
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true}
                                        height={20}
                                        width={20}
                                        animationDuration={0}
                                        fill="green"
                                        shape="Balloon"
                                        dataSource={[
                                            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
                                            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
                                            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
                                        ]}
                                        initialMarkerSelection={{
                                            latitude: -6.64607562172573, longitude: -55.54687499999999
                                        }}
                                        selectionSettings={{
                                            enable: true,
                                            fill: 'blue',
                                            border: { color: 'white', width: 2}
                                        }}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
        document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Selection, Marker, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
            <Inject services={[Marker, Selection]}/>
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true} height={20} width={20} animationDuration={0} fill="green" shape="Balloon" dataSource={[
    { latitude: 49.95121990866204, longitude: 18.468749999999998, name: 'Europe' },
    { latitude: 59.88893689676585, longitude: -109.3359375, name: 'North America' },
    { latitude: -6.64607562172573, longitude: -55.54687499999999, name: 'South America' }
]} initialMarkerSelection={{
    latitude: -6.64607562172573, longitude: -55.54687499999999
}} selectionSettings={{
    enable: true,
    fill: 'blue',
    border: { color: 'white', width: 2 }
}}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Highlight

Each shape in the Maps can be highlighted during mouse hover on the Maps elements such as shapes, bubbles, markers and legends. Highlight is enabled by setting the enable property of highlightSettings to true.

The following properties are available to customize the highlight of Maps elements such as shapes, bubbles, markers and legends.

  • border - To customize the color, width and opacity of the border of which element is highlighted in Maps.
  • fill - Applies the color for the element that is highlighted.
  • opacity - To customize the transparency for the element that is highlighted.

Hovering on the specific legend, the shapes which are bounded to the selected legend is also highlighted and vice versa.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Highlight, Inject, Legend } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps" legendSettings={{visible: true}}>
        <Inject services={[Highlight, Legend]} />
            <LayersDirective>
                <LayerDirective shapeData={world_map}  highlightSettings={ {
                    enable: true,
                    fill: 'green',
                    border: { color: 'white', width: 2 }
                } }
                    dataSource={[
                        { "Country": "China", "Membership": "Permanent"},
                        { "Country": "France", "Membership": "Permanent" },
                        { "Country": "Russia", "Membership": "Permanent"},
                        { "Country": "Kazakhstan", "Membership": "Non-Permanent"},
                        { "Country": "Poland", "Membership": "Non-Permanent"},
                        { "Country": "Sweden", "Membership": "Non-Permanent"}
                    ]} shapePropertyPath="name" shapeDataPath="Country"
                     shapeSettings={{
                        colorValuePath: 'Membership',
                        colorMapping: [
                            { value: 'Permanent', color: '#D84444' },
                            { value: 'Non-Permanent', color: '#316DB5'}]
                     }}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Highlight, Inject, Legend } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps" legendSettings={{ visible: true }}>
        <Inject services={[Highlight, Legend]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} highlightSettings={{
    enable: true,
    fill: 'green',
    border: { color: 'white', width: 2 }
}} dataSource={[
    { "Country": "China", "Membership": "Permanent" },
    { "Country": "France", "Membership": "Permanent" },
    { "Country": "Russia", "Membership": "Permanent" },
    { "Country": "Kazakhstan", "Membership": "Non-Permanent" },
    { "Country": "Poland", "Membership": "Non-Permanent" },
    { "Country": "Sweden", "Membership": "Non-Permanent" }
]} shapePropertyPath="name" shapeDataPath="Country" shapeSettings={{
    colorValuePath: 'Membership',
    colorMapping: [
        { value: 'Permanent', color: '#D84444' },
        { value: 'Non-Permanent', color: '#316DB5' }
    ]
}}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Enable highlight for bubbles

To enable the highlight for bubbles in Maps, set the highlightSettings in bubbleSettings and set the enable property of highlightSettings as true.

To use the bubble feature, the Bubble module must be injected.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Inject } from '@syncfusion/ej2-react-maps';
import { BubblesDirective, BubbleDirective, Bubble, Highlight } from '@syncfusion/ej2-react-maps';


ReactDOM.render(
        <MapsComponent id="maps">
        <Inject services={[Bubble, Highlight]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} shapeDataPath="name" shapePropertyPath="name">
                    <BubblesDirective>
                        <BubbleDirective visible={true} valuePath="population"
                                         dataSource={[
                                            { name: 'India', population: '38332521' },
                                            { name: 'Pakistan', population: '3090416' },
                                            { name: 'New Zealand', population: '19651127' }
                                         ]}
                                         highlightSettings={{
                                            enable: true,
                                            fill: 'green',
                                            border: { color: 'white', width: 2}
                                         }} />
                    </BubblesDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
        document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Inject } from '@syncfusion/ej2-react-maps';
import { BubblesDirective, BubbleDirective, Bubble, Highlight } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
        <Inject services={[Bubble, Highlight]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} shapeDataPath="name" shapePropertyPath="name">
                    <BubblesDirective>
                        <BubbleDirective visible={true} valuePath="population" dataSource={[
    { name: 'India', population: '38332521' },
    { name: 'Pakistan', population: '3090416' },
    { name: 'New Zealand', population: '19651127' }
]} highlightSettings={{
    enable: true,
    fill: 'green',
    border: { color: 'white', width: 2 }
}}/>
                    </BubblesDirective>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Enable highlight for markers

To enable the highlight for markers in Maps, set the highlightSettings in markerSettings and set the enable property of highlightSettings as true.

To use the marker feature, the Marker module must be injected.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Highlight , Marker, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps">
            <Inject services={[Marker, Highlight]} />
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true}
                                        height={20}
                                        width={20}
                                        animationDuration={0}
                                        fill="green"
                                        shape="Balloon"
                                        dataSource={[
                                            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
                                            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
                                            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
                                        ]}
                                        highlightSettings={{
                                            enable: true,
                                            fill: 'blue',
                                            border: { color: 'white', width: 2}
                                        }}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
        document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MarkersDirective, MarkerDirective, Highlight, Marker, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
            <Inject services={[Marker, Highlight]}/>
                <LayersDirective>
                    <LayerDirective shapeData={world_map}>
                    <MarkersDirective>
                        <MarkerDirective visible={true} height={20} width={20} animationDuration={0} fill="green" shape="Balloon" dataSource={[
    { latitude: 49.95121990866204, longitude: 18.468749999999998, name: 'Europe' },
    { latitude: 59.88893689676585, longitude: -109.3359375, name: 'North America' },
    { latitude: -6.64607562172573, longitude: -55.54687499999999, name: 'South America' }
]} highlightSettings={{
    enable: true,
    fill: 'blue',
    border: { color: 'white', width: 2 }
}}>
                        </MarkerDirective>
                    </MarkersDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Tooltip

On mouse over or touch end event, the tooltip is used to get more information about the layer, bubble, or marker. To enable tooltip in Maps, the Tooltip module must be injected into Maps using Inject services={[Tooltip]} tag. It can be enabled separately for layer or bubble or marker by using the visible property of tooltipSettings as true. The valuePath property in the tooltip takes the field name that presents in data source and displays that value as tooltip text. The tooltipDisplayMode property is used to change the display mode of the tooltip in Maps. Following display modes of tooltip are available in the Maps component. By default, tooltipDisplayMode is set to MouseMove.

  • MouseMove
  • Click
  • DoubleClick
Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
        <MapsComponent id="maps">
                    <Inject services={[MapsTooltip]} />
            <LayersDirective>
                <LayerDirective shapeData={world_map}  tooltipSettings={ {
                        visible: true,
                        valuePath: 'name'
                    } }>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
import { world_map } from 'world-map.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
                    <Inject services={[MapsTooltip]}/>
            <LayersDirective>
                <LayerDirective shapeData={world_map} tooltipSettings={{
    visible: true,
    valuePath: 'name'
}}>
                </LayerDirective>
            </LayersDirective>
        </MapsComponent>, document.getElementById("maps"));

Customization

The following properties are available in the tooltipSettings to customize the tooltip of the Maps component.

  • border - To customize the color, width and opacity of the border of the tooltip in layers, markers, and bubbles of Maps.
  • fill - Applies the color of the tooltip in layers, markers, and bubbles of Maps.
  • format - To customize the format of the tooltip in layers, markers, and bubbles of Maps
  • textStyle - To customize the style of the text in the tooltip for layers, markers, and bubbles of Maps.
Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import { default_data } from 'data.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';

class App extends React.Component {
render() {
    return(<div><MapsComponent id="maps">
    <Inject services={[MapsTooltip]}/>
        <LayersDirective>
          <LayerDirective shapeData={world_map} dataSource={default_data} shapeDataPath='continent'
          shapePropertyPath='continent'
          tooltipSettings={{
              visible: true,
              valuePath: 'continent',
              format: '${continent}',
              fill: '#D0D0D0',
              textStyle: {
                color: 'green',
                fontFamily: 'Times New Roman',
                fontStyle: 'Sans-serif'
            }
          }}/>
        </LayersDirective>
       </MapsComponent></div>);
}
}
ReactDOM.render(<App/>, document.getElementById('maps'));
Copied to clipboard
import { world_map } from 'world-map.ts';
import { default_data } from 'data.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';
class App extends React.Component {
    render() {
        return (<div><MapsComponent id="maps">
    <Inject services={[MapsTooltip]}/>
        <LayersDirective>
          <LayerDirective shapeData={world_map} dataSource={default_data} shapeDataPath='continent' shapePropertyPath='continent' tooltipSettings={{
            visible: true,
            valuePath: 'continent',
            format: '${continent}',
            fill: '#D0D0D0',
            textStyle: {
                color: 'green',
                fontFamily: 'Times New Roman',
                fontStyle: 'Sans-serif'
            }
        }}/>
        </LayersDirective>
       </MapsComponent></div>);
    }
}
ReactDOM.render(<App />, document.getElementById('maps'));

Tooltip template

The HTML element can be rendered in the tooltip of the Maps using the template property of the tooltipSettings.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import { world_map } from 'world-map.ts';
import { default_data } from 'data.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';

class App extends React.Component {
render() {
    return(<div><MapsComponent id="maps">
    <Inject services={[MapsTooltip]}/>
        <LayersDirective>
          <LayerDirective shapeData={world_map} dataSource={default_data} shapeDataPath='continent'
          shapePropertyPath='continent'
          tooltipSettings={{
              visible: true,
              valuePath: 'continent',
              template: '<div style="width:60px; text-align:center; background-color: white; border: 2px solid black; padding-bottom: 10px;padding-top: 10px;padding-left: 10px;padding-right: 10px;"><span>${continent}</span></div>',
              textStyle: {
                  color: 'black'
              }
          }}/>
        </LayersDirective>
       </MapsComponent></div>);
}
}
ReactDOM.render(<App/>, document.getElementById('maps'));
Copied to clipboard
import { world_map } from 'world-map.ts';
import { default_data } from 'data.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, MapsTooltip, Inject } from '@syncfusion/ej2-react-maps';
class App extends React.Component {
    render() {
        return (<div><MapsComponent id="maps">
    <Inject services={[MapsTooltip]}/>
        <LayersDirective>
          <LayerDirective shapeData={world_map} dataSource={default_data} shapeDataPath='continent' shapePropertyPath='continent' tooltipSettings={{
            visible: true,
            valuePath: 'continent',
            template: '<div style="width:60px; text-align:center; background-color: white; border: 2px solid black; padding-bottom: 10px;padding-top: 10px;padding-left: 10px;padding-right: 10px;"><span>${continent}</span></div>',
            textStyle: {
                color: 'black'
            }
        }}/>
        </LayersDirective>
       </MapsComponent></div>);
    }
}
ReactDOM.render(<App />, document.getElementById('maps'));