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

翻译稿

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

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

}

CMoRecordset recs(states.SearchExpression(expression));

//

// Beep if not found. Otherwise, show the first state // found by zooming in and flashing. //

if (recs.GetEof()) ::MessageBeep(MB_ICONQUESTION); else { CMoFields fields(recs.GetFields()); CMoField shapeField(fields.Item(COleVariant(TEXT(\ CMoPolygon shape(shapeField.GetValue().pdispVal); CMoRectangle r(shape.GetExtent()); r.ScaleRectangle(2); m_map.SetExtent(r); // zoom to the state m_map.Refresh(); // force redraw m_map.FlashShape(shape, 3); }

21

The search code first builds a simple SQL query expression using the text from IDC_SEARCHEDIT. Then the States layer is searched using the SearchExpression method with the result being a RecordSet object. If the value of the RecordSet's EOF property is False, the RecordSet is positioned on the first record that satisfies the search expression. In that case, the value of the Shape field is obtained for the first record. The Extent of the shape is scaled and then set to be the Extent of the map. The map is then explicitly redrawn using the Refresh method, and finally, the shape is flashed three times.

搜寻码首先建立一个简单的SQL查询表达式IDC_SEARCHEDIT使用文本。然后美国搜索SearchExpression层使用方法和结果是一个记录集对象。如果值的记录集的EOF财产是假的,记录的位置在第一条记录时,满足了搜索的表达。在这种情况下,价值的领域得到形状的第一张唱片。形状的程度,然后将缩减程度的地图。然后这个地图使用显式刷新方法,最后,其形状是闪过三次。

Test your changes

1. 2. 3. 4.

Build the application. Run the application.

Type the name of a state, for example Illinois, into the search field. Press the Search key.

测试你的改变

1。建立应用程序。 2。运行的应用。

3。一个国家的类型的名字,例如伊利诺斯州,在搜寻栏。 4。按搜索关键字。

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

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

Step Five: Displaying map layers based on scale

In this section you will add a new layer to your map and add code which controls whether or not that layer is visible at a given time.

Add another layer

1. Open IDD_EASYMAP_FORM in the resource editor.

2. Right-click the map to display the context menu. Click Properties to show the Map Control property

sheet.

3. Click the Control Tab and then click the Add button and locate the folder where the sample data is

stored.

4. Click the Counties.shp file and then click Open. 5. Click the Counties layer in the list to select it.

6. Click the down arrow to move the Counties layer below the USHigh layer. 7. Click Properties to change the color of the Counties layer. 8. Click OK to dismiss the Layer Properties dialog. 9. Close the property sheet.

If you run your application now you'll notice that every county in the US is displayed. At the full extent, there is no need to display that much detail; so in response to the BeforeLayerDraw event, you will selectively make the Counties and States layers visible or invisible depending on the current extent of the map.

Respond to the BeforeLayerDraw event

1. Use Class Wizard to add a IDC_MAP1 BeforeLayerDraw handler to CEasyMapView. Call it

OnBeforeLayerDrawMap1.

2. Add code to the OnBeforeLayerDrawMap1 procedure:

void CEasyMapView::OnBeforeLayerDrawMap1(short index, long hDC) {

//

// Calculate whether or not counties should be shown //

CMoRectangle extent(m_map.GetExtent());

CMoRectangle fullExtent(m_map.GetFullExtent());

BOOL showDetail = (extent.GetWidth() < (fullExtent.GetWidth() / 4.0));

//

// Set layer visiblility //

CMoLayers layers(m_map.GetLayers());

CMoMapLayer layer(layers.Item(COleVariant(index)));

switch (index) { // counties case 1: layer.SetVisible(showDetail); break; // states case 2: layer.SetVisible(!showDetail); break; } }

The value of the visible property of each layer is based on the current extent of the map. If the width of the current extent is less than or equal to one fourth of the full extent of the map, then the counties will be visible and the states will be invisible. As this code is executed in response to the BeforeLayerDraw event for each layer, the value of the visible field is calculated before drawing occurs.

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

Test your changes

1. Build the application 2. Run the application

3. Zoom into New England and the Counties layer becomes visible.

4. Click the FullExtent button and the Counties are no longer visible.

Step Six: Adding a spatial query tool

In this section you will implement the spatial query tool. You will add code to your application that carries out the query and draws the results onto the map. When you click on the map using the spatial query tool, two searches are performed. The first search is a point proximity search on the USHigh layer. The point is obtained by converting the x and y coordinates of the event, which are in control units, into map units. If the first search is successful, the highway that is found is used as the input to the second search which is performed on the Counties layer. The result of the second search is stored in the variable, CEasyMapView::m_selection.

Add the query code

1. Use the ClassView “Add Member Variable...” menu to add a new private variable to

CEasyMapView (or simply edit MapView.h):

CMoRecordset m_selection;

2. Open mapview.cpp and go to the CEasyMapView::OnMouseDownMap1 method.

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