专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > GIS

【新手请问】arcgis engine+c# 怎么在mapcontrol上添加picture

发布时间:2010-06-06 17:16:09 文章来源:www.iduyao.cn 采编人员:星星草
【新手请教】arcgis engine+c# 如何在mapcontrol上添加picture
请教各位:
  如何将picture导入mapcontrol中?

------解决方案--------------------
这需要使用到javascript api,以下是代码

var graphicCount = 0;

function drawGraphic(point)
{
var symbol = new ESRI.ADF.Graphics.MarkerSymbol("images/图片.gif", 8, 8, "");
var coords = point.toString("<br>", ","); 
var attributes = { "ID": graphicCount, "featureCoordinates": coords };
var graphicFeature = $create(ESRI.ADF.Graphics.GraphicFeature, { "id": graphicCount.toString(), "geometry": point, "symbol": symbol, "attributes": attributes});
map.addGraphic(graphicFeature); 
graphicCount++;
}

函数中的point参数在调用时传入,初始化方法如下:

//x和y分别表示当前的经纬度,可在mouseClick事件中设置
var ppp = new ESRI.ADF.Geometries.Point(x,y);
drawGraphic(ppp);

------解决方案--------------------

object missing =Type.Missing ;
IActiveView pActiveView = axMapControl1.ActiveView as IActiveView ;

OpenFileDialog pOpenFileDialog = new OpenFileDialog ();
pOpenFileDialog.Filter ="jpg files (*.jpg)|*.jpg|bmp files (*.bmp)|*.bmp";
pOpenFileDialog.RestoreDirectory=true;

if(pOpenFileDialog.ShowDialog ()==DialogResult.OK ){
 IElement pElement = GetPicture(pOpenFileDialog.FileName);
 IPictureElement pPictureElement;
if( pElement is IPictureElement ){
pPictureElement = pElement as IPictureElement ;
pPictureElement.MaintainAspectRatio =false;
pPictureElement.SavePictureInDocument =true;
}

//图片的大小和显示位置可以通过修改pEnv的坐标来自己决定
IEnvelope pEnv = new EnvelopeClass ();
//pEnv.PutCoords(....)
pEnv = axMapControl1.ActiveView.Extent ;

pElement.Geometry =pEnv as IGeometry ;
axMapControl1.ActiveView.GraphicsContainer.AddElement(pElement,0);
axMapControl1.CtlRefresh(esriViewDrawPhase.esriViewBackground ,missing,missing);
}

private IElement GetPicture(string sPath)
{
 IRasterPicture pRasterPicture = new RasterPictureClass ();
 IOlePictureElement pOlePicture = new BmpPictureElementClass ();
 pOlePicture.ImportPicture (pRasterPicture.LoadPicture (sPath) as stdole .IPictureDisp );
 return pOlePicture as IElement ;
}

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: