Read VC + MapX attribute data

Source: Internet
Author: User
Char clientpath [121];
Getcurrentdirectory (120, clientpath); // obtain the current path
Cstring
M_tempclientpath =
_ T ("");
M_tempclientpath.format ("% S/MAP/gps_status.tab", clientpath); // place the tab file in the directory where the map is located
Cstring
Temppathgst = _ T ("");
Temppathgst. Format ("% S/MAP/untitled. GST", clientpath); // obtain the path of the gallery's GST File
Cmapxfields
FLDS;
If (! FLDS. createdispatch (FLDS. getclsid ()))
// Return
False;
MessageBox ("create field error! ");
Variant
Fieldname; // field name
Fieldname. Vt = vt_bstr;
Cstring
Cstmp; // Chinese field name
Cstmp = _ T ("statusfield ");
Lpctstr lcstmp =
(Lpctstr) cstmp;
Variant
Fieldlength; // Field Length
Fieldlength. Vt = vt_i2;
Fieldlength. ival
= 200;
Long iwidth =
200;
FLDS. addstringfield (lcstmp, iwidth, false );
// Create a variant that
Points to the fields collection just created
Variant vflds;
Vflds. Vt =
Vt_dispatch;
Vflds. pdispval = FLDS. m_lpdispatch;
// Create a new layerinfo
Object
Cmapxlayerinfo
Linfo;
Linfo. createdispatch (linfo. getclsid ());
// Set the layer info type
To type: New table
Linfo. settype (milayerinfotypenewtable );
// Add
Parameters for the new table
Linfo. addparameter ("filespec ",
Colevariant (m_tempclientpath); // tab File
Linfo. addparameter ("name ",
Colevariant ("gps_status"); // layer name
Linfo. addparameter ("fields", vflds );
// Fields
Linfo. addparameter ("overwritefile", colevariant ("1 "));
// Add
New layer to the map

Cmapxlayer
Lyr = m_ctrlmapx.getlayers (). Add (linfo. m_lpdispatch );
MessageBox ("create Layer
Correctly, statuslayer! ");
// The following code checks whether a new layer is added to display the names of all layers.
Cmapxlayers
Layers = m_ctrlmapx.getlayers ();
Int IIi = layers. getcount ();
If
(Iii> 0)
{
For (int iss = 1; ISS <= III; ISS
++)
{
Cmapxlayer
Templayer = layers. Item (ISS );
Cstring
SSS = templayer. getname ();
Afxmessagebox (SSS );
}
}
// Save
The GST
File
// If the GST is not stored, this layer is not added to the GST file the next time it is opened.
// M_ctrlmapx.savemapasgeoset ("", temppathgst );

Method 2: If a layer file already exists, you only need to add the file to the gallery.
For other code, refer to the first example.
To obtain the path of the tab file, go to m_tempclientpath and add a layer.
Cmapxlayer
Lyr = m_ctrlmapx.getlayers (). Add (m_tempclientpath );
Remember to save the GST file at the end; otherwise, you need to add the file next time you open the file.

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.