[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
}
}
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.