PointSymbolizer size-zoom ratio [Solved] - New problems [Not Solved]

Jun 13, 2012 at 4:47 PM

Hi all, I'm starting mi project with dotspatial, it's about a scada panel for power energy systems wich re-generates itself when there is a change in the power grid topology, so no need the operator to redraw the panel.

I'm trying to generate the one-line diagram of the power grid so I'm drawing symbols (each one with the suitable image) here and there. My main problem is that when I zoom on these symbols, they maintains their size and I don't want that behaviour. It would be great for my purpose that symbols could be zoomed in and out.

On the other hand, I though about adding multiple images on one imagelayer but I don't find the way. In this case, furthermore, due to I have to handle the user clicks on the different symbols/images, I need to retrieve too the FID on selection change.

P.D. Here is my code to handle users click (got it here at dotspatial)

    Private Sub map1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Map1.SelectionChanged
        '  DotSpatial.Data.IFeature feat = map1.GetFeatureLayers()[0].DataSet.GetFeature(0);
        '  this.Text = feat.DataRow.ItemArray.GetValue(0).ToString();
        Dim ls1 As New List(Of IFeature)()
        Dim fl1 As FeatureLayer = TryCast(Map1.Layers(0), FeatureLayer)
        Dim il1 As ISelection = fl1.Selection
        Try
            ls1 = il1.ToFeatureList()
            Me.Text = ""
            For i As Integer = 0 To il1.Count - 1
                Me.Text += ls1(i).Fid.ToString() & " , "
                'FID
                'attribute 
                Me.Text += ls1(i).DataRow.ItemArray.GetValue(0).ToString() & " , "
            Next
        Catch
        End Try
    End Sub

P.D. 2 Here is my code to adding symbols, I only have to modify the Location variable as I want
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        PointF.Projection = Map1.Projection
        Dim columnID As New DataColumn("PointID")
        If Not PointF.DataTable.Columns.Contains("PointID") Then
            PointF.DataTable.Columns.Add(columnID)
        End If

        Dim pointLayer As New MapPointLayer(PointF)
        Dim TestImage As Image = Image.FromFile("d:\123.bmp")
        Dim symbol As New PointSymbolizer(TestImage, 200)

        pointLayer.Symbolizer = symbol
        pointLayer.LegendText = "point"
        Map1.Layers.Add(pointLayer)

        If pointmouseClick = True Then
            pointmouseClick = False
            Exit Sub
        End If
        pointmouseClick = True


    End Sub


    Private Sub map1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Map1.MouseDown
        If e.Button = MouseButtons.Left AndAlso (pointmouseClick) Then
            Dim PointID As String = TextBoxID.Text
            Dim coord As Coordinate = Map1.PixelToProj(e.Location)
            Dim point As New DotSpatial.Topology.Point(coord)
            Dim currentFeature As IFeature = PointF.AddFeature(point)
            currentFeature.DataRow("PointID") = PointID
            Map1.ResetBuffer()
        End If
    End Sub

 

 

Jun 14, 2012 at 8:14 AM

I just solved the problem with symbol.ScaleMode = ScaleMode.Geographic (symbol is the pointsymbolizer).

There are two new problems:

The first is about selection mode. Selection only works when I click exactly in the center of the image symbol. I want it to work clicking on the entire image.

The second is about selection too. When I successful select a image symbol, the image itself dissapears and the only thing the map shows is a cyan dot. I would preffer to highlight the image with a surrounding circle or to specify another image for the new selected status.

 

Any advice? Thanks in advance.

Jun 20, 2012 at 2:23 AM

hi Pachis ,when i add a pointsymolizer  using the scalemode to control the image zoom size,there is no image to show on the mapcontrol,but it was added to the mapcontrol, my code is like below:

private void SetPictrue(FeatureLayer fl,FeatureSet fs,IFeature ff)
        {
            PointScheme pointScheme = new PointScheme();
            pointScheme.ClearCategories();
            foreach (IFeature f in fs.Features)
            {
                if (f.Coordinates[0] == ff.Coordinates[0])
                {
                    PictureSymbol pis = new PictureSymbol(deviceImageInfo.DeviceImage, 28);
                    pis.ImageFilename = deviceImageInfo.ImageFileName;                    
                    PointCategory pc = new PointCategory(pis);
                    pc.Symbolizer.ScaleMode = ScaleMode.Geographic;
                    pc.FilterExpression = "[ID]='" + ff.DataRow["ID"].ToString() + "'";
                    pointScheme.AddCategory(pc);
                    continue;
                }
                IFeatureCategory fc = fl.GetCategory(f);
                if (fc==null)
                {
                    continue;
                }
                fc.FilterExpression = "[ID]='" + f.DataRow["ID"].ToString() + "'";
                pointScheme.AddCategory(fc);
            }
            fl.Symbology = pointScheme;
            fl.ApplyScheme(pointScheme);   
        }

 the code above is trying to add mutilple pointsymbolizer in one mappointlayer!

Jun 20, 2012 at 6:17 AM
Pachis wrote:

I just solved the problem with symbol.ScaleMode = ScaleMode.Geographic (symbol is the pointsymbolizer).

There are two new problems:

The first is about selection mode. Selection only works when I click exactly in the center of the image symbol. I want it to work clicking on the entire image.

The second is about selection too. When I successful select a image symbol, the image itself dissapears and the only thing the map shows is a cyan dot. I would preffer to highlight the image with a surrounding circle or to specify another image for the new selected status.

 

Any advice? Thanks in advance.


while I use the code symbol.scalemode=scalemode.geographic to zoom out the pointsymbolizer there is no exception,but while i zoom in them the exception happened!

the exception is System.ArgumentException happen at this code line: Bitmap normalSymbol = new Bitmap((int)(size.Width * scaleSize) + 1, (int)(size.Height * scaleSize) + 1);

I don't know why, So can  you help me out! thanks in advance!

Jun 20, 2012 at 7:17 AM

I can't help you too much, my dotspatial and .net skill are limited. Try with a  Map1.ResetBuffer() after zooming but I can't assure you anything.

Why don't you use my code to adding symbols? I works quite well and you can add multiple pointsymbolizer in one layer I think.

I solved the cyan dot problem when selecting a feature using pointLayer.SelectionSymbolizer = symbol2 (where symbol2 is a picturesymbolizer and pointlayer a MapPointLayer).

For selecting features not only clicking in the center I didn't find any solution yet... :(

Jun 20, 2012 at 8:18 AM

Well the exception is coming from the mapframe.resetbuffer(), so i don't think it can work, and I was using the map.functionmode=functionmode.zoomin or zoomout ,so where should i add the code map.resetbuffer();

Jun 21, 2012 at 9:51 AM
Edited Jun 21, 2012 at 10:34 AM

Is this line of code yours?

 Bitmap normalSymbol = new Bitmap((int)(size.Width * scaleSize) + 1, (int)(size.Height * scaleSize) + 1);

You don't have to worry about resizing symbols if you are using scalemode geographic.I can't help you too much.

Jun 23, 2012 at 2:49 PM
Edited Jun 25, 2012 at 12:47 AM

the code is not mine!

but I add 1000 pointsymbolizer to the mappointlayer,so while I zoom in them the exception happened!

Jun 27, 2012 at 1:57 PM

Sorry mate but I don't know why are you getting that error. As I told you my vb.net and dotspatial skills are very limited, the only thing I can assure you is that using the code I posted I'm not getting any errors yet...