Show me to draw a point in sharpmap using asp.net

Dec 23, 2008 at 5:59 AM
I have simple application which displays a shape file on image button. I want to draw a line on that using the following code but it generates error
 The code:

SharpMap.Layers.VectorLayer VLayer = new SharpMap.Layers.VectorLayer("GeometryLayer");
System.Collections.Generic.List<SharpMap.Geometries.Geometry> GeomColl = new System.Collections.Generic.List<SharpMap.Geometries.Geometry>();
        //Add a single Point
        GeomColl.Add(new SharpMap.Geometries.Point(10, 10));

        //Add a LineString with 2 Points
        System.Collections.Generic.List<SharpMap.Geometries.Point> PointColl = new System.Collections.Generic.List<SharpMap.Geometries.Point>();
        PointColl.Add(new SharpMap.Geometries.Point(10, 10));
        PointColl.Add(new SharpMap.Geometries.Point(20, 20));
        map.Layers.Add(VLayer);

The error:

<title>Object reference not set to an instance of an object.</title> <style> body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } </style>

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 29: 		{
Line 30: 			//This is the initial view of the map. Zoom to the extents of the map:
Line 31:             myMap.ZoomToExtents(); 
Line 32: 			//Save the current mapcenter and zoom in the viewstate
Line 33: 			ViewState.Add("mapCenter", myMap.Center

Thank u in advance
Coordinator
Dec 27, 2008 at 10:51 AM
Hi halson, it looks like you havent initialised the myMap field. It also looks like you have got 2 Map fields in your page 'map' and 'myMap' I guess you should only have one and it needs to be initialised before calling methods or setting properties on it. You would often do this in the Page_Load or even Page_Init event handlers hth jd