I have implemented this code to create point event layer by xy text file.
However, I'm wondering how to create a point graphic by xy value?
This script draws point graphic by mouse down. When I steer away from the mouse down event and input my xy values manually it does not draw.
Using the Point class looks like it might also be a solution, however I'm not sure how to implement this code without getting a null reference error on point.setX line.
Dim point As New Point()
point.setX(-100.0)
point.setY(40)
Dim markerElement As New MarkerElement()
markerElement.setGeometry(point)
Dim map As IMap = mxdoc.FocusMap
Map.addElement(markerElement, 0)
2 Answers 2
In the ArcGIS Resource Center is a discussion about Working with map elements which gives you an example on how to create a Point:
Dim point As IPoint = New PointClass()
point.X = 0
point.Y = 0
Then you can use the AddGraphicToMap snippet to draw the graphic on the map using the supplied colors.
The API you are using looks like a mix of VB.NET and JavaScript or according to one of your links. If you are using VB.NET turn on Option Explicit and Option Strict and I'd bet you get some errors.
The IPoint interface doesn't expose 'setX' in .NET. You need to call:
point.X = 0
point.Y = 0
The complete code would look like:
Dim map As ESRI.ArcGIS.Carto.IMap = mxdoc.FocusMap
Dim point As IPoint = New ESRI.ArcGIS.Geometry.Point()
point.SpatialReference = map.SpatialReference
point.X = -100
point.Y = 40
Dim rgbColor As ESRI.ArcGIS.Display.IRgbColor = New ESRI.ArcGIS.Display.RgbColor()
rgbColor.Blue = 200
AddGraphicToMap(map, point, rgbColor, rgbColor)
Explore related questions
See similar questions with these tags.