Ticket T287322
Visible to All Users

WinForms - How to display geospatial information in XAF Views using Google, Bing or OpenStreet maps

created 9 years ago

Hi DevExpress Team !

Based on :
http://dennisgaravsky.blogspot.hu/2015/03/google-maps-integration-in-xaf-web-ui.html and
https://www.devexpress.com/Support/Center/Question/Details/T195734 and
https://www.devexpress.com/Support/Center/Question/Details/T222593.

I would like to use google map in Winforms application.
Is there any possibility to handle this problem ?

thanks for trhe help,
Zoltan

Answers approved by DevExpress Support

created 9 years ago (modified 5 years ago)

Hello Zoltan,

Sure, that is possible. Note that our built-in Maps Module is specific for ASP.NET XAF apps.

To implement maps in a WinForms app, consider the following options:

  1. Embed a standard System.Windows.Forms.WebBrowser control showing the required web page with Google Maps. For more information, see Show a custom form with a map in the WebBrowser control.
  2. Use the Map Control available in the DevExpress WinForms line. For the XAF integration options, please check out the Using a Custom Control that is not Integrated by Default article, which you must be familiar with from your previous tickets. This important article is useful almost in every case where you want to add a custom control that is not included with standard XAF modules. You can find ready examples from XAF customers here: T172371, T357698, Q572992.

The attached project illustrates how to add a map control to DetailView using ControlViewItem in the Application Model (Model.DesignedDiffs.xafml).

XML
... <Views> <DetailView Id="Capital_DetailView"> <Items> <ControlDetailItem Id="MapControl" ControlTypeName="DevExpress.XtraMap.MapControl" Caption="Map" IsNewNode="True" /> </Items> <Layout> <LayoutItem Id="MapControl" ViewItem="MapControl" Index="1" RelativeSize="89.688506981740062" IsNewNode="True" /> ...

A custom Controller configures this map control item in DetailView (CapitalMapDetailViewController.cs).

C#
... protected override void OnActivated() { base.OnActivated(); View.CustomizeViewItemControl<ControlViewItem>(this, (item) => { MapControl map = item.Control as MapControl; if(map != null) { InitializeMap(map); } }, "MapControl"); // This view item identifier is set in the XAFML file for Capital_DetailView. } ...

This control displays European capitals on a vector Bing map.

C#
... MapItem[] GetCapitals() { return View.ObjectSpace.GetObjectsQuery<Capital>().Select( c => new MapCallout() { Text = c.Name, Location = new GeoPoint(c.Latitude, c.Longitude) } ).ToArray<MapItem>(); } ...

The persistent Capital class with map coordinates serves as a data model (initial data is created in Updater.cs).

C#
... CreateCapital("Madrid", 40.4, -3.68); ObjectSpace.CommitChanges(); } public Capital CreateCapital(string name, double latitude, double longitude) { Capital result = ObjectSpace.FirstOrDefault<Capital>(c => c.Name == name); if(result == null) { result = ObjectSpace.CreateObject<Capital>(); result.Name = name; result.Latitude = latitude; result.Longitude = longitude; } return result; } ...

It is important to add the DevExpress.XtraMap and DevExpress.Map.Core assemblies to be able to use these map features.

Search keywords
desktop, windows forms, map control, maps, mapping, Google, geo, location, GIS, XtraMap, Bing, Google Earth

    Comments (2)

      Hi,

      I have got this to work sucesffully in XAF and vb.net based off this exampled and attached project, using my own custom class with the exception of one line of code

      View.CurrentObjectChanged += (s, e) => {
      CenterPointOnMap(map, ViewCurrentObject);

      Is there a equivalent way to add this in VB.net?

      When the object is saved the latitude and longitude are updated via geocoding which works fine but I need that event to fire to update the location on the map

      Thanks

      Dennis Garavsky (DevExpress) 4 years ago

        @Adam Bilcich: I've answered you in WinForms - Maps in VB.NET.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.