Use Mo in VC

Source: Internet
Author: User

Overview: MapObjects is a secondary GIS development product of ESRI.
There are two major companies in the GIS industry. One is ESRI, and the other is MapInfo.

In ESRI, all their GIS products are called ArcGIS. Including:
ArcIMS is used to publish GIS to the Internet. It also supports JSP and other development.
ArcSDE is a path for storing and managing multi-user space databases in the database management system.
Simply put, it is an online map server.
ArcView is used for core plotting and GIS functions.
Arceditor includes all the functions of acrview and adds the ability to edit spatial databases.
ArcInfo includes ArcView, arceditor, and advanced space processing capabilities. Is a complete GIS Data creation, update, query drawing and analysis system.
ArcObjects and MapObjects are the secondary development component tools of ESRI. ArcObjects is more powerful than Mo. ArcView is developed using AO.
The new ESRI product has an ARCserver that registers some features as some webservers. Reduces the number of development times.

In Mapinfo, their map editing software is MapInfo. The component for secondary development is MapX.

Before using Mo, you need to understand some of these basic concepts. The MO display uses a mo control. It can load layers, zoom in, zoom out, and so on.
Each layer corresponds to a table and a SHP file. This table stores the attribute information of all the point and line planes in this layer. We can render the layer so that some points can display its attribute information. This is the so-called annotation.
You can also find some SHP in the layer to locate it.

1. Load MapObjects to the project first.
2. Find the three files in the installation directory. It encapsulates some common operations of MapObjects. We can directly use these function libraries to reduce our code .. Under the/samples/mfc/common/directory: maphelper. cpp, maphelper. H, mapobjects2.h.
3. Start to load layers. You can create a map folder under the directory of your exe program to save the map files that need to be added to this program. Use the addlayer function in the function library to load layers.
4. Zoom in, zoom out, and roam. Map the mouse click event and call several methods to implement three functions.

Switch (m_ncurrid)
{
Case id_map_zoomin:
{
Cmorectangle R (m_map.trackrectangle ());
If (lpdispatch (r ))
{
M_map.setextent (R );
}
}
Break;
Case id_map_zoomout:
{
Cmorectangle R (m_map.getextent ());
R. scalerectangle (1.5 );
M_map.setextent (R );
}
Break;
Case id_map_pan:
{
M_map.pan ();
}
Case id_map_label:
{
}
Break;
Default:
Break;
}

5. How to find a SHP in the layer.
// Query Functions
Void cmodemoview: findshape (cstring searchtext)
{

// The query statement indicates the name, =, and field in the table to be found in this layer...
Cstring expression;
Expression. Format ("(name like '% S %')", searchtext );

// Find the layer we want to query
Cmolayers layers (m_map.getlayers ());
Cmomaplayer layer (layers. Item (colevariant (text ("label1 "))));

// Start querying in this layer
Cmorecordset RECs (layer. searchexpression (expression ));
 
// If the query is successful
If (recs. geteof ())
{
: Messagebeep (mb_iconhand );
}
Else
{
// Obtain the shape file from the record set
Cmofields fields (recs. getfields ());
Cmofield shapefield (fields. Item (colevariant (text ("shape "))));

// The shape file is a vertex object.
Cmopoint shape (shapefield. getvalue (). pdispval );
Cmorectangle R (m_map.getfullextent ());

// Get a fixed proportion. The vertex object is located in the center.
R. scalerectangle (0.01999 );
M_map.setextent (R );
M_map.centerat (shape. getx (), shape. Gety ());

// Trigger this point three times
M_map.refresh (); // force redraw
M_map.flashshape (shape, 3 );

}
}
6. How to display the SHP attribute in the layer. As annotation.
// Find this layer
Cmolayers layers (m_map.getlayers ());
Cmomaplayer lable1 (layers. Item (colevariant (text ("label1 "))));
 
// Create a New Annotation object
Cmolabelplacer labelplacer;
Labelplacer. createdispatch ("mapobjects2.labelplacer ");

// Select the name field as the Annotation
Labelplacer. setfield (text ("name "));
Labelplacer. setdrawbackground (false );
Labelplacer. setallowduplicates (false );
Labelplacer. setplaceabove (false );
Labelplacer. setplacebelow (false );
Labelplacer. setplaceon (true );
Labelplacer. setsymbolheight (m_map.getfullextent (). getheight ());

// Set the font for this annotation object
Cmotextsymbol textsymbol (labelplacer. getdefasymsymbol ());
Cmofont fnt;
Fnt. setname (text (" "));
Fnt. setsize (10 );
Textsymbol. setfont (fnt );

Associate a annotation object with a layer object
Lable1.setrenderer (labelplacer );

7. How to map points, lines, and surfaces in an existing Layer
First, define a storage point, line, and surface vector.
For the main functions of writing such code in the click function, see the annotation:
// Obtain a dynamic Layer
Cmotrackinglayer tlayer (m_map.gettrackinglayer ());
Case id_map_ranger:
{
// Add a vertex object
Cmorectangle rect (m_map.trackrectangle ());
If (lpdispatch (rect ))
{
// Save to the object Array
M_rects.push_back (rect );
}

// Trigger dynamic layer re-painting
Variant var;
Var. Vt = vt_dispatch;
Var. pdispval = rect. m_lpdispatch;

Tlayer. Refresh (true, VAR );
}
Break;
Case id_map_point:
{
Cmopoint point (m_map.tomappoint (float) x, (float) y ));
If (lpdispatch (point ))
{
M_points.push_back (point );
}

Cmorectangle R;
R. createdispatch (text ("mapobjects2.rectangle "));

R. setbottom (point. Gety ());
R. settop (point. Gety () + 1.0 );

R. setleft (point. getx ());
R. setright (point. getx () + 1.0 );

R. scalerectangle (50.0 );
Variant var;
Var. Vt = vt_dispatch;
Var. pdispval = R. m_lpdispatch;

Tlayer. Refresh (true, VAR );
}
Break;
Let's take a look at how to write the redraw function for this dynamic layer.
Cmosymbol sym;
If (! Sym. createdispatch ("mapobjects2.symbol "))
Return;
Sym. setcolor (mopurple );

//
// Draw points
//
Sym. setcolor (mored );
Sym. setsymboltype (mopointsymbol );
Sym. setstyle (mocirclemarker );
For (INT I = 0; I <m_points.size (); I ++)
M_map.drawshape (m_points [I], sym );
 
//
// Draw points
//
Sym. setcolor (moblue );
Sym. setsymboltype (mofillsymbol );
Sym. setstyle (mograyfill );
For (I = 0; I <m_rects.size (); I ++)
M_map.drawshape (m_rects [I], sym );

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.