State Persistence

30 Sep 20223 minutes 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.

@using Syncfusion.EJ2.Maps;
@{
    var titleStyle = new MapsFont
    {
        Size = "16px",
    };
}
<ejs-maps id="maps" format="n" useGroupingSeparator="true" enablePersistence="true">
    <e-maps-titlesettings alignment="@Syncfusion.EJ2.Maps.Alignment.Center" text="Top 50 largest cities in the World" textStyle="titleStyle"></e-maps-titlesettings>
        <e-maps-zoomsettings enable="true"></e-maps-zoomsettings>
            <e-maps-layers>
                <e-maps-layer shapeData="ViewBag.shapeData">
                <e-layersettings-shapesettings fill="#C1DFF5"></e-layersettings-shapesettings>
                <e-layersettings-markers>
                    <e-layersettings-marker visible="true" shape="Balloon" height="20" width="20" animationDuration="0"
                                            dataSource="ViewBag.markerData"></e-layersettings-marker>
            </e-layersettings-markers>
        </e-maps-layer>
    </e-maps-layers>
</ejs-maps>
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);
        }
    }
}