Bing Maps
23 Feb 20228 minutes to read
Bing Maps is a online Maps provider, owned by Microsoft. As like OSM, it provide Maps tile images based on our requests and combines those images into a single one to display Maps area.
Adding Bing Maps
The Bing Maps can be rendered by setting the LayerType
property as Bing and the key for the Bing Maps must be set in the Key
property. The Bing Maps key can be obtained from here.
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").Layers(l=> {
l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.Bing).BingMapType(Syncfusion.EJ2.Maps.BingMapType.AerialWithLabel).Key("// …bingMapKey").Add();
}).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
Specify Bing Maps key in the
key
property.
Types of Bing Maps
Bing Maps provides different types of Maps and it is supported in the Maps component.
- Aerial - Displays satellite images to highlight roads and major landmarks for easy identification.
- AerialWithLabel - Displays aerial Maps with labels for the continent, country, ocean, etc.
- Road - Displays the default Maps view of roads, buildings, and geography.
- CanvasDark - Displays dark version of the road Maps.
- CanvasLight - Displays light version of the road Maps.
- CanvasGray - Displays grayscale version of the road Maps.
To render the light version of the road Maps, set the BingMapType
to CanvasLight
as demonstrated in the following code sample.
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").Layers(l=> {
l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.Bing).BingMapType(Syncfusion.EJ2.Maps.BingMapType.AerialWithLabel).Key("// …bingMapKey").Add();
}).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
Specify Bing Maps key in the
key
property.
Zooming and Panning
Bing 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.
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").ZoomSettings(zoom=>zoom.Enable(true)).Layers(l=> {
l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.Bing).BingMapType(Syncfusion.EJ2.Maps.ShapeLayerType.BingMapType.CanvasLight).Key("// …bingMapKey")Add();
}).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
Specify Bing Maps key in the
key
property.
Adding markers and navigation line
Markers can be added to the layers of Bing Maps by setting the corresponding location’s coordinates of latitude and longitude using MarkerSettings
. Navigation lines can be added on top of an Bing Maps layer for highlighting a path among various places by setting the corresponding location’s coordinates of latitude and longitude in the NavigationLineSettings
.
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l => l.LayerType('Bing').Key("// …bingMapKey").
{
.NavigationLineSettings(ns => {
ns.Visible(true).Latitude(new double[] { 34.060620, 40.724546})
.Longitude(new double[] { -118.330491, -73.850344 }).Color("blue").Angle(90)
.Width(5).Add();
}).MarkerSettings(marker =>
{
marker.Visible(true).DataSource(ViewBag.markerData).Add();
}).Add();
}).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.worldmap = GetWorldMap();
List<MarkerData> data = new List<MarkerData>
{
new MarkerData {latitude= 37.0000, longitude= -120.0000, city= "California" },
new MarkerData {latitude= 40.7127, longitude= -74.0059, city= "New York" },
new MarkerData {latitude= 42.0000, longitude= -93.0000, city= "Iowa" }
};
ViewBag.markerData = data;
return View();
}
public class MarkerData
{
public double latitude { get; set; }
public double longitude { get; set; }
public string city { get; set; }
}
}
}
Specify Bing Maps key in the
Key
property.
Sublayer
Any GeoJSON shape can be rendered as a sublayer on top of the Bing Maps layer for highlighting a particular continent or country in Bing Maps by adding another layer and specifying the Type
property of Maps layer to SubLayer. The key for the Bing Maps must be set in the Key
property.
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l =>
{
l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.Bing).Key('../bingmapkey').Add();
l.ShapeSettings(s => s.Fill("blue")).ShapeData(ViewBag.africaShape).Type(Syncfusion.EJ2.Maps.Type.SubLayer).Add();
}).Render()
using Newtonsoft.Json;
using Syncfusion.EJ2.Charts;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.africa = GetAfricaMap();
ViewBag.africaShape = GetAfricaShape();
return View();
}
public object GetAfricaShape()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/Africa.json"));
return JsonConvert.DeserializeObject(allText, typeof(object));
}
public object GetAfricaMap()
{
string text = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/Africa.json");
return JsonConvert.DeserializeObject(text);
}
}
}