MapObject Control Use Change Layer Color

zhaozj2021-02-16  51

MapObject Control Use Change Layer Color

Author: Zhangsong Wei

Zswying@163.com

If your land country is displaying a "China Map" layer, each province in the layer is the same, do you want to make the same effect as a real map, give each province with colors ? Ok, let's get started.

Note that be sure to make sure you have data and fields identifying each province in your "Middle Map" layer data (you can see in ArcMap), because only the area can be distinguished, and now we have a map The layer name is CHINA, identifies the fields of each province for NAME. Ok, add a function of changing the color in your program.

Void CMapCortrol :: changechinacolor ()

{

CMORECORDSET RECS; // Recording set

CMOStrings strs; // Mo string class

strs.createdISPATCH ("MapObjects2.strings");

// Get the record of the Name field in the layer data, saved in STRS.

CMOMAPLAYER LAY = M_Map.getlayers (). Item (Colevariant ("China");

Recs = lay.getRecords ();

While (! recs.geteof ())

{

CMOFIELDS MFS = Recs.Getfields ();

Cmofield MF = MFS.ITEM (Colevariant ("name");

CString s = mf.get_value (). BSTRVAL;

strs.add (s);

Recs.movenext ();

}

// Change the region color

CMOVALUEMAPRENDERER VMREND;

VMREND.CREATEDISPATCH ("MapObjects2.ValuemaPrenderer");

VMRend.SetValuecount (strs.getcount ());

VMRend.setfield ("name");

For (int i = 0; i

{

// Take the saved province with VMRend

Variant V;

V.vt = vt_i2;

V.ival = i;

VMREND.SETVALUE (I, strs.Item (V));

/ / Take the province name and judgment

IF (vMrend.getValue (i) == "Beijing" || VMREND.GETVALUE (i) == "Shanghai" ||

VMREND.GETVALUE (i) == "Jiangxi Province" || VMREND.GETVALUE (i) == "Sichuan Province")

{

VMREND.GETSYMBOL (I) .SetColor (RGB (239, 252, 230));

}

Else if (VMREND.GETVALUE (i) == "Anhui Province" || VMREND.GETVALUE (i) == "Heilongjiang" ||

VMRend.getValue (i) == "Liaoning Province" || VMREND.GETVALUE (i) == "Guangxi Zhuang Autonomous Region" ||

VMREND.GETVALUE (i) == "Taiwan" || VMREND.GETVALUE (i) == "Gansu Province" ||

VMREND.GETVALUE (i) == "Tianjin" || vMrend.getValue (i) == "Shanxi Province") {

VMREND.GETSYMBOL (i) .SetColor (RGB (241, 232, 252);

}

Else IF (i) == "Shandong Province" || VMREND.GETVALUE (i) == "Shaanxi Province ||

VMREND.GETVALUE (i) == "Hunan Province" || VMREND.GETVALUE (i) == "Hainan" ||

VMREND.GETVALUE (i) == "Macau" || VMREND.GETVALUE (i) == "Hong Kong")

{

VMRend.getsymbol (i) .SetColor (RGB (252, 237, 248);

}

Else IF (VMREND.GETVALUE (i) == "Henan Province" || VMREND.GETVALUE (i) == "Inner Mongolia Autonomous Region ||

VMREND.GETVALUE (i) == "Fujian Province" || VMREND.GETVALUE (i) == "Guizhou Province" ||

VMREND.GETVALUE (i) == "Qinghai Province")

{

VMREND.GETSYMBOL (i) .SETCOLOR (RGB (252, 251, 235);

}

Else IF (VMREND.GETVALUE (i) == "Jiangsu Province" || VMREND.GETVALUE (i) == "Tibet Autonomous Region")

{

VMREND.GETSYMBOL (I) .SETCOLOR (RGB (252, 230, 246);

}

Else IF (vMrend.getValue (i) == "Jilin Province" || VMREND.GETVALUE (i) == "Hebei Province" ||

VMREND.GETVALUE (i) == "Zhejiang" || VMREND.GETVALUE (i) == "Hubei Province" ||

VMREND.GETVALUE (i) == "Guangdong" || VMREND.GETVALUE (i) == "Xinjiang Uygur Autonomous Region" || VMRend.getValue (i) == "Yunnan" || VMREND.GetValue (i) == "Ningxia Hui Autonomous Region")

{

VMREND.GETSYMBOL (i) .SetColor (RGB (245, 252, 252);

}

// Set the color of the provincial boundary

VMREND.GETSYMBOL (i) .SETOUTLINECOLOR (RGB (185, 185, 185);

}

Lay.seRenderer (VMRend);

m_map.refresh ();

}

OK, call this function after adding the layer, see if it is very beautiful? I am limited, you are welcome to criticize.

转载请注明原文地址:https://www.9cbs.com/read-24294.html

New Post(0)