This project is read-only.

How to Load the [Measure Plugin] & create a ribbon button in Devexpress Ribbon or other ribbon

Nov 7, 2012 at 1:09 AM
Edited Nov 7, 2012 at 1:10 AM

My Question is:

How to Load the [Measure Plugin] which is an UI Plugin & create a ribbon button in Devexpress Ribbon or other ribbon?? without implementing the (IDocManager, IHeaderControl, IstatusControl).

I need to control my custom interface rather than using your provided Header Controls.

For Example: I need to use the (DevExpress) components (Docking control, Statusbar, Ribbon) instead of using the 3 interfaces.

I checked the following tutorials:

1- (How to Support Loading Extensions in DotSpatial).

2- (Composing an Application by Cominbing Extensions).

3- (How to Load DotSpatial Extensions Into My Toolbar)

But i could not understand how to create a (ribbon button) in the (DevExpress Ribbon)  which in the (MainForm) dynamically when activating the plugin and link this ribbonButton with its Click Event to load the (Measure UI Form).

Nov 8, 2012 at 7:19 AM

Hi,

I am using the Windows Ribbon Framework to create my own user interface.

Imports DotSpatial.Plugins.Measure

 With Map1
                .FunctionMode = FunctionMode.None
                'if was already added, remove and add again (otherwise, displays prior graphic measurements)
                For Each mapfunc As IMapFunction In .MapFunctions
                    If TypeOf mapfunc Is MapFunctionMeasure Then
                        .MapFunctions.Remove(mapfunc)
                        Exit For
                    End If
                Next
                
                mf = New MapFunctionMeasure(Map1)
                
                .MapFunctions.Add(mf)
                .Cursor = Cursors.Cross

                mf.Activate()
            End With

Nov 10, 2012 at 6:35 PM

Thanks ambiente

 

it works good but i could not use this method with other extensions like (ADE, Shape editor, tiles webmap, ...)

 

if you please have a solution for this problem kindly reply me.

 

Thanks in advance

 

best regards

Nov 19, 2012 at 12:26 PM

Hi Ahmedgis

looking inside the dotspatial sources for plugins.shapeeditor, which is written in c#, I could get my own buttons able to create a new shape file, and add shapes to it.

I first translated the source codes I found in ButtonHandler.cs in vb.net (my working language), then in my toolbar I created a couple of buttons pointing to addshape and newshapefile subs implemented as reported in the followings (You need to import dotspatial.plugins.shapeeditor so you need to reference it in your project)

 

    Private _AddShapeFunction As AddShapeFunction
    Private _activeLayer As IFeatureLayer
    Private _addShape As SimpleActionItem
    Private _disposed As Boolean
    Private _moveVertexFunction As MoveVertexFunction
    Private _doSnapping As Boolean = True

    'Subroutine called when addshape button is clicked	
    Private Sub addshape_Click_1(sender As System.Object, e As System.EventArgs) Handles ToolStripButton8.Click
        If Map1 Is Nothing Then
            Return
        End If

        If Map1.Layers.SelectedLayer IsNot Nothing Then
            _activeLayer = TryCast(Map1.Layers.SelectedLayer, IFeatureLayer)
        End If
        If _activeLayer Is Nothing Then
            Return
        End If

        If _AddShapeFunction Is Nothing Then
            _AddShapeFunction = New AddShapeFunction(Map1) With { _
           .Name = "AddShape" _
            }
        End If
        If Map1.MapFunctions.Contains(_AddShapeFunction) = False Then
            Map1.MapFunctions.Add(_AddShapeFunction)
        End If
        Map1.FunctionMode = FunctionMode.None
        Map1.Cursor = Cursors.Hand


        UpdateAddShapeFunctionLayer()

        _AddShapeFunction.Activate()

    End Sub

    Private Sub UpdateAddShapeFunctionLayer()
        _AddShapeFunction.FeatureSet = _activeLayer.DataSet
        SetSnapLayers(_addShapeFunction)
    End Sub

    Private Sub SetSnapLayers(func As SnappableMapFunction)
        func.DoSnapping = Me._doSnapping
        If Not Me._doSnapping Then
            Return
        End If

        For Each layer As IMapLayer In Map1.Layers
            Dim fl As IFeatureLayer = TryCast(layer, IFeatureLayer)
            If fl IsNot Nothing AndAlso fl IsNot _activeLayer AndAlso fl.DataSet.FeatureType <> _activeLayer.DataSet.FeatureType Then
                func.AddLayerToSnap(fl)
            End If
        Next
    End Sub

    'subroutine called when newshapefile button is clicked
    Private Sub newshapefile_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton12.Click
        Dim dlg As New FeatureTypeDialog()
        If dlg.ShowDialog() <> DialogResult.OK Then
            Return
        End If
        Dim fs As New FeatureSet(dlg.FeatureType)
        If Map1.Projection IsNot Nothing Then
            fs.Projection = Map1.Projection
        End If
        fs.CoordinateType = dlg.CoordinateType
        fs.IndexMode = False

        Dim layer As IMapFeatureLayer = Map1.Layers.Add(fs)
        layer.EditMode = True
        Map1.Layers.SelectedLayer = layer
        layer.LegendText = Map1.Layers.UnusedName("New Layer")

    End Sub

these are not the complete ShapeEditor functionalities, since I didn't need the movevertex function, but the point is that you can 
simply find how to implement every plugin in your customized toolbar simply looking on how they are called in the dotspatial sourcecode.
I didn't find another way to do it, maybe there is a better one, however this works good enough for me.

Hope you find it useful
Oscar
Nov 19, 2012 at 12:33 PM

Hi Oscar

Thanks for your code, I'll try it and informing you with the results

 

Thanks

Jan 24, 2013 at 11:46 AM

Hi Oscar

Any idea how to call the Label Setup of a layer from a ribbon button.

I tried this with no success

_labellayer = CType(Map1.Layers(0), MapPolygonLayer).LabelLayer
            Dim lableSetupDialog = New LabelSetup() With {.Layer = _labellayer}
            lableSetupDialog.Show()

this is the code from FeatureLayerEventReceiver.cs

  private static void FeatureLayerLabelSetupClicked(object sender, LabelLayerEventArgs e)
        {
            lableSetupDialog = new LabelSetup { Layer = e.LabelLayer };
            lableSetupDialog.Show();
        }

Thank you

Thomas

 

Jan 24, 2013 at 12:12 PM

I tried with this and it works. Placed a button, and on this buttonclick I execute the following code

    Private Sub ToolStripButton17_Click(sender As Object, e As EventArgs) Handles ToolStripButton17.Click
        Dim fl As IFeatureLayer

        If Map1.Layers.SelectedLayer IsNot Nothing Then
            fl = TryCast(Map1.Layers.SelectedLayer, IFeatureLayer)
            If fl IsNot Nothing Then
                Dim dlg As LayerDialog = New LayerDialog(fl, New FeatureCategoryControl())
                dlg.ShowDialog()
            End If
        End If

    End Sub

Hope it is what you're looking for

Oscar

Jan 24, 2013 at 12:40 PM

Hi Oscar,

What I am looking for is to open the Label Setup dialog, your code for the Layer Dialog works fine but the label Dialog has no parameter.

I only can pass the property .labellayer but it do not work.

Here I tried to ajust your code for the label setup

 Dim fl As IFeatureLayer

            If Map1.Layers.SelectedLayer IsNot Nothing Then
                fl = TryCast(Map1.Layers.SelectedLayer, IFeatureLayer)
                If fl IsNot Nothing Then
                    Dim dlg As LabelSetup = New LabelSetup With {.Layer = fl.LabelLayer}
                    dlg.ShowDialog()
                End If
            End If

This gives me an System.NullReferenceException at LabelSetup.cs

 private void UpdateCategories()
        {
            lbCategories.SuspendLayout();
            lbCategories.Items.Clear();
            foreach (ILabelCategory cat in _layer.Symbology.Categories)
            {
                lbCategories.Items.Insert(0, cat);
            }
            lbCategories.ResumeLayout();
        }

Any idea how I can show the Label Setup for the selected layer.

Thank you

Thomas

Jan 24, 2013 at 1:12 PM

debugging your code it sais that fl.labellayer is nothing hence the nullreference

but I don't know how to create a labellayer connected to your featurelayer

Oscar

Jan 25, 2013 at 9:27 AM

Hi Oscar,

Now the code open the Label setup but I cannot apply the Label settings. Nothing is shown on the map, no error message.

If I open the label setup via the layer context menu the dialog shows the same way but I can apply the labels.

Here my code:

 Dim fl As IFeatureLayer
            Dim ll As ILabelLayer

            If Map1.Layers.SelectedLayer IsNot Nothing Then
                fl = TryCast(Map1.Layers.SelectedLayer, IFeatureLayer)

                If fl IsNot Nothing Then
                    ll = New MapLabelLayer(fl)
                    Dim dlg As LabelSetup = New LabelSetup With {.Layer = ll}
                    dlg.ShowDialog()
                End If
            End If

Jan 28, 2013 at 9:13 AM

Hi Ambiente,

I don't know exactly how to proceed, but I think you should look into LabelSetup.cs code.

There I found the following

        protected virtual void OnChangesApplied()
        {
            if (ChangesApplied != null) ChangesApplied(this, new EventArgs());
            _original.CopyProperties(_layer);
            _original.CreateLabels();

            // We have no guarantee that the MapFrame property is set, but redrawing the map is important.
            if (_original.FeatureLayer.MapFrame != null)
                _original.FeatureLayer.MapFrame.Invalidate();
        }

I think you should check if the eventhandler ChangesApplied is null or not... but to be onest this is above my knowledge how to deal with it

Oscar