Search results

State Persistence in ASP.NET MVC Maps control

22 Oct 2021 / 1 minute to read

State persistence

For state maintenance, state persistence allows Maps to save the current model value in browser cookies. This action is handled through the EnablePersistence property which is set to false by default. When this property is set to true, some of the Maps component model values are preserved even after the page is refreshed.

razor
persistence.cs
Copied to clipboard
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@Html.EJS().Maps("container").EnablePersistence(true).TitleSettings(title => title.Text("Top 50 largest cities in the World").
    TextStyle(new MapsFont { Size = "16px" })).ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
      {
          Enable = true
      }).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
         {
            new Syncfusion.EJ2.Maps.MapsLayer
                {
                    ShapeSettings = new MapsShapeSettings
                        {
                            Fill = "#C1DFF5"
                        },
                    ShapeData =  ViewBag.shapeData,
                    MarkerSettings  = new List<Syncfusion.EJ2.Maps.MapsMarker>
                        {
                            new Syncfusion.EJ2.Maps.MapsMarker
                            {
                                Visible = true,
                                DataSource = ViewBag.ClusterData,
                                Shape=MarkerType.Circle,
                                Height= 20,
                                Width= 20,
                                AnimationDuration= 0,
                            }
                        }}}).Render()
Copied to clipboard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Maps;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using EJ2MVCSampleBrowser.Models;

namespace EJ2MVCSampleBrowser.Controllers.Maps
{
    public partial class MapsController : Controller
    {
        // GET: MarkerClustering
        public ActionResult MarkerClustering()
        {
            ViewBag.shapeData = this.getWorldMap();
            ViewBag.ClusterData = this.ClusterData();
            return View();
        }
        public object ClusterData()
        {
            string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/MapData/ClusterData.json"));
            return JsonConvert.DeserializeObject(allText, typeof(object));
        }
        public object getWorldMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.json");
            return JsonConvert.DeserializeObject(allText);
        }
    }
}