ThinkGeo.com    |     Documentation    |     Premium Support

Order of drawing Features and skewed map with GeoCanvas

Hi ThinkGeo Forums,

We are having 2 issues with PlatformGeoCanvas.

First, no matter what options/order we add the line and point on the map the line is always over top of the point. I have tried different drawing methods and orders of adding the items with no luck.

Second, we noticed on the PlatformGeoCanvas that the image/projection seems skewed compared to our regular map. Our regular map is on the left and the GeoCanvas on the right.

Any ideas for either of these two? Thank you.

Neil

Hi Neil,

Please show us the code or a simple sample is welcome.

For the 1st question, I don’t understand your question, what’s the mean of the added order and point? Could you please describe it again?

For the 2nd point, if the two line is the same line, that should because different projection, it looks the line still start and end at the same point.

Regards,

Ethan

Hi Ethan,

Sorry for the confusion. My first question is simply we want the circle to be on top of the line. In the image it shows the line on top of the point.

As for the second question, we would need to apply the projection to each of the items added to the canvas?

Here is the code

Dim objBitMap As Bitmap = New Bitmap(300, 300)
Dim objGeoCanvas As PlatformGeoCanvas = New PlatformGeoCanvas()
Dim colLayers As System.Collections.ObjectModel.Collection(Of SimpleCandidate) = New System.Collections.ObjectModel.Collection(Of SimpleCandidate)()
Dim colLineFeatures As System.Collections.ObjectModel.Collection(Of Feature) = New ObjectModel.Collection(Of Feature)()
Dim colPointFeatures As System.Collections.ObjectModel.Collection(Of Feature) = New ObjectModel.Collection(Of Feature)()

    Dim objLine As New LineShape
    Dim objVertex As Vertex
    Dim objImages As ArrayList = mobjViewer.RouteImageArray
    Dim objLatLng As List(Of KeyValuePair(Of String, String)) = mobjViewer.RouteLatLng
    Dim strLon As String = ""
    Dim strLat As String = ""
    Dim strItem As String = ""

    If objImages.Count > 0 Then
        Session.Item("ImagesPath") = ""
    End If

    Dim objProjectionJUR As Proj4Projection = New Proj4Projection()
    objProjectionJUR.InternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString
    objProjectionJUR.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString
    objProjectionJUR.Open()

    For i As Integer = 0 To objImages.Count - 1
        If i > objLatLng.Count - 1 Then Exit For
        Dim strSplit As String() = Split(objLatLng(i).Value.ToString, ",")
        If IsNothing(strSplit) = False Then
            If strSplit.Count < 2 Then
            Else
                strLon = strSplit(0)
                strLat = strSplit(1)
            End If
        End If

        If Val(strLon) <> 0 And Val(strLat) <> 0 Then
            objVertex = objProjectionJUR.ConvertToExternalProjection(CDbl(strLon), CDbl(strLat))
            strLon = objVertex.X.ToString
            strLat = objVertex.Y.ToString
            objLine.Vertices.Add(objVertex)
            'ClientScript.RegisterHiddenField("mp" & objLatLng(i).Key.ToString, strLon & "," & strLat)
        End If
    Next

    'Creates the Point Shape
    Dim pointMap As New MapShape

    For Each objPair As KeyValuePair(Of String, String) In mobjViewer.RouteLatLng
        Dim objKey As String = objPair.Key
        Dim objValue As String = objPair.Value

        If objKey = mstrMPText Then
            Dim strLatLng As String() = objValue.Split(CChar(","))

            pointMap.Feature = objProjectionJUR.ConvertToExternalProjection(New Feature(CDbl(strLatLng(0).ToString()), CDbl(strLatLng(1).ToString())))
            pointMap.ZoomLevels.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(New GeoColor(0, 0, 255), 10, New GeoColor(255, 255, 0), 1)
            pointMap.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
            Exit For
        End If
    Next

    'Creates the Line Shape
    Dim linemap As New MapShape
    Dim ext As RectangleShape

    With linemap
        .Feature = New Feature(objLine)
        .ZoomLevels.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Yellow, 4, True)
        .ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
        ext = .Feature.GetBoundingBox
    End With

    ext.ScaleUp(60)

    'Bing Map

    ' Please set your own information about those parameters below.   
    Dim applicationID As String = "[Your Bing Key]"
    Dim cacheDirectory As String = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data/Bingmaps")

    If Directory.Exists(cacheDirectory) = False Then
        Directory.CreateDirectory(cacheDirectory)
    End If

    cacheDirectory = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data/Bingmaps/StreetPix")

    If Directory.Exists(cacheDirectory) = False Then
        Directory.CreateDirectory(cacheDirectory)
    End If

    'Begins Drawing the Image
    objGeoCanvas.BeginDrawing(objBitMap, ext, GeographyUnit.Meter)

    'Builds Bing Maps Layer
    Dim objLayer As New BingMapsLayer(applicationID, ThinkGeo.MapSuite.Layers.BingMapsMapType.Road, cacheDirectory)
    Dim strKey As String = ""
    objLayer.Logo = Nothing
    objLayer.Name = "Bing Maps"
    objLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException
    objLayer.MapType = ThinkGeo.MapSuite.Layers.BingMapsMapType.AerialWithLabels

    strKey = objLayer.Name.Replace(" ", "") & "Layer"

    objLayer.TileCache = New FileBitmapTileCache(cacheDirectory)
    objLayer.Open()
    objLayer.Draw(objGeoCanvas, colLayers)
    objLayer.Close()

    'objGeoCanvas.DrawLine(linemap.Feature, linemap.ZoomLevels.ZoomLevel01.DefaultLineStyle.CenterPen, DrawingLevel.LevelFour)

    'Adds the Shapes
    'Dim objTempLayer As MapShapeLayer = New MapShapeLayer()
    'objTempLayer.MapShapes.Add("Line", linemap)
    'objTempLayer.Draw(objGeoCanvas, colLayers)
    colPointFeatures.Add(pointMap.Feature)
    pointMap.ZoomLevels.ZoomLevel01.DefaultPointStyle.Draw(colPointFeatures, objGeoCanvas, colLayers, colLayers)
    colLineFeatures.Add(linemap.Feature)
    linemap.ZoomLevels.ZoomLevel01.DefaultLineStyle.Draw(colLineFeatures, objGeoCanvas, colLayers, colLayers)

    'objTempLayer = New MapShapeLayer()
    'objTempLayer.MapShapes.Add("Point", pointMap)
    'objTempLayer.Draw(objGeoCanvas, colLayers)

    objGeoCanvas.EndDrawing()

    'Adds the border around the image
    Dim objBorder As Brush = New SolidBrush(Color.Silver)
    Dim objGraphics As Graphics = Graphics.FromImage(CType(objBitMap, Image))

    'objGraphics.FillRectangle(objBorder, 0, 0, 6, 6)
    objGraphics.DrawLine(New Pen(objBorder, 6), New Point(0, 0), New Point(0, 300))
    objGraphics.DrawLine(New Pen(objBorder, 6), New Point(0, 0), New Point(300, 0))
    objGraphics.DrawLine(New Pen(objBorder, 6), New Point(300, 0), New Point(300, 300))
    objGraphics.DrawLine(New Pen(objBorder, 6), New Point(0, 300), New Point(300, 300))
    Dim objPoint As Point = New Point(0, 0)
    objGraphics.DrawImage(objBitMap, objPoint)

    Return objBitMap

Thanks,

Neil

Hi Neil,

For question 1: I think your point and line should be in the same layer, and you just set the DefaultLineStyle and DefaultPointStyle. And the point feature should be added before the line feature in your data source. So the solution is don’t set the default style, but add line style at first into custom styles and then add the point style into it like this:

        LineStyle line1 = new LineStyle(new GeoPen(GeoColors.DarkBlue, 10));
        PointStyle point1 = PointStyles.City1;

        InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
        //layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = style1;
        //layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = point1;
        
        layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(line1);
        layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(point1);
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        LineShape line = new LineShape();
        line.Vertices.Add(new Vertex(15, 10));
        line.Vertices.Add(new Vertex(21, 16));

        PointShape point = new PointShape(21, 16);

        
        layer.InternalFeatures.Add(new Feature(point));
        layer.InternalFeatures.Add(new Feature(line));
        layerOverlay.Layers.Add(layer);

For question 2:

Please set the projection to layer.FeatureSource.Projection, you don’t need set projection to each feature, assign it to whole layer, it will works.

Regards,

Ethan