Page 1 of 1

Map control with xServer 2 only (how to optimize performance)

Posted: Wed Oct 16, 2024 9:53 am
by Bernd Welter
These days some xServer.NET users asked in the github.
We're using the Map controls (via a FormsMap control) and set the XMapUrl. When it's a xServer 2, it takes a while before the map appears, since it checks first if it's an xServer 1 (the setter of the property actually performs a WebRequest with timeout of 5 seconds. When I know that I have an xServer 2, this wastes some time that the user has to wait before the actual map appears.
This could maybe fixed by a property in Map, e.g. UseXserver2Only or something. @oliverheilig what do you think? Or is there alternative ways to skip the xServer 1 check?

Re: Map control with xServer 2 only (how to optimize performance)

Posted: Thu Oct 17, 2024 7:58 am
by Oliver Heilig
It is possible to skip the automatic initialization/probing by inserting the layers programmatically.

xserver-1

* Initialize the xmap layers explictly, without automatic setup, snippet
* A more lightweight variant is using the REST/API, snippet. This is more efficient if only the basemap layers are needed.

xserver2

xMap-2 can be added as generic tile layer. When Featurelayer-overlays with tooltips are needed, these can be added via the UntiledLayer.

Code: Select all

private void Form1_Load(object sender, EventArgs e)
{
    formsMap1.SetMapLocation(new System.Windows.Point(8.4044, 49.01405), 15);
    formsMap1.MaxZoom = 22;

    string storedProfile = "silkysand";
    string token = "....";

    // Initialize the base map as generic tile layer, but only with background/transport activated
    formsMap1.Layers.Add(new TiledLayer("Background")
    {
        TiledProvider = new RemoteTiledProvider
        {
            MinZoom = 0,
            MaxZoom = 22,
            RequestBuilderDelegate = (x, y, z) =>
                $"https://s0{(x + y) % 4 + 1}-xserver2-test.cloud.ptvgroup.com/services/rest/XMap/tile/{z}/{x}/{y}" +
                $"?xtok={token}&storedProfile={storedProfile}&layers=background,transport"
        },
        IsBaseMapLayer = true,
        Caption = MapLocalizer.GetString(MapStringId.Background),
        Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png"),
        Copyright = $"© {DateTime.Now.Year} PTV Group, HERE, TomTom",
    });

    // The overlays wit FeatureLayer content
    formsMap1.Layers.Add(new UntiledLayer("Labels")
    {
        UntiledProvider = new UntiledProvider
        {
            RequestUriString = "https://xserver2-test.cloud.ptvgroup.com/services/rs/XMap/renderMap",
            StoredProfile = storedProfile,                   
            ThemesForRendering = new[] { "Labels", "PTV_TrafficIncidents" },
            ThemesWithMapObjects = new[] { "PTV_TrafficIncidents" },
            TimeConsiderationScenario = "SnapshotTimeConsideration",
            TimeSpan = 1000,
            ReferenceTime = DateTime.Now.ToString("o"),
            XToken = token,
        },
        Caption = MapLocalizer.GetString(MapStringId.Labels),
        Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Labels.png"),
        Copyright = $"© {DateTime.Now.Year} PTV Group, HERE, TomTom",
    });
}