Hello Oli,
a prospect asked me for a codesample about "connecting the xServer.NET control to xMap2".
Where can we find some samples?
Best regards Bernd
Codesample xMap2 with MapControl available?
- Bernd Welter
- Site Admin
- Posts: 2703
- Joined: Mon Apr 14, 2014 10:28 am
- Contact:
Codesample xMap2 with MapControl available?
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany
Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning...
Technical Partner Manager Developer Components
PTV Logistics - Germany
Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning...
- Oliver Heilig
- Posts: 160
- Joined: Tue May 13, 2014 12:10 pm
- Location: Karlsruhe, Germany
- Contact:
Re: Codesample xMap2 with MapControl available?
Oookay,
Here's the sample how to use xMapServer(-internet)-2 with xServer.NET. You can download the sample program or get the source code at https://github.com/ptv-logistics/xservernet-bin (XSTwo).
Basic considerations
The sample code uses the xMapServer-2 tile-api with the xServer.NET generic RemoteTiledProvider. There are two basic methods, depending on the application content you want to show on the map. As xMapServer-2 supports zoom-levels up to 22, you should set the option
at the startup of the application.
1. Use xMap2 as single base-map layer
This method just adds the xMap2 as one single base-map layer. It is comparable to the Leaflet sample https://xserver2-europe-eu-test.cloud.p ... ve_map.htm
2. Add two separate basemap-layers
The second method uses two layers for building up the basemap. Application content can then be rendered in-between these xMap layers. It is comparable to the Leaflet sample https://xserver2-europe-eu-test.cloud.p ... m_data.htm
Here's the sample how to use xMapServer(-internet)-2 with xServer.NET. You can download the sample program or get the source code at https://github.com/ptv-logistics/xservernet-bin (XSTwo).
Basic considerations
The sample code uses the xMapServer-2 tile-api with the xServer.NET generic RemoteTiledProvider. There are two basic methods, depending on the application content you want to show on the map. As xMapServer-2 supports zoom-levels up to 22, you should set the option
Code: Select all
// set the inifinite zoom option to allow high zoom levels for xMap-2
Ptv.XServer.Controls.Map.GlobalOptions.InfiniteZoom = true;
1. Use xMap2 as single base-map layer
This method just adds the xMap2 as one single base-map layer. It is comparable to the Leaflet sample https://xserver2-europe-eu-test.cloud.p ... ve_map.htm
Code: Select all
// center and radius for our map
var center = new Point(8.4044, 49.01405);
// the maixum zoom level of the map
formsMap1.MaxZoom = 22;
// set the map center to Karlsruhe
formsMap2.SetMapLocation(center, 16);
// insert base map layer
formsMap1.Layers.Add(new TiledLayer("Background")
{
TiledProvider = new RemoteTiledProvider
{
MinZoom = 0,
MaxZoom = 22,
RequestBuilderDelegate = (x, y, z) => string.Format("https://s0{0}-xserver2-europe-test.cloud.ptvgroup.com/services/rest/XMap/tile/{1}/{2}/{3}?storedProfile={4}&xtok={5}",
"1234"[(x ^ y) % 4], z, x, y, "silkysand", myToken)
},
IsBaseMapLayer = true, // set to the basemap category -> cannot be moved on top of overlays
Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png"),
Caption = MapLocalizer.GetString(MapStringId.Background),
Copyright = "PTV, TOMTOM"
});
// add custom layer
var myLayer = new ShapeLayer("MyLayer");
formsMap1.Layers.Add(myLayer);
AddCircle(myLayer, center, 435);
The second method uses two layers for building up the basemap. Application content can then be rendered in-between these xMap layers. It is comparable to the Leaflet sample https://xserver2-europe-eu-test.cloud.p ... m_data.htm
Code: Select all
// center and radius for our map
var center = new Point(8.4044, 49.01405);
// the second map instance is initialized with two basemap layers
formsMap2.MaxZoom = 22;
// set the map center to Karlsruhe
formsMap2.SetMapLocation(center, 16);
// add a base layer with only background and transport
formsMap2.Layers.Add(new TiledLayer("Background")
{
TiledProvider = new RemoteTiledProvider
{
MinZoom = 0,
MaxZoom = 22,
RequestBuilderDelegate = (x, y, z) => string.Format("https://s0{0}-xserver2-europe-test.cloud.ptvgroup.com/services/rest/XMap/tile/{1}/{2}/{3}?storedProfile={4}&layers=background,transport&xtok={5}",
"1234"[(x ^ y) % 4], z, x, y, "silkysand", myToken)
},
IsBaseMapLayer = true, // set to the basemap category -> cannot be moved on top of overlays
Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png"),
Caption = MapLocalizer.GetString(MapStringId.Background),
Copyright = "PTV, TOMTOM"
});
// now a custom shape layer in-betwee background and labels
var myLayer = new ShapeLayer("MyLayer");
formsMap2.Layers.Add(myLayer);
AddCircle(myLayer, center, 435);
// now add the labels overlay layer
formsMap2.Layers.Add(new TiledLayer("Labels")
{
TiledProvider = new RemoteTiledProvider
{
MinZoom = 0,
MaxZoom = 22,
RequestBuilderDelegate = (x, y, z) => string.Format("https://s0{0}-xserver2-europe-test.cloud.ptvgroup.com/services/rest/XMap/tile/{1}/{2}/{3}?storedProfile={4}&layers=labels&xtok={5}",
"1234"[(x ^ y) % 4], z, x, y, "silkysand", myToken)
},
Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Labels.png"),
Caption = MapLocalizer.GetString(MapStringId.Labels),
Copyright = "PTV, TOMTOM"
});
Oliver Heilig
Chief Developer Logistic Services
PTV GROUP - Germany
https://github.com/oliverheilig/
Chief Developer Logistic Services
PTV GROUP - Germany
https://github.com/oliverheilig/