第一范文网 - 专业文章范例文档资料分享平台

翻译稿

来源:用户分享 时间:2025/6/1 7:10:28 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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.

搜索更多关于: 翻译稿 的文档
翻译稿.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c438bp8e7sv9mzf00wd8d_8.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top