Search results

Other Maps in ASP.NET Core Maps control

28 Oct 2021 / 2 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.

tagHelper
othermap.cs
Copied to clipboard
@using Syncfusion.EJ2;
   <ejs-maps id="maps">
        <e-maps-layers>
            <e-maps-layer layerType="OSM" urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"></e-maps-layer>
        </e-maps-layers>
    </ejs-maps>
Copied to clipboard
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

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.

tagHelper
otherzoom.cs
Copied to clipboard
@using Syncfusion.EJ2;
   <ejs-maps id="maps">
        <e-maps-zoomSettings Enable="true">
        <e-maps-layers>
            <e-maps-layer layerType="OSM" urlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"></e-maps-layer>
        </e-maps-layers>
    </ejs-maps>
Copied to clipboard
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();
        }
    }
}

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.

tagHelper
othermarker.cs
Copied to clipboard
@{
    var data = new[]
    {
            new {latitude= 37.0000, longitude= -120.0000, city= "California" },
            new {latitude= 40.7127, longitude= -74.0059, city= "New York" },
            new {latitude= 42.0000, longitude= -93.0000, city= "Iowa" }
       };
    var marker = new List<MapsMarker>
    {
        new MapsMarker{Visible=true, DataSource=data}
    };

    }

@using Syncfusion.EJ2.Maps;
@using Syncfusion.EJ2;
<div id="control-section">
    <ejs-maps id="maps" load="window.onMapLoad">
        <e-maps-layers>
            <e-maps-layer LayerType="OSM" UrlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level" markerSettings="marker"></e-maps-layer>
        </e-maps-layers>
    </ejs-maps>
</div>

<script>
    function onMapLoad(args) {
        args.maps.layers[0].navigationLineSettings = [
            {
                visible: true,
                latitude: [40.7128, 36.7783],
                longitude: [-74.0060, -119.4179],
                color: 'black',
                angle: 90,
                width: 2,
                dashArray: '4'
            }
        ];
    }
</script>
Copied to clipboard
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; }
        }
    }
}

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.

tagHelper
othersublayer.cs
Copied to clipboard
@{ 
}  
@using Syncfusion.EJ2;
<ejs-maps id="maps">
        <e-maps-layers>
            <e-maps-layer LayerType="OSM" UrlTemplate="http://mt1.google.com/vt/lyrs=m@129&hl=en&x=tileX&y=tileY&z=level"></e-maps-layer>
            <e-maps-layer type="SubLayer" shapeData="ViewBag.usmap" shapeSettings="us_shape"></e-maps-layer>
        </e-maps-layers>
</ejs-maps>
Copied to clipboard
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);
        }
    }
}