请教各位:
如何将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 ;
}