翻译稿

发布时间 : 星期五 文章翻译稿更新完毕开始阅读

Getting Started with MapObjects Version 2.x in Visual C++

29

3. Add some layers to the map using the new AddLayer helper function. Make sure you specify the

appropriate path to your data:

void CEasyMapView::OnInitialUpdate() {

CFormView::OnInitialUpdate();

//

// Add data to the map. //

AddLayer(m_map, TEXT(\ AddLayer(m_map, TEXT(\ AddLayer(m_map, TEXT(\}

Test your change

1. Build and run the application

2. Your application should work the same as before

Step Eight: Statistical mapping

In this section you will modify your application so that the Counties layer is drawn using underlying attribute information.

Attach a renderer to the Counties layer

1. Find the CEasyMapView::OnInitialUpdate method in EasyMapView.cpp.

2. Add code to attach a ClassBreaksRenderer to the counties layer.

void CEasyMapView::OnInitialUpdate() {

CFormView::OnInitialUpdate();

//

// Add data to the map. //

AddLayer(m_map, TEXT(\ AddLayer(m_map, TEXT(\ AddLayer(m_map, TEXT(\

//

// Set up county renderer //

CMoLayers layers(m_map.GetLayers());

CMoMapLayer counties(layers.Item(COleVariant(TEXT(\

CMoClassBreaksRenderer cbRenderer; // Create from scratch

cbRenderer.CreateDispatch(TEXT(“MapObjects2.ClassBreaksRenderer\ cbRenderer.SetField(TEXT(\

// calculate breaks away from the mean in both directions,

// but only add those breaks that are within the range of values CMoRecordset recs(counties.GetRecords());

CMoStatistics stats(recs.CalculateStatistics(TEXT(\ double breakVal = stats.GetMean() - (stats.GetStdDev() * 3.0); double min = stats.GetMin(); double max = stats.GetMax(); for (int i = 0; i < 7; i++) { if (min <= breakVal && breakVal <= max) { int breakCount = cbRenderer.GetBreakCount(); cbRenderer.SetBreakCount(breakCount + 1); cbRenderer.SetBreak(breakCount, breakVal); } breakVal = breakVal + stats.GetStdDev();

Getting Started with MapObjects Version 2.x in Visual C++

}

cbRenderer.RampColors(moPaleYellow, moOrange); counties.SetRenderer(cbRenderer); }

30

Each MapLayer object has a Renderer property. A renderer object controls how the MapLayer is drawn. The ClassBreaksRenderer can be used to display continuous data, in this case the number or mobile homes per capita by county.

Attach a renderer to the States layer

1. Modify the CEasyMapView::OnInitialUpdate method.

2. Append code after the code for the Counties renderer.

//

// Set up states renderer //

CMoMapLayer states(layers.Item(COleVariant(TEXT(\CMoDotDensityRenderer ddRenderer; // Create from scratch

ddRenderer.CreateDispatch(TEXT(“MapObjects2.DotDensityRenderer\ ddRenderer.SetField(TEXT(\recs = states.GetRecords();

stats = recs.CalculateStatistics(TEXT(\ddRenderer.SetDotValue(stats.GetMax() / 100.0); states.SetRenderer(ddRenderer);

Test your changes

1. Build and run your application.

2. Look at the States layer. Notice that the polygons are now drawn with dots that indicate the

number of farms.

Getting Started with MapObjects Version 2.x in Visual C++

31

3. Zoom into an area so that the Counties layer becomes visible. Notice that the counties are now

drawn in different colors, depending on the underlying attribute values representing the number of mobile homes in each county.

Getting Started with MapObjects Version 2.x in Visual C++ 32

Step Nine: Event tracking

It is often desirable to display geographic entities on top of the map, especially if those entities have a tendency to move. For example, a vehicle tracking system would want to display vehicles on the map at the appropriate locations and update those locations over time without redrawing all the layers of the map each time a vehicle changes location.

In this section you will add an event tracking layer to your application (though you may have already used this layer to highlight your selected Counties).

Implement the event tool

1. Open EasyMapView.cpp and go to the CEasyMapView::OnMouseDownMap1 method.

2. Implement the ID_MAP_ADDEVENT case:

case ID_MAP_ADDEVENT: { CMoPoint mapPt(m_map.ToMapPoint((float)X, (float)Y)); CMoTrackingLayer tLayer(m_map.GetTrackingLayer()); tLayer.AddEvent(mapPt, 0); } break;

Test the event tool

1. Run your application. 2. Zoom into an area.

3. Click the event tool, then click on the map to add events. We shall cover how to change the

symbol later.

联系合同范文客服:xxxxx#qq.com(#替换为@)