Search results

Other Maps in React Maps component

15 Oct 2021 / 3 minutes to read

Apart from the OpenStreetMap and Bing Maps, you can also render the Maps from other map service providers by specifying layerType as OSM and the URL generated by map provider in the urlTemplate property. Here, Google Maps is rendered. This provides customizable Maps with your own content and imagery.

Refer to Google Maps Licensing.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
//tslint:disable
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps">
                <LayersDirective>
                    <LayerDirective layerType='OSM'
                                    urlTemplate= "http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level" />
                </LayersDirective>
            </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
//tslint:disable
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
                <LayersDirective>
                    <LayerDirective layerType='OSM' urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"/>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Zooming and Panning

Tile Maps layer can be zoomed and panned. Zooming helps to get a closer look at a particular area on a Maps for in-depth analysis. Panning helps to move a Maps around to focus the targeted area.

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

ReactDOM.render(
            <MapsComponent id="maps" zoomSettings= {{enable: true}}>
            <Inject services={[Zoom]}/>
                <LayersDirective>
                    <LayerDirective layerType='OSM'
                                    urlTemplate= "http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level" />
                </LayersDirective>
            </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
//tslint:disable
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 layerType='OSM' urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"/>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Adding markers and navigation line

Markers can be added to the layers of tile Maps by setting the corresponding location’s coordinates of latitude and longitude using markerSettings. Navigation lines can be added on top of an tile Maps layer for highlighting a path among various places by setting the corresponding location’s coordinates of latitude and longitude in the navigationLineSettings.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
//tslint:disable
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, MarkersDirective, NavigationLine, NavigationLinesDirective, NavigationLineDirective, MarkerDirective, Marker, Maps, Inject } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps" zoomSettings= {{ zoomFactor: 4}}
                                     centerPosition = {{
                                         latitude: 29.394708,
                                         longitude: -94.954653
                                     }}>
            <Inject services={[Zoom, NavigationLine, Marker]} />
                <LayersDirective>
                    <LayerDirective layerType='OSM'
                                    urlTemplate= "http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level">
                        <MarkersDirective>
                        <MarkerDirective visible={true}
                                            height={25}
                                            width={15}
                                            dataSource={[
                                                {
                                                    latitude: 34.060620,
                                                    longitude: -118.330491,
                                                    name: "California"
                                                },
                                                {
                                                    latitude: 40.724546,
                                                    longitude: -73.850344,
                                                    name: "New York"
                                                }
                                            ]}
                                        >
                            </MarkerDirective>
                            </MarkersDirective>
                            <NavigationLinesDirective>
                            <NavigationLineDirective visible={true}
                                                     latitude={[34.060620, 40.724546]}
                                                     longitude={[-118.330491,-73.850344]}
                                                     color="blue"
                                                     angle={90}
                                                     width={5} />
                        </NavigationLinesDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
//tslint:disable
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective, Zoom, MarkersDirective, NavigationLine, NavigationLinesDirective, NavigationLineDirective, MarkerDirective, Marker, Inject } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps" zoomSettings={{ zoomFactor: 4 }} centerPosition={{
    latitude: 29.394708,
    longitude: -94.954653
}}>
            <Inject services={[Zoom, NavigationLine, Marker]}/>
                <LayersDirective>
                    <LayerDirective layerType='OSM' urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level">
                        <MarkersDirective>
                        <MarkerDirective visible={true} height={25} width={15} dataSource={[
    {
        latitude: 34.060620,
        longitude: -118.330491,
        name: "California"
    },
    {
        latitude: 40.724546,
        longitude: -73.850344,
        name: "New York"
    }
]}>
                            </MarkerDirective>
                            </MarkersDirective>
                            <NavigationLinesDirective>
                            <NavigationLineDirective visible={true} latitude={[34.060620, 40.724546]} longitude={[-118.330491, -73.850344]} color="blue" angle={90} width={5}/>
                        </NavigationLinesDirective>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));

Sublayer

Any GeoJSON shape can be rendered as a sublayer on top of the tile Maps layer for highlighting a particular continent or country in tile Maps by adding another layer and specifying the type property of Maps layer to SubLayer.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
//tslint:disable
import { usa_map } from 'usa.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective } from '@syncfusion/ej2-react-maps';

ReactDOM.render(
            <MapsComponent id="maps">
                <LayersDirective>
                    <LayerDirective layerType='OSM'
                                    urlTemplate= "http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level" />
                    <LayerDirective shapeData= {usa_map}
                                    type= 'SubLayer'
                                    shapeSettings = {{
                                        fill: 'blue'
                                    }}>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>,
document.getElementById("maps") as HTMLElement
);
Copied to clipboard
//tslint:disable
import { usa_map } from 'usa.ts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { MapsComponent, LayersDirective, LayerDirective } from '@syncfusion/ej2-react-maps';
ReactDOM.render(<MapsComponent id="maps">
                <LayersDirective>
                    <LayerDirective layerType='OSM' urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"/>
                    <LayerDirective shapeData={usa_map} type='SubLayer' shapeSettings={{
    fill: 'blue'
}}>
                    </LayerDirective>
                </LayersDirective>
            </MapsComponent>, document.getElementById("maps"));