Download presentation
Presentation is loading. Please wait.
Published byDelphine Boisvert Modified over 6 years ago
1
Jun Liang, Geography @ UNC
Lecture 4 An example for changing a layer’s Name Before you write code for this purpose, you will need to know: The two default objects, which you can use without create, or define them – Application, and ThisDocument The general path you can reach a layer object from the two existing objects. 2018/11/21 Jun Liang, UNC
2
Changing a layer’s Name (Cont.)
Application MxDocument * Map * Layer FeatureLayer RasterLayerr 2018/11/21 Jun Liang, UNC
3
Changing a layer’s Name (Cont.)
Which layer? To simplify the task, we will work on the first layer, from current map (focus map) (1) Initial Variable: ThisDocument(MxDocument) (2) To work with focus map, you will need to use IMxDocument interface. Please check MxDocument class, and find the interface which includes “focusMap” property. (3) To access focus map object, you will need to define a IMap (Why?) interface variable, and initialize it with… 2018/11/21 Jun Liang, UNC
4
Changing a layer’s Name (Cont.)
(4) Now you can access layer objects through IMap interface variable (pMap). Check IMap definition in OMD and see how you can access the first layer. (5) Before you can access the first layer object in focus map, you need to define a Layer interface variable, which one if you want to change its name? Check it from Map Layer Object Model. Here an ILayer interface variable is needed. (6) Initialize the pLayer interface variable using pMap. (7) pMxDoc.UpdateContents is necessary to update TOC. 2018/11/21 Jun Liang, UNC
5
A little more than changing name
Instead of changing an arbitrary layer’s name from current active map, you will list available maps and ask user to choose, and then list available layers and ask user to choose, then ask user to type a new name for that layer. 2018/11/21 Jun Liang, UNC
6
Jun Liang, Geography @ UNC
Tools Recall you can create four different UI controls from customize window: Button (Examples – buttons to change background color) Tool EditBox ComboBox What is the difference between button and tool? 2018/11/21 Jun Liang, UNC
7
Reporting Coordinates
What will you choose to report mouse’s coordinates? Button or Tool? Add some data to your Arcmap document. Create a tool and add a MouseDown event procedure for it. Use MsgBox to report its X & Y coordinates. 2018/11/21 Jun Liang, UNC
8
Reporting Coordinates (Cont.)
Notice – MouseDown event only reports coordinates in pixels. If you want to report coordinates in map units, you will need to use ArcObjects programming. Coclass Point and its Interface Ipoint MxDocument class (its Object – ThisDocument) has CurrentLocation (IPoint), which will report coordinates in map units. So how can you access this property? 2018/11/21 Jun Liang, UNC
9
Reporting Coordinates (Cont.)
Access CurrentLocation fron ThisDocument object: Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pPoint As IPoint Set pPoint = pMxDoc.CurrentLocation MsgBox “Longitude: “ & pPoint.X & “, Latitude: “ & pPoint.Y You may also change cursor’s look by using _CursorID Function You can change _CursorID’s value to refer to different cursor 2018/11/21 Jun Liang, UNC
10
Reporting Coordinates (Cont.)
Show Message in status bar: IStatus is a member of Application Class. (Check diagram to see their relationship). And you can access Istatus by the following line: Dim pStatus As IStatusBar Set pStatus = Application.StatusBar pStatus.Message(0) = “Latitude: “ & pPoint.y & “, Longitude: “ & _ pPoint.x You may test the code in the mousemove event procedure. 2018/11/21 Jun Liang, UNC
11
Jun Liang, Geography @ UNC
Drawing Graphics Graphics belong to Element abstract class, and both maps and pagelayouts are composed of Elements. Each has an IGraphicsContainer interface with methods. MxDocument * IGraphicContainer Map IGraphicContainer PageLayout * * Element Element 2018/11/21 Jun Liang, UNC
12
Drawing Graphics (Cont.)
Geometry Element Color Symbol GraphicElement FrameElement LineElement TextElement MarkerElement PolygonElement To make graphics on a map, you create objects out of the coclass under GraphicElement. 2018/11/21 Jun Liang, UNC
13
Drawing Graphics (Cont.)
Point Geometry Line Polygon Suppose you want to create a marker element to mark a city, what will be the procedures to do this? 2018/11/21 Jun Liang, UNC
14
Drawing Graphics (Cont.)
TextSymbol Symbol ArrowMarkerSymbol MarkerSymbol SimpleMarkerSymbol LineSymbol CartographicLineSymbol SimpleSymbol FillSymbol SimpleFillSymbol 3DChartSymbol BarChartSymbol 2018/11/21 Jun Liang, UNC
15
Using TypeOf Statements
You might receive “type mismatch” error if you write code for a vector layor/dataset, when the user tries to apply it to a raster layer/dataset. This can be prevented by using TypeOf statement: If TypeOf pLayer Is IRasterLayer Then ……………. Else …………….. EndIf 2018/11/21 Jun Liang, UNC
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.