Simple Question

Dec 17, 2009 at 3:03 AM

I may just be working too late, but I think this is a simple question.

I'm trying to (from code) place markers at specific points via lats and longs but for the life of me I can't figure out how. Any tips?

Coordinator
Dec 17, 2009 at 7:08 AM

Assuming your using the DEMap control:

            GeometryLayer elementUpdateLayer = new GeometryLayer(map) { UpdateMode = GeometryLayer.UpdateModes.ElementUpdate };
            map.Layers.Add(elementUpdateLayer);
            elementUpdateLayer.Add(new PointBase { Point = new Point(-180, 0) });

You add a layer to the map, we support a few rendering modes for performance.

Add you point to that layer, use our PointBase or create your own custom from it.

The Bing Maps control is similar, let me know if you want a reference for that.

 

Dec 17, 2009 at 7:12 AM

Sorry, I should have clarified, I am using the Bing Maps controls. Could you post an example of that? Thanks! (great controls btw!)

Coordinator
Dec 17, 2009 at 10:24 PM

So the enhancement we bring to the Bing Maps control is the ability to render OGC geometries, for example data from SQL 2008 spatial.

We're using the NetTopologySuite to parse WKB into IGeometry but you can also make your own, here are two examples:

directly to a layer:

            var myLayer = new EnhancedMapLayer
            {
                ID = "Test Data",
                ZIndex = 0,
                MapInstance = map,
                MinZoomLevel = 1,
                MaxZoomLevel = 20
            };
            map.Children.Add(vectorLayer);
            var point = new Point(25, 25);
            var style = new StyleSpecification
                            {
                                ID = "style 3",
                                LineColour = "FFAEAEAE",
                                LineWidth = 1,
                                PolyFillColour = "88ee3355",
                                ShowFill = false,
                                ShowLine = true,
                                IconURL = "http://soulsolutions.com.au/Images/pin.png",
                                IconScale = 1
                            };
            var basegeometry = new BaseGeometry(point, style, map);
            myLayer.AddChild(basegeometry, CoordinateConvertor.ConvertBack(point.Centroid.Coordinate),
                                 PositionOrigin.Center);

add a collection of data as a layer to the layer control:

            var data = new ObservableCollection<VectorLayerData>();
            for (int x = -80;x<=80;x++)
            {
                var point = new Point(x, x);
                data.Add(new VectorLayerData
                             {
                                 Geo = point.AsBinary(),
                                 ID = x.ToString(),
                                 Label = x.ToString(),                             
                                 DateRange = new DateRange
                                                 {
                                                     ValueLow = DateTime.Now.AddHours(x),
                                                     ValueHigh = DateTime.Now.AddHours(x+1)
                                                 },
                                 
                             });
            }

            layerPanel.CreateVectorOverlay(data, args.Layer);

 

What I do is a have a layerdefinition table that defines all the data for each layer, all stored in SQL2008. We have LayerDefinition class setup as a partial class with both server side and client side fields, code on the client is as simple as this:

        private void layerPanel_LoadLayer(object sender, LoadLayerEventArgs args)
        {
            DataServiceClient dataService = Utility.GetMyServiceClient(ServerPath);
            dataService.GetVectorLayerCompleted += dataService_GetVectorLayerCompleted;
            dataService.GetVectorLayerAsync(args.Layer.LayerID, args.Layer);
        }

        private void dataService_GetVectorLayerCompleted(object sender, GetVectorLayerCompletedEventArgs e)
        {
            layerPanel.CreateVectorOverlay(e.Result, (LayerDefinition)e.UserState);
        }

        private void layerPanel_BalloonLaunch(object sender, BalloonEventArgs args)
        {
            var layer = layerPanel.GetLayerDefinitionById(args.LayerID);
            var template = layer.ObjectAttributes[0].ObjectAttributeTemplate;
            DataServiceClient dataService = Utility.GetMyServiceClient(ServerPath);
            dataService.GetItemDataCompleted += (ob, ev) => ((InfoGeometry) ev.UserState).BalloonData.Add(
                                                                DeepEarth.BingMapsToolkit.Client.Controls.Utility.
                                                                    CombineTemplate(ev.Result,template));
            dataService.GetItemDataAsync(args.LayerID, args.ItemID, 0, sender);
        }
On the server we do this:
            var vectorLayerDataList = new List<VectorLayerData>();

            var layerDefinition = GetLayerDefinition(roleID, layerID);
            if (layerDefinition != null)
            {
                using (var sqlConn = new SqlConnection(layerDefinition.LayerConnection))
                {
                    sqlConn.Open();
                    using (var cmd = new SqlCommand(layerDefinition.LayerURI, sqlConn))
                    {
                        SqlDataReader geomRdr = cmd.ExecuteReader();
                        if (geomRdr != null)
                        {
                            while (geomRdr.Read())
                            {
                                //Optional fields.
                                string label = "";
                                string style = "";
                                if (layerDefinition.ObjectHasLabel)
                                {
                                    label = Utilities.ConvertNullString(geomRdr[2]);
                                    if (layerDefinition.ObjectHasStyle)
                                    {
                                        style = Utilities.ConvertNullString(geomRdr[3]);
                                    }
                                }
                                else if (layerDefinition.ObjectHasStyle)
                                {
                                    style = Utilities.ConvertNullString(geomRdr[2]);
                                }

                                vectorLayerDataList.Add(new VectorLayerData
                                                            {
                                                                Geo = Utilities.ConvertNullBinary(geomRdr[0]),
                                                                ID = Utilities.ConvertNullString(geomRdr[1]),
                                                                Label = label,
                                                                Style = style,
                                                            });
                            }
                            geomRdr.Close();
                        }
                    }
                    sqlConn.Close();
                }
            }
            return vectorLayerDataList;