大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 用VC++实现矢量地图背景下的实时显示

用VC++实现矢量地图背景下的实时显示

时间: 2021-07-31 作者:daque

纲要 正文引见了在vc++实行的及时表露体例中,用ole办法嵌入mapinfo矢量舆图的编制程序本领,扼要报告了本来现进程。  一、 媒介  电子舆图运用动作一门新办学科,已不只限于舆图创造中。正文运用vc++和ole(object linking and embedding, 东西贯穿和嵌入)编制程序本领,实行了及时消息在矢量舆图后台上的表露。  步调运用于表露处置结尾,接受并处置搜集消息的局部在各别的体例中有各别的诉求,这边不复赘述。mapinfo矢量舆图用图层办法举行保存和处置,每个图层对应舆图上的一类因素(如住户地,水系,铁路,铁路等),对于每个包括图形消息的图层,须要有4个文献(.dat, .tab, .map, .id)扶助。  mapinfo舆图承诺嵌入一个舆图窗口就任何能接收ole东西的运用步调中。从效劳器(如mapinfo)插入一个ole东西到容器运用步调(如microsoft word),并在该运用步调中对这个东西举行处置。被嵌入的东西是来自效劳器运用步调的东西的一个复本。东西一旦坐落容器中,它将不复被链接到源东西。  在vc++运用步调顶用ole办法嵌入mapinfo过程,需设置了一个mapinfo东西(dmapinfo类),dmapinfo类在mapinfo典型库(mapinfow.tlb)中设置。mapinfo软硬件供给了本人的编制程序谈话mapbasic, vc++对舆图过程的操纵重要经过发送mapbasic吩咐来实行。  二、 创造步调框架  步调框架是用mfc实行的,mfc 运用步调引导(appwizard)天生了大局部的代码,而后介入mapinfo过程。办法如次:  1. 创造一个新名目,名目典型采用mfc appwizard(exe),名目称呼设为mapapp,其它依照提醒举行树立即可。运用步调引导机动天生了三个类:   cmapappapp 运用步调类   cmapappdoc 文书档案类   cmapappview 视图类   cmainframe 主框架类  2. 增添mapinfo典型库  运转类引导,单击减少类按钮(add class …),采用"from a type library",找到"mapinfow.tlb"文献并翻开,在"confirm classes"中采用"dmapinfo"类,单击ok确认输出并封闭对话框。此刻mapapp运用步调中已增添了dmapinfo类,并减少了"mapinfow.h"和"mapinfow.cpp"两个源文献。3. 用ole办法嵌入mapinfo过程  在"mapapp.cpp"中cmapappapp theapp语句底下介入底下的语句:dmapinfo mapinfo; file://mapinfo东西   在cmapappapp::initinstance() 因变量中减少ole的初始化,代码如次:  步调清单1 mapapp.cpp文献bool cmapappapp::initinstance(){if (!afxoleinit()) file://ole初始化{ file://波折afxmessagebox("ole波折!");return false;}if (!mapinfo.createdispatch("mapinfo.application")) file://舆图窗口处置过程{ file://波折afxmessagebox("failed to create mapinfo dispatch class!");file://::messagebox(0, mapinfo.getfullname(), "amazing!", mb_ok);return false;}/*本处简略mfc机动天生的代码*/}   将"mapbasic.h"文献正片到内项手段目次中,在"stdafx.h"中减少以次代码,把mapinfo证明为全部变量:#include "mapbasic.h"#include "mapinfow.h"extern dmapinfo mapinfo; file://全部变量,舆图窗口东西 4. 表露舆图窗口  为cmapappview类减少舆图窗口的标识和句柄变量,在mapappview.h文献中增添如次代码:unsigned long m_lwindowid; file://舆图窗口标识hwnd m_hwindowhwnd; file://舆图窗口句柄   翻开类引导窗口,在class name下拉列表框中采用类cmapappview,object ids列表框中采用cmapappview,messages列表框中采用oninitialupdate,单击add function为cmapappview重载oninitialupdate()因变量,而后在因变量中增添表露舆图窗口的代码。  步调清单2 mapappview.cpp文献void cmapappview::oninitialupdate(){char str[256];cview::oninitialupdate();char str[256];///创造航显底图mapinfo.do("open table \"f:\\province.tab\" readonly interactive");mapinfo.do("open table \"f:\\capitals.tab\" readonly interactive");mapinfo.do("open table \"f:\\china.tab\" readonly interactive");sprintf(str,"set next document parent %lu style 2 ",(long)(uint)m_hwnd);mapinfo.do(str);//创造舆图窗口/*树立舆图窗口的图层,由最上一层发端是华夏边境,各省边境,省城都会,并标明上省城都会的名字*/mapinfo.do("map from capitals, province, china");mapinfo.do("set map layer 1 label with capital_character_name parallel on auto on visibility on");file://获得舆图窗口的id号和句柄m_lwindowid = atol(mapinfo.eval("windowid(0)")); file://窗口idsprintf(str,"windowinfo(0, %u)", win_info_wnd); file://窗口hwndm_hwindowhwnd = (hwnd)atol(mapinfo.eval(str));file://安排舆图窗口尺寸,将舆图窗口安置在右半屏上sprintf(str,"set window %lu position (8.3,0) width 8.4 height 6.05 scrollbars off sysmenuclose off", m_lwindowid);mapinfo.do(str);file://安排舆图窗口视线和重心点double m_dview_center_x=113.35; file://舆图窗口重心点,经纬度double m_dview_center_y=35.04;double m_dview_zoom = 4000.0; file://舆图窗口视线,"km"sprintf(str,"set map window %lu zoom %lf units \"km\" center (%lf,%lf) xy units \"degree\"", m_lwindowid,m_dview_zoom,m_dview_center_x,m_dview_center_y);mapinfo.do(str);//树立舆图窗口重心点窗口视线file://树立舆图窗口遨游缩放的右键菜单mapinfo.do("create menu \"mapshellshortcut\" id 17 as \"遨游\" calling 1702,\"减少\" calling 1706, \"夸大\" calling 1705 ,\"(-\"");file://创造及时航迹表露图层mapinfo.do("create table plane (id integer) file \"f:\\plane.tab\" ");mapinfo.do("create map for plane");sprintf(str,"add map window %lu layer plane animate",m_lwindowid);mapinfo.do(str); file://及时航迹图层树立为赶快革新} 5. 编写翻译运转软硬件,将屏幕表露辨别率树立为1600′1024,则在右半屏展示舆图窗口。此刻剩下的处事不过介入接受目的数据并变换为经纬度保守行及时表露,这边只给出同舆图窗口相关的局部,假如正在连接接受目的数据,写入全部变量中,并向cmapappview类发送动静,挪用cmapappview类的showmapline()因变量。在mapapp.cpp文献中增添全部变量设置:   double global_long;//经度   double global_lat;//纬度   double global_long_last;//上一点经度   double global_lat_last;//上一点纬度   unsigned long global_num; file://接受点计数  在mapapp.h文献中增添全部变量证明:   extern double global_long;//经度   extern double global_lat;//纬度   extern double global_long_last;//上一点经度   extern double global_lat_last;//上一点纬度   extern unsigned long global_num; file://接受点计数  在cmapappview::oninitialupdate()因变量的中断局部增添如次代码://///////////////设置mapinfo中所用的变量mapinfo.do("dim obj1 as object"); file://铁鸟图圈点东西mapinfo.do("dim line1 as object"); file://航迹线东西global_num = 0; file://接受目的数据计数初始化为0   在cmapappview:: showmapline()因变量代码如次:  步调清单3 mapappview.cpp文献void cmapappview::showmapline(){char str[256];file://画铁鸟图标double m_angle = copi*atan2((global_lat - global_lat_last),(global_long - global_long_last))-90;//目的观点sprintf(str,"create point into variable obj1 (%lf,%lf) symbol (85,255,30,\"mapinfo transportation\",0,%lf)",global_long, global_lat, m_angle); file://树立铁鸟目的表露的款式mapinfo.do(str); file://创造目的图标东西if (global_num >0 ){/*收到的第一点,在plane表中插入第一条记载,反面的点都是革新第一条记载*/sprintf(str,"update plane set obj = obj1 where rowid = %lu",1);}else {sprintf(str,"inset into plane (id,obj) values (%lu,line1) ", global_num);}mapinfo.do(str);//用obj1东西革新表中的记载file://画各摆设的航迹sprintf(str,"create line into variable line1 (%lf,%lf) (%lf,%lf) pen makepen(2,2,255)",global_long_last, global_lat_last , global_long, global_lat);mapinfo.do(str);//创造line1东西if (global_num >0 ){//第一个点不画航迹sprintf(str,"fetch last from plane");mapinfo.do(str);file://插入line1到表中sprintf(str,"insert into plane (id,obj) values (%lu,line1)",global_num);mapinfo.do(str);}global_num ++;}   6. 编写翻译运转软硬件,  要生存plane表,可在cmapappview类的析构因变量中增添底下的代码:  步调清单4 mapappview.cpp文献cmapappview::~cmapappview(){char str[256];if (m_hwindowhwnd) file://舆图窗口生存{sprintf(str,"close window %lu",m_lwindowid);mapinfo.do(str);m_hwindowhwnd = null;m_lwindowid = 0l;mapinfo.do("commit table plane");//生存及时航迹表}}   左屏表露实质的结构,可按照各软硬件体例的诉求,表露数据,图表等,由vc++编制程序实行。  三、 其它证明  上头步调清单第22中学sprintf(str,"add map window %lu layer plane animate",m_lwindowid);   语句中的animate属性确定要有,这表白将plane图层树立为动静(animate)图层,每个舆图窗口只能有一个动静图层,当这个图层上的东西变革时,舆图窗口只革新此图层,再不不妨实行赶快革新。  在运用ole本领嵌入舆图窗口的运用中,还可按照须要介入多种东西,用来舆图消息的窜改和查问,如标尺窗口,消息窗口,图层遏制,图层采用编纂等,但在及时接受数据并表露的状况下,有些功效的运用将会引导考察辩论,以至步调堕落,如图层遏制、图层编纂等,因为是及时数据正在对plane表举行编纂,此时再变换其它图层,就与mapinfo一次只能编纂一个图层的规则爆发了辩论。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.