Design reusable large-granularity GIS components using the event mechanism of Visual Basic

Source: Internet
Author: User
1. introduction The current application of geographic information systems requires the organic integration of GIS and other systems such as MIS and OA. Therefore, most GIS systems are developed with component GIS as the core for secondary development. Therefore, with the rapid development of computer and geographic information technology and the gradual maturity of GIS theories and applications, component technology has gradually become the mainstream of GIS software, this has changed the operating mode of the traditional integrated GIS platform. Representative component GIS includes ArcGIS of ERSI and Supermap object of Beijing Supermap. In the development of component-based GIS, because GIS functions and user interface requirements are customized as needed, most GIS functions need to be called by the underlying GIS components for implementation. Therefore, each development requires coding and implementation of some repeated basic or core GIS functions, which is tedious and error-prone. For example, the map browsing function (including size scaling, roaming, and display control) is required in almost all GIS systems, and its core implementation is based on GIS components. Therefore, during the development process, developers often need to implement similar functions over and over again. This article describes how to encapsulate similar functions into a COM Component Based on VB event mechanism and object delegation. 2. Visual Basic event mechanism Visual Basic is not a good object-oriented language, but in Visual Basic can also be fully developed with properties, methods, events (P-M-E) COM components. The following describes the VB6 event processing process in detail. In VB, the event definition and trigger syntax are as follows: defined in class (class): ○ event definition: event... ○ Event triggering: raiseevent... And customers Code The following syntax is used for event processing: ○ 1. Define the event processing object: dim withevents objectxx as class ○ 2. process the event: private sub objectxx_eventname... In general, end sub does not need to be used for forms and controls because there are default event processing processes, such as form_load events and command1_click events, we only need the corresponding event. However, if there is a command1 button control in a form, we can define the following event processing Program : Private sub command1_click () msgbox "old test" End sub. In addition, we can define another processing process: dim withevents ss as commandbutton private sub ss_click () msgbox "new test" End sub execution shows that both processes can respond to the execution. Therefore, the event processing process defined by withevents can be in a separate module or class to isolate the interface and specific logic of the program. This is the technology that needs to be applied in this article. In fact, for VB.net or C #, the event processing method is not very different from VB6 in form. The difference is that VB6 has the default event processing process, just as VB6 has the default form, you can use form1.show in this way. In VB.net, you must create a form before calling it. 3. by using the above methods and technologies, we will first create a map browsing control that can be reused Based on the Supermap object component GIS of Beijing Supermap company, and a simple project is used to test its correctness. 3.1. You can reuse the Map Browsing control mapview. First, start VB6, create an ActiveX Control Project, add a toolbar control to the project, and add necessary buttons. Next, we need to add a reference to the Supermap object component and add the following declaration to the component code: dim SW as superworkspacedim sm as Supermap private withevents eventsm as Supermap the first and second statements declare the workspace and map object, and the third statement declares the processing object of the map object event. Add a connection method to the control so that the declared workspace and map space point to the actual control in the project: Public Function connect (objsw as object, objsm as object) as Boolean if objsw is nothing or objsm is nothing then connect = false else set Sw = objsw set Sm = objsm set eventsm = Sm connect = true end ifend function where, the input parameters declare the workspace and map as the object type because both controls cannot be created and therefore cannot be declared in the parameters. Other code is very simple, just assign the input control instance to the workspace and map object in the control. Set eventsm = Sm initializes the eventsm object so that the eventsm object can process the events of the map object. Then, for map operations, we can use these two objects (SW and SM. For example, map Scaling :...... Case "zoomin" SM. Action = scazoomincase "zoomout" SM. Action = scazoomout ...... The event processing for the workspace and map object is because the specific event processing object "eventsm" is declared in the control, and the corresponding event can be processed with this object. In the following two processes, when the map is re-painted, the display of the map scale is updated, and the second one is called to display the attributes of the corresponding object after the map object is selected. Private sub eventsm_aftermapdraw (byval HDC as stdole. ole_handle) 'map scale if SM. viewscale <> 0 then combo1.text = "1:" & format (1/SM. viewscale, "#") end ifend sub private sub eventsm_geometryselected (byval nselectedgeometrycount as long) 'displays the attributes of the selected object showobjectinfo smend sub during the display of the call properties, we can encapsulate some code displayed by map browsing in a control, without having to worry about its implementation, as long as it is connected to the actual map and workspace object in the code. 3.2. use the mapview Map Browsing control to create a VB6 project, add the corresponding Supermap object control and mapview control, adjust it to the appropriate location, and add the following code in the formload event: if me. superworkspace1.open ("... ") Then me. supermap1.connect me. superworkspace1.handle me. supermap1.openmap "world" if not me. mapview1.connect (Me. superworkspace1, me. supermap1) Then unload me end ifend if the connection statement between the program and the control only needs "mapview1.connect" to run the program. You can see that the map browsing control has been correctly run, as shown in:

4. conclusion based on the above method, the author applies VB6 to implement a map browsing Control Based on Supermap object. This control only needs to call the connect statement during initialization, connects to the workspace control and map control of Supermap object, allows you to scale, translate, control layers, query attributes SQL, output the current map as an image, and print the current map. This control and its sample code can be downloaded from the author's blog. Using the event processing mechanism of Visual Basic and appropriate object-oriented design, on the one hand, we can encapsulate the GIS functions that are frequently used in project development into independent components, it can greatly speed up development, avoid unnecessary errors, reduce coupling between application logic, program interface, and GIS implementation, and improve development quality. On the other hand, through this method, reasonable division of labor can be done in actual development to improve work efficiency. Code development and testing environments in this article:
    • Windows XP SP1
    • Visual Basic 6 (SP6)
    • Supermap object 3

Http://files.cnblogs.com/maweifeng/MapView.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.