Search results

Other Maps in React Maps component

24 Jun 2022 / 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. The URL template concept has been implemented in such a way that any online map service providers using the following template can benefit from previewing their Map in the Syncfusion React Maps component.

Sample Template: https://< domain_name >/maps/basic/{z}/{x}/{y}.png

  • ”${z}” - It represents zoom factor (level).
  • ”${x}” - It indicates tile image x-position (tileX).
  • ”${y}” - It indicates tile image y-position (tileY).

This provides customizable maps with your desired content and imagery. In this example, Google Maps is rendered.

Refer to Google Maps Licensing.

Source
Preview
index.jsx
index.tsx
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"));
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
);

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.jsx
index.tsx
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"));
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
);

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.jsx
index.tsx
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"));
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
);

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.jsx
index.tsx
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"));
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
);