ASPx Google Maps Property Editor

Used for Xafari.Base.GeoPoint type properties to save and display location on the Google map.

The following code snippet demonstrates GeoPointContainer business class that includes several GeoPoint type properties (Point, DemoZoomPoint and DemoMapTypeIdPoint).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class GeoPointContainer : BaseObject
{
    public GeoPointContainer(Session session) : base(session) { }
 
    public override void AfterConstruction()
    {
        base.AfterConstruction();
        this.Point = new GeoPoint();
        this.DemoZoomPoint = new GeoPoint();
        this.DemoMapTypeIdPoint = new GeoPoint();
    }
 
    public String Name { get; set; }
 
    [ValueConverter(typeof (GeoPointConverter))]
    public GeoPoint Point { get; set; }
 
    [ValueConverter(typeof(GeoPointConverter))]
    public GeoPoint DemoZoomPoint { get; set; }
 
    [ValueConverter(typeof (GeoPointConverter))]
    public GeoPoint DemoMapTypeIdPoint { get; set; }
}

GeoPoint type properties are decorated with ValueConverter attribute. Set value of this attribute to GeoPointConverter.

The code behind demonstrates GeoPointConverter class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class GeoPointConverter : ValueConverter
{
    public override object ConvertFromStorageType(object value)
    {
        return GeoPoint.Parse(value);
    }
 
    public override object ConvertToStorageType(object value)
    {
        return value.ToString();
    }
 
    public override Type StorageType
    {
        get { return typeof(String); }
    }
}

Then add controller GoogleMapsViewController that attaches javascript to the Web application. The code of this controller is demonstrated behind.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public partial class GoogleMapsViewController : ViewController
{
    private void CallbackManager_ScriptCreating(object sender, ScriptCreatingEventArgs e)
    {
        ((Page)Frame.Template).ClientScript.RegisterStartupScript(typeof(Page), "mapScript",""); 
    } 
 
    private XafCallbackManager GetCallbackManager() 
    { 
        XafCallbackManager manager = null; 
        if (Frame != null && Frame.Template != null) { 
            var holder = Frame.Template as ICallbackManagerHolder; 
 
            if (holder != null) manager = holder.CallbackManager; 
        } 
 
        return manager; 
    } 
 
    private void Frame_TemplateChanging(object sender, EventArgs e) 
    { 
        var callbackManager = GetCallbackManager(); 
        if (callbackManager != null) callbackManager.ScriptCreating -= CallbackManager_ScriptCreating; 
    } 
 
    private void Frame_TemplateChanged(object sender, EventArgs e) 
    { 
        var callbackManager = GetCallbackManager(); 
        if (callbackManager != null) callbackManager.ScriptCreating += CallbackManager_ScriptCreating; 
    } 
 
    protected override void OnFrameAssigned() 
    { 
        base.OnFrameAssigned(); 
        Frame.TemplateChanging += Frame_TemplateChanging; 
        Frame.TemplateChanged += Frame_TemplateChanged; 
    } 
}

To use ASPx Google Maps Property Editor invoke Model Editor and focus the corresponding BOModel|Class|OwnMembers|Member node, set PropertyEditorType property to the ASPxGoogleMapsPropertyEditor value.

ASPx Google Maps Property Editor

Run the Web application. Select the appropriate item in the navigation control and click the New Action. In the invoked Detail View you can view properties which are displayed by ASPx Google Maps Property Editor. If you change latitude or longitude value, point changes location.

ASPx Google Maps Property Editor
Write US