plan9
路人甲
路人甲
  • 注册日期2006-08-08
  • 发帖数8
  • QQ
  • 铜币138枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:995回复:0

VC+AE,分享(2)

楼主#
更多 发布于:2006-08-14 21:31
<P>三,继续,有个MapControl上测距和测面积的问题也一直困扰我。<BR>其实到现在我也还没搞懂测出来的距离是米还是什么其他的距离单位-_-b,先测试啦,慢慢就好了。<BR>解决方法:1,还是直接放代码吧<BR>2,代码:<BR>double CGISTestDlg::LineLength()<BR>{<BR> IActiveViewPtr ipActiveView;<BR> m_ipMapControl->get_ActiveView(;ipActiveView);<BR> IScreenDisplayPtr ipScreenDisplay;<BR> ipActiveView->get_ScreenDisplay(;ipScreenDisplay);<BR> IRubberBandPtr ipRubberLine(CLSID_RubberLine);<BR>//设置线的颜色:红<BR> IRgbColorPtr ipRgbColor(CLSID_RgbColor);<BR> ipRgbColor->put_Red(255);<BR> ISimpleLineSymbolPtr ipLineSymbol(CLSID_SimpleLineSymbol);<BR> ipLineSymbol->put_Color(ipRgbColor);</P>
<P> ISymbolPtr ipSym(ipLineSymbol);<BR> IGeometryPtr ipGeometry;<BR> ipRubberLine->TrackNew(ipScreenDisplay, ipSym, ;ipGeometry);</P>
<P> OLE_HANDLE hDC;<BR> ipScreenDisplay->get_hDC(;hDC);<BR> ipScreenDisplay->StartDrawing(hDC, esriNoScreenCache);<BR> ipScreenDisplay->SetSymbol(ipSym);<BR> ipScreenDisplay->DrawPolyline(ipGeometry);<BR> ipScreenDisplay->FinishDrawing();<BR>//把画出来的PolyLine转成ICurve.<BR> ICurvePtr pCurve = ipGeometry;<BR> double length;<BR> pCurve->get_Length(;length);</P>
<P> CString str;<BR> str.Format("%f", length);<BR> AfxMessageBox(str);<BR> return length;<BR>}<BR>下一个是矩形面积的:<BR>double CGISTestDlg::RectangleArea()<BR>{<BR> IActiveViewPtr ipActiveView;<BR> m_ipMapControl->get_ActiveView(;ipActiveView);</P>
<P> IScreenDisplayPtr ipScreenDisplay;<BR> ipActiveView->get_ScreenDisplay(;ipScreenDisplay);<BR> IRubberBandPtr ipRubberEnv(CLSID_RubberEnvelope);<BR> IRgbColorPtr ipRgbColor(CLSID_RgbColor);<BR> ipRgbColor->put_Red(255);</P>
<P> ISimpleLineSymbolPtr ipFillSymbol(CLSID_SimpleLineSymbol);<BR> ipFillSymbol->put_Color(ipRgbColor);<BR> ISymbolPtr ipSym(ipFillSymbol);<BR> IGeometryPtr ipGeometry;<BR>//上面的代码不起作用,我也不知道为什么。<BR> ipRubberEnv->TrackNew(ipScreenDisplay, ipSym, ;ipGeometry);<BR> IEnvelopePtr ipEnvelope;<BR> ipGeometry->get_Envelope(;ipEnvelope);</P>
<P> OLE_HANDLE hDC;<BR> ipScreenDisplay->get_hDC(;hDC);<BR> ipScreenDisplay->StartDrawing(hDC, esriNoScreenCache);<BR> ipScreenDisplay->SetSymbol(ipSym);<BR> ipScreenDisplay->DrawRectangle(ipEnvelope);<BR> ipScreenDisplay->FinishDrawing();<BR>//用的是IArea接口。<BR> IAreaPtr pArea = ipGeometry;<BR> double ar;<BR> pArea->get_Area(;ar);</P>
<P> CString str;<BR> str.Format("%f", ar);<BR> AfxMessageBox(str);<BR> return ar;<BR>}<BR>四,在mapcontrol的OnMouseDown事件里处理放大缩小地图<BR>解决方法:如下,但是缩小地图怎么才能框选缩小呢。还没想好。<BR> m_MapControl.SetExtent(m_MapControl.TrackRectangle());<BR> m_ipMapControl->get_Extent(;ipExtent);<BR> ipExtent->Expand(0.5, 0.5, VARIANT_TRUE);<BR> m_ipMapControl->put_Extent(ipExtent);<BR>  <BR> m_ipMapControl->get_Extent(;ipExtent);<BR> ipExtent->Expand(1.5, 1.5, VARIANT_TRUE);<BR> m_ipMapControl->put_Extent(ipExtent);</P>
<P>先写这些吧,都是测试代码。</P>
喜欢0 评分0
游客

返回顶部