Galaktikasoft

ASPx Google Maps Property Editor

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).

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:

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.

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.