Render OpenStreetMap and BingMaps in JS 2 | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Render OpenStreetMap and BingMaps in JS 2

One of the most important features in Essential JS 2 maps control is a built-in online map provider support. By using this feature, you can render OpenStreetMaps, Bing maps, or maps from other providers in the maps control. This provides the ability to visualize satellite, aerial, and street maps, or other kinds of imagery tiles, without using any external shape files. By using these external services, the map data can be located easily.

OpenStreetMap

The OpenStreetMap (OSM) is the world map built by a community of mappers; it is free to use under an open license. It allows you to view geographical data in a collaborative way from anywhere on the earth. The OSM map provides small tile images based on our requests and combines those images into a single image to display the map area in the maps control.

To use OSM, add a layer in maps layers collection, and set the layerType to OSM as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'OSM'
        }
    ]
});


Bing maps

Bing maps is a map of the entire world owned by Microsoft. As with OSM, it provides map tile images based on our requests and combines those images into a single one to display a map area. To use Bing maps, set the layerType to Bing, and set the Bing maps key (which can be obtained here) to key property as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

The maps control supports six types of viewing style options in Bing maps: Aerial, AerialWithLabel, Road, CanvasDark, CanvasLight, and CanvasGray. The default view of the Bing maps style is Aerial.

Aerial

Aerial view displays satellite images to highlight roads and major landmarks for easy identification. To render the Aerial view, set the bingMapType to Aerial as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'Aerial',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});


AerialWithLabel

The AerialWithLabel view displays the Aerial map with labels for the continent, country, ocean, etc. To render this type of view, set the bingMapType to AerialWithLabel as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'AerialWithLabel',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

Road

The Road view displays the default map view of roads, buildings, and geography. To render the Road view, set the bingMapType to Road as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'Road',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

CanvasDark

CanvasDark is a dark version of the road maps. To render this view, set the bingMapType to CanvasDark as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'CanvasDark',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

CanvasLight

CanvasLight is a light version of the road maps. To render this view, set the bingMapType to CanvasLight as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'CanvasLight',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

CanvasGray

CanvasGray is a grayscale version of the road maps. To render this view, set the bingMapType to CanvasGray as shown in the following code.

let maps: Maps = new Maps({
    layers: [
        {
            layerType: 'Bing',
            bingMapType: 'CanvasGray',
            key: ''
            // Need to create Bing maps key and set to key property.
        }
    ]
});

Other map providers

As well as OSM and Bing maps, you can also render maps from other map service providers using Essential JS 2 maps control by specifying the layerType as OSM and the URL generated by the map provider in the urlTemplate property. Here, we have rendered Google maps. (Refer to Google maps licensing here).

let maps: Maps = new Maps({
    layers: [{
        layerType: 'OSM',
        urlTemplate: 'http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level'
    }]
});

Functionalities on OSM/Bing maps

Apart from rendering, Essential JS 2 maps control also provides various functionalities to OSM/Bing maps layers such as zooming and panning support, placing markers, rendering navigation lines, sublayers, etc.

Zooming and panning

You can zoom and pan the OSM/Bing maps layer. Zooming helps you get a closer look at a particular area on a map for in-depth analysis. Panning helps you to move a map around to focus the targeted area.

Markers

Markers can be added to the layers of OSM/Bing maps by setting the corresponding location’s coordinates of latitude and longitude. The type of marker can be changed to built-in shapes such as circles, diamonds, rectangles, etc. Custom HTML elements can also be added as markers to highlight a location.

let maps: Maps = new Maps({
    layers: [{
        layerType: 'OSM',
        markerSettings: [{
            visible: true,
            dataSource: [
                { latitude: 37.6276571, longitude: -122.4276688 },
                { latitude: 40.7424509, longitude: -74.0081468 },
                { latitude: -23.5268201, longitude: -46.6489927 },
                { latitude: 48.8773406, longitude: 2.3299627 },
                { latitude: 19.1555762, longitude: 72.8849595 },
                { latitude: 35.6628744, longitude: 139.7345469 }
            ],
            shape: 'Balloon',
            fill: '#E13E40',
            height: 20,
            width: 15
        }]
    }]
});

Navigation lines

You can add navigation lines on top of an OSM/Bing maps layer for highlighting a path among various places by setting the corresponding locations’ coordinates of latitude and longitude in the navigationLineSettings property.

let maps: Maps = new Maps({
    zoomSettings: {
        zoomFactor: 5
    },
    centerPosition: {
        latitude: 24.0902,
        longitude: -90.7129
    },
    layers: [{
        layerType: 'OSM',
        navigationLineSettings: [
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [22.403410892712124, 29.756032197482973], longitude: [-97.8717041015625, -95.36270141601562],
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [22.403410892712124, 30.180747605060766 ], longitude: [-97.8717041015625, -85.81283569335938]
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [22.403410892712124, 27.9337540167772], longitude: [-97.8717041015625, -82.49908447265625]
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [22.403410892712124, 21.282336521195344], longitude: [-97.8717041015625, -89.6649169921875]
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [29.756032197482973, 21.282336521195344], longitude: [-95.36270141601562, -89.6649169921875]
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [30.180747605060766, 21.282336521195344], longitude: [-85.81283569335938, -89.6649169921875]
        },
        {
            visible: true, angle: 0, color: '#E13E40',
            latitude: [27.9337540167772, 21.282336521195344], longitude: [-82.49908447265625, -89.6649169921875]
        }]
    }]
});

Sublayers

You can render any GeoJSON shape as a sublayer on top of an OSM maps layer for highlighting a particular continent or country in OSM/Bing maps by adding another layer and specifying the type to SubLayer.

let maps: Maps = new Maps({
    zoomSettings: {
        zoomFactor: 1
    },
    layers: [{
        layerType: 'OSM',
    },
    {
        type: 'SubLayer',
        // GeoJSON data to render the African continent.
        shapeData: [{ }],
        shapeSettings: {
            fill: '#5100a3',
            opacity: 0.7
        }
    }]
});

An interactive version of an OSM sample is available on Plunker: https://plnkr.co/edit/LRvu74GBiimg4LQrnZi6?p=preview

We hope that you will enjoy this feature that makes Syncfusion maps more usable. If you have any questions or need any clarification, please let us know in the comments section. You can also contact us through our support forum or Direct-Trac. We are always happy to assist you!

 

If you like this blog post, we think you’ll also like the following free e-books:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed