Search results

Other Maps in ASP.NET MVC Maps control

Apart from the OpenStreetMap and Bing Maps, you can also render the maps from other map service provided 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.

razor
othermap.cs
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").Layers(l=> {
    l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.OSM).UrlTemplate("http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level").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();
        }
    }
}

Zooming and panning

You can zoom and pan the Google 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.

razor
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").ZoomSettings(zoom=>zoom.Enable(true)).Layers(l=> {
    l.LayerType(Syncfusion.EJ2.Maps.ShapeLayerType.OSM).UrlTemplate("http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level").Add();
}).Render()

Adding markers and navigation line

Markers can be added to the layers of Google maps by setting the corresponding location’s coordinates of latitude and longitude using markerSettings property. You can add navigation lines on top of an Google maps layer for highlighting a path among various places by setting the corresponding location’s coordinates of latitude and longitude in the navigationLineSettings property.

razor
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l => l.LayerType('OSM').UrlTemplate("http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level").
   {
       .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()

Sublayer

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

razor
othersublayer.cs
@using Syncfusion.EJ2;
@Html.EJS().Maps("maps").Layers(l =>
   {
       l.LayerType("OSM").UrlTemplate("http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level").Add();
       l.ShapeData(ViewBag.usMap).type("SubLayer").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;
using Syncfusion.EJ2.Charts;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            ViewBag.usmap = GetUSMap();
            return View();
        }
        public object GetUSMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/USA.json");
            return JsonConvert.DeserializeObject(allText);
        }
    }
}