Adding Shapelayers

Sep 3, 2008 at 9:32 PM
I'm having a problem adding more than one shapelayer; each is contains a single polygon of a county.  I can add either one individually when the application starts up; however if I try to add them both only one will show.

Any ideas????  thanks.....
Developer
Sep 4, 2008 at 12:20 AM
in the project you download from the "Source Code" section...

in the "Prototype" silverlight project, there is a sample of how to add a ShapeLayer...

I added a new button (copied the "Add Polygon" button) so I have 2 on the xaml page (usercontrol) in the progect
then I added another method to handle the click event and just copied and pasted the code from the orginal to the new click event handler... "AddPolygon_Click2"

I changed the points in the second shapelayer to be a different place...

and I am able to click either button and add the shapes onto the map, and both work fine, so I am able to show both, by adding them at different times, via the button clicks.

from the Source Download....

project: DeepEarthPrototype
file: Page.xaml.cs


 

private void AddPolygon_Click(object sender, RoutedEventArgs e)

 

{

 

//Sample Polygon added to the map

 

 

if (shapeLayer == null)

 

{

shapeLayer =

new ShapeLayer { ID = "POLYGONLAYER" };

 

map.Layers.Add(shapeLayer);

}

 

List<Point> points = new List<Point> { new Point(0, 0), new Point(20, 0), new Point(20, 20), new Point(0, 20) };

 

 

Polygon polygon = new Polygon { Points = points };

 

shapeLayer.List.Add(polygon);

}

 

private void AddPolygon_Click2(object sender, RoutedEventArgs e)

 

{

 

//Sample Polygon added to the map

 

 

if (shapeLayer == null)

 

{

shapeLayer =

new ShapeLayer { ID = "POLYGONLAYER" };

 

map.Layers.Add(shapeLayer);

}

 

List<Point> points = new List<Point> { new Point(100, 0), new Point(120, 0), new Point(120, 20), new Point(100, 20) };

 

 

Polygon polygon = new Polygon { Points = points };

 

shapeLayer.List.Add(polygon);

}

Sep 4, 2008 at 1:38 PM
Thanks dotnetnoobie,

I try to add multiple polygons via a loop structure at the start of the application.  To do this,

- I first create multiple shapelayers and add them to the map - works fine.  (Seemed like I had to do this way vs creating shapelayer then adding geometry immediately after or I would get an error of an already existing shapelayer, even though they had different IDs).
- Then I add the geometries to the shapelayers.

Using this approach, I can never get more than one of the layers to show the polygons.  I don't get any errors, I just don't get more than one polygon.

I'm trying to add these polygons through a callback function.  To get the geometries of the polygons, I make a call to a web service that gives me the geometries, then I create a polygon and add it to the map.  Perhaps the callback function is causing the problem with multiple polygons.

For my purposes, I cannot use buttons to add the shapelayers.  I will keep exploring but wonder if you have any additional suggestions.  Thanks again....

Sep 12, 2008 at 3:18 PM

FYI

This problem was solved when I rearranged how I was making my callbacks.