Ticket T419111
Visible to All Users

How to implement the Refresh method for a custom list editor that shows Google Maps in XAF ASP.NET application

created 9 years ago

[DevExpress Support Team: CLONED FROM T195734: How to use Google Maps in XAF ASP.NET application]
Hello Dennis,

I used the following custom list editor,

C#
using BeYat.BusinessObjectsLibrary.Helpers; using DevExpress.Data; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Web; using DevExpress.Web; using DevExpress.Xpo; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.UI.WebControls; namespace BeYat.Module.Web.Editors { [ListEditor(typeof(IGoogleMapsMarker), true)] public class ASPxGoogleMapsListEditor : ListEditor { public ASPxGoogleMapsListEditor(IModelListView model) : base(model) { } protected override void AssignDataSourceToControl(object dataSource) { //IListSource listSource = (IListSource)dataSource; //IListServer listServer = (IListServer)listSource.GetList(); //IList rows = listServer.GetAllFilteredAndSortedRows(); WebWindow.CurrentRequestWindow.RegisterClientScript(Model.Id + "_markers_script", ConvertToJS(Enumerable.Cast<IGoogleMapsMarker>((IEnumerable)dataSource)), true); } protected override object CreateControlsCore() { return CreateGoogleMapControl(); } public static string ConvertToJS(IGoogleMapsMarker marker) { List<IGoogleMapsMarker> markers = new List<IGoogleMapsMarker>(); if(marker != null) { markers.Add(marker); } return ConvertToJS(markers); } public static string ConvertToJS(IEnumerable<IGoogleMapsMarker> markers) { string markersScript = "var markers = ["; if(markers != null) { foreach(IGoogleMapsMarker marker in markers) { string title = (marker.Title == null) ? "" : marker.Title.Replace("'", "\\'"); //markersScript += string.Format(@"{{ title: '{0}', latitude: {1}, longitude: {2} }},", title, marker.Position.Latitude, marker.Position.Longitude); markersScript += string.Format(@"{{ title: '{0}', latitude: {1}, longitude: {2} }},", title, marker.Position.Latitude.ToString().Replace(",", "."), marker.Position.Longitude.ToString().Replace(",", ".")); } } markersScript = markersScript.TrimEnd(','); markersScript += "];"; return markersScript; } public static WebControl CreateGoogleMapControl() { Panel ctrl = new Panel(); ctrl.ID = "map-canvas"; ctrl.Height = Unit.Percentage(100); ctrl.Width = Unit.Percentage(100); ASPxPanel geoMapControlPanel = new ASPxPanel(); geoMapControlPanel.ID = "MapPanel"; geoMapControlPanel.Height = new Unit(600); geoMapControlPanel.Width = Unit.Percentage(100); geoMapControlPanel.Controls.Add(ctrl); geoMapControlPanel.Load += delegate(object sender, EventArgs e) { geoMapControlPanel.ClientSideEvents.Init = @" function ShowMap() { //create empty LatLngBounds object var bounds = new google.maps.LatLngBounds(); var infowindow = new google.maps.InfoWindow(); var mapOptions = { center: new google.maps.LatLng(" + GoogleMapsDefaults.MapCenterLatitude.ToString().Replace(",", ".") + ", " + GoogleMapsDefaults.MapCenterLongitude.ToString().Replace(",", ".") + @"), zoom: 6, }; var map = new google.maps.Map(document.getElementById('" + ctrl.ClientID + @"'), mapOptions); if (typeof markers === 'undefined') { } else { for (i = 0; i < markers.length; i++) { var data = markers[i] var latlng = new google.maps.LatLng(data.latitude, data.longitude); var marker = new google.maps.Marker({ position: latlng, map: map, title: data.title }); //extend the bounds to include each marker's position bounds.extend(marker.position); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i)); } //now fit the map to the newly inclusive bounds map.fitBounds(bounds); } }"; }; return geoMapControlPanel; } public override DevExpress.ExpressApp.Templates.IContextMenuTemplate ContextMenuTemplate { get { return null; } } public override IList GetSelectedObjects() { return new object[0]; } public override void Refresh() {} public override DevExpress.ExpressApp.SelectionType SelectionType { get { return DevExpress.ExpressApp.SelectionType.None; } } } }

and now I tried to add a couple of Filters on the ListView but when I switch from one to the other the Map doesn't refresh. But If I press refresh it works as expected.
Can you tell me how I can implement the Refresh method, because I tried the following and it doesn't work.

Thank you

C#
private ProxyCollection collection; private WebControl control; public override void Refresh() { if (collection != null) { collection.Refresh(); } if (control != null) { // nor WebControl nor AspxPanel have a refresh method } }
Comments (1)
DevExpress Support Team 9 years ago

    Anthony,

    Thank you for the detailed information.  We need additional time to research it.  We will get back to you once we have any results or need extra information.  Your patience is appreciated.

    Answers approved by DevExpress Support

    created 9 years ago (modified 9 years ago)

    Hello Anthony,
    I have attached a modified sample project that illustrates how you can refresh this data source when filter is changed.
    Please clarify whether you experience difficulties with migrating to the latest version and using Maps Module or you prefer to use the older version with your project?

      Show previous comments (1)
      DevExpress Support Team 9 years ago

        You're always welcome, Anthony.
        Thank you for the clarification.

          Hi Alexey,

          I eventually ended up to use the Maps List Editor because I had several issues.
          Now my issue with refreshing the view correctly is back when I apply a filter…

          can you help?

          Dennis Garavsky (DevExpress) 9 years ago

            Hello Anthony,

            Since you have started to use a totally different solution, would you please submit a separate ticket via the https://www.devexpress.com/Support/Center/Question/Create service and attach your debuggable sample there so we can see exactly which filters (custom or the built-in ListView | Filters node?) and which List Editor (custom or the built-in WebMapsListEditor  or WebVectorMapsListEditor?) you are using. This will help us avoid misunderstandings, replicate and research the unwanted behavior faster. We want to help you and look forward to researching your case. Thanks.

            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.