How can I select a symbol without having to click in the exact center?

Jun 19, 2012 at 2:57 PM

When I put the map in selection mode, the only way to select a symbol is clicking in its exact center. How can I select it clicking in any point of the symbol area?.

 

Thanks.

Jun 20, 2012 at 1:23 AM

I also want to know the answer,any one can help?

Jun 21, 2012 at 12:05 PM
you can try the code below for a test, and test it whether server your need!
private void map1_MouseClick(object sender, MouseEventArgs e)
        {           

            System.Drawing.Point p = e.Location;
            int x=p.X-50;
            int y=p.Y-50;
            int x1=p.X+50;
            int y1=p.Y+50;
            Coordinate c = map1.PixelToProj(p);
            Coordinate c1=map1.PixelToProj(new System.Drawing.Point(x,y));
            Coordinate c2=map1.PixelToProj(new System.Drawing.Point(x1,y1));
            IEnvelope env = new Envelope(c1.X, c2.X, c1.Y, c2.Y);
            IEnvelope env1 = new Envelope(c);
            bool selected = map1.Select(env, env1);
            if (selected)
            {
                DotSpatial.Topology.Point fp = new DotSpatial.Topology.Point(c.X, c.Y);   
                dfs.AddFeature(fp);    //dfs is a featureset for show what have selected, it is the featureset of the drawinglayer
                map1.Refresh();
            }

        }

Jun 27, 2012 at 1:59 PM

I'll try to test it this afternoon. I will let you know the results. Thank you very much.

Jul 3, 2012 at 10:49 AM
Edited Jul 3, 2012 at 10:50 AM

It seems to work m8. It's working quite well for me.

Only one question, is there a envelope associated to the symbol with this code (so symbol envelope is bigger than a single point)? or it works associating a envelope to the mouse pointer, so it's easier to intersect the mouse pointer envelope with the symbol envelope (which continues to be a single point)?.

I ask you this because I'm going to join symbols with lines and I'm afraid I'll not be able to select only lines or only symbols correctly. Do you know what I mean?.

Thanks!.

Jul 4, 2012 at 1:32 AM

well ,the function of selecting feature which dotspatial has supplied is the code of map.functionmode=functionmode.select.  It works like this,first click the map to get a point location, second drag the mouse to contain the feature ,third click again to get another point location ,after the three steps it creating a rect maybe call extent or envelope, and the feature itself there is also a extent or envelope ,the two envelope if intersected then the feature be selected!

So my code also do like this ,but I just calculate the extent for approximate rather than to drag the mouse to calculate the extent!

why not test it for yourself, just create layer which contain lines join with symbols and use this code to test!

Jul 6, 2012 at 12:58 PM

Yes it works quite well with lines too. Now the problem is that I realise that my map has symbols with differents sizes so the selection trick is not working properly with the small or big ones because is too easy (or too difficult) to the mouse pointer envelope to touch the center point of the symbol.

Is there any other way to add an image (with its envelope from drawing dimensions) in certain coordinates of certain featureset/layer?¿ It would be great for my purposes.

Jul 10, 2012 at 11:35 AM
Edited Jul 10, 2012 at 11:53 AM

SOLVED! I found a way to change a point symbolizer envelope:

 

        PF_OFF_AT_FS.Features(0).EnvelopeSource = CacheTypes.Cached
        PF_OFF_AT_FS.Features(0).Envelope.Minimum.X = -25
        PF_OFF_AT_FS.Features(0).Envelope.Minimum.Y = -50
        PF_OFF_AT_FS.Features(0).Envelope.Maximum.X = +25
        PF_OFF_AT_FS.Features(0).Envelope.Maximum.Y = +50

 

(PF_OFF_AT_FS is my featureset)

 

In this way you don't have to use workarounds (associating a envelope to the mouse pointer) when selecting symbols, only set the right envelope size for them and it will let you select clicking in their entire area. It's very important to set the envelope source to cached, otherwise dotspatial fixes the envelope size to a single point.

For selecting I'm using selectionmode.intersectsextent, like this:

 

Map1.[Select](env, env, SelectionMode.IntersectsExtent, Map1.Extent.ToEnvelope)

(env is an square envelope of only 2x2 size)

 

Thank you all for the advices.

 

P.D. Edited to change envelope minimums to negative values and solve bottom-left selection issues.

Jul 10, 2012 at 11:45 AM

well, have you tried to edit the maplayer,for example, try to move the feature or add/remove a feature to a exsisted featureset ?

Jul 10, 2012 at 12:08 PM
Edited Jul 10, 2012 at 12:09 PM

I'm not planning to move features in my app. It's about an SCADA where the SCADA panel generates itself from inventory data on a SQL table.

In the case of changes in the inventory, it would reset the entire map/panel and draw it again from scratch. Anyway I have this sub to delete features from its ItemID (from datatable) if needed:

 

 

Private Sub DeleteItem(ByVal ItemID As String)
        Dim layer As MapPointLayer = Nothing
        layer = DirectCast(Map1.Layers(0), MapPointLayer)
        Dim featureSetRows As DataRowCollection = PF_OFF_AT_FS.DataTable.Rows
        For i As Integer = 0 To featureSetRows.Count - 1
            If featureSetRows(i).ItemArray(0).ToString() = ItemID Then
                Dim f As IFeature = PointF.FeatureFromRow(featureSetRows(i))
                layer.DataSet.Features.Remove(f)
            End If
        Next
End Sub

 

If you move a feature you will have to update its envelope changing x,y,maximums,minimums,etc... for example:

 

Private Sub MoveFeature()
        Dim coord1 As New Coordinate(100, 100)
        PF_OFF_AT_FS.Features(0).Coordinates(0) = coord1
        PF_OFF_AT_FS.Features(0).Envelope.X = 100
        PF_OFF_AT_FS.Features(0).Envelope.Y = 100
        PF_OFF_AT_FS.Features(0).Envelope.Minimum.X = 75
        PF_OFF_AT_FS.Features(0).Envelope.Minimum.Y = 50
        PF_OFF_AT_FS.Features(0).Envelope.Maximum.X = 125
        PF_OFF_AT_FS.Features(0).Envelope.Maximum.Y = 150
        Map1.Refresh()
End Sub

 

 

Jul 12, 2012 at 1:06 AM

well Pachis, can you tell me how to save the mappointlayer with the point as a picturesymbol. I try to add a point with a picturesymbol in a mappointlayer, I succeed, but while i use the featureset.save() method after adding and reopen the mappointlayer the picturesymbol disappear, i don't know why,which make me frustration! I will very pleased to hear from you! thanks in advance!

Jul 12, 2012 at 10:21 AM
Edited Jul 12, 2012 at 10:31 AM

Wich is the content of the save file? Open it with notepad for example.

Jul 16, 2012 at 3:47 AM

I have sovled the problem already,it is due to the code if (featureLayer.Symbology.NumCategories > 1),so it can't show only point feature with picturesymbol!

change the code like follow: if (featureLayer.Symbology.NumCategories >= 1),it can show now!