当前位置:网站首页>Principle analysis of ArcEngine print view and layout view
Principle analysis of ArcEngine print view and layout view
2022-04-22 14:23:00 【ShirmyMao】
Arcengine Principle analysis of print view and layout view
1.LayoutControl And MapControl View synchronization
1.1. View synchronization
/// <summary>
/// The map view is synchronized with the data view
/// </summary>
/// <param name="mapcontrol"></param>
/// <param name="layoutControl"></param>
public static void CopyMapToLayput(AxMapControl mapcontrol,AxPageLayoutControl layoutControl)
{
if (mapcontrol is null) return;
layoutControl.ActiveView.Clear();
IObjectCopy objectCopy = new ObjectCopyClass();
var from = objectCopy.Copy(mapcontrol.Map);
object to = layoutControl.ActiveView.FocusMap;
objectCopy.Overwrite(from, ref to);
layoutControl.ZoomToWholePage();
}
1.2. principle

copy front ,mapcontrol.extent Equal to the range of the red box on the figure (range), However copy The display range has changed after , This is because copy There is no change in the front and back scale , namely
- LayoutControl.ActiveView.FocusMap.MapScale = mapcontrol.MapScale .
therefore copy after ,
- The width of the red frame =range.Width / mapcontrol.MapScale * 100( centimeter );( about 5.9743461756502541 centimeter )
- Height of red frame =range.Height / mapcontrol.MapScale * 100( centimeter ); about (6.9638472610237478 centimeter )
Compared with the properties of the data frame ,copy The rear layout view is centered as shown in the figure above

Use the code to find that the attribute of the data frame in the figure above is :
var lw = pMapFrame.MapBounds.Width / pMapFrame.MapScale*100;
var lh = pMapFrame.MapBounds.Height / pMapFrame.MapScale * 100;
1.3. Print view zooms to the visible range of a map view
from 1.2 The principle analysis of , To keep the print view consistent with the data view range , It needs to be adjusted by comparing the example ruler , Generally, small changes are used to adapt to the whole range ( Adapt with large changes , The other side is out of range ), The code is as follows :
/// <summary>
/// Range adaptation
/// </summary>
/// <param name="env"></param>
/// <returns></returns>
private IEnvelope CalExtent(IEnvelope env)
{
IEnvelope result = new EnvelopeClass();
var pGraphicsContainer = LayoutControl.ActiveView as IGraphicsContainer;
IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(LayoutControl.ActiveView.FocusMap);
// The length and width of the data frame of the actual display element
var lw = pMapFrame.MapBounds.Width / pMapFrame.MapScale*100;
var lh = pMapFrame.MapBounds.Height / pMapFrame.MapScale * 100;
//mapcontrol The length and width of
var mw = env.Width;
var mh = env.Height;
/// copy The front and back scales remain unchanged ,
/// So calculate the width of the actual database (lw centimeter ) And the width on the project scope width drawing (mw / mapcontrol.MapScale * 100 centimeter ) The ratio of the
var d1 = lw / (mw / mapcontrol.MapScale * 100);
/// Highly similar
var d2 = lh / (mh / mapcontrol.MapScale * 100);
/// Adjust the range of the whole map with small changes
var d=Math.Min(d1, d2);
LayoutControl.ActiveView.FocusMap.MapScale = mapcontrol.MapScale / d;
if (Scalces.Count() > 4)
Scalces.Remove(Scalces.LastOrDefault());
var scale = $"1:{
LayoutControl.ActiveView.FocusMap.MapScale.ToString("F3")}";
Scalces.Add(scale);
SelectedScale = scale;
Marshal.ReleaseComObject(pGraphicsContainer);
return result;
}
The adaptation results are shown in the figure below :

2.LayoutControl Point extraction on Mapcontrol The points on the
private void LayoutControl_OnMouseDown(object sender, IPageLayoutControlEvents_OnMouseDownEvent e)
{
var point = CalMapPoint(e.pageX, e.pageY);
}
/// <summary>
/// LayoutControl The point on the push back mapcontrol The actual position on the
/// </summary>
/// <param name="pageX"></param>
/// <param name="pageY"></param>
/// <returns></returns>
private IPoint CalMapPoint(double pageX,double pageY)
{
///copy Before the map mapcontrol.Actiview.Extent
/// Since adaptation has been made , therefore vb≠ Current mapcontrol.Actiview.Extent
var vb = mapcontrol.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;
//frame The actual pixel size for the map control , Corresponding to the current mapcontrol.Actiview.Extent
//var frame = mapcontrol.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
var pMapFrame = (IMapFrame)LayoutControl.ActiveView.GraphicsContainer.FindFrame(LayoutControl.ActiveView.FocusMap);
// The length and width of the data frame of the actual display element
var lw = pMapFrame.MapBounds.Width / pMapFrame.MapScale * 100;
var lh = pMapFrame.MapBounds.Height / pMapFrame.MapScale * 100;
//mapcontrol Distance on the road /layoutcontrol The distance on the graph
double mapDisPerCm;
IPoint point = new PointClass();
///mapcontrol Partial width , The width shall prevail
if (vb.Width / lw > vb.Height / lh)
{
mapDisPerCm = vb.Width / lw;
// The actual height on the map ( centimeter )
var mapHeightCm = vb.Height / mapDisPerCm;
//vb The lower left corner is layoutcontrol The corresponding coordinates on ( Relative to the lower left corner of the whole paper )
var lxCm = (Width - lw) / 2;
var lyCm = (Height - mapHeightCm) / 2;
//e.pageX It means the whole A4 The lower left corner of the paper , Larger than the data frame
var mapX = vb.XMin + (pageX - lxCm) * mapDisPerCm;
var mapY = vb.YMin + (pageY - lyCm) * mapDisPerCm;
point.PutCoords(mapX, mapY);
}
///mapcontrol High , The height shall prevail
else
{
mapDisPerCm = vb.Height / lh;
// The actual width on the map ( centimeter )
var mapWidthCm = vb.Width / mapDisPerCm;
//vb The lower left corner is layoutcontrol The corresponding coordinates on ( Relative to the lower left corner of the whole paper )
var lxCm = (Width - mapWidthCm) / 2;
var lyCm = (Height - lh) / 2;
//e.pageX It means the whole A$ The lower left corner of the paper , Larger than the data frame
var mapX = vb.XMin + (pageX - lxCm) * mapDisPerCm;
var mapY = vb.YMin + (pageY - lyCm) * mapDisPerCm;
point.PutCoords(mapX, mapY);
}
return point;
}
版权声明
本文为[ShirmyMao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221421352088.html
边栏推荐
- HashTable哈希表与统计594、350、|554、609、454、18
- spark代码 spark-submit提交yarn-cluster模式
- C语言的三子棋,用22天总结了一份完美的SQL学习笔记
- Binarytree练习二叉树层序遍历 || 用队列实现层序遍历
- CRM系统改善客户体验的方法
- Move blog to CSDN
- Completion of minmao e-commerce in 10 days - Implementation of user module (2nd day)
- 20道25K+Android工程师面试必问面试题,网易Android面试必问
- ArcGIS版本更新对比
- 知识就是力量,但更重要的是运用知识的能力---网页端微信扫码支付-技术设计
猜你喜欢

有了飞项这款任务管理神器,工作更便捷高效

Completion of minmao e-commerce in 10 days - Implementation of user module (2nd day)

BinaryTree练习 从前序与中序、中序与后序遍历序列构造二叉树||重构二叉树654、105、106

BitMap BloomFilter BitSet详解

Deep understanding of read-write lock reentrantreadwritelock and concurrent container copyonwritearraylist

系列解读 SMC-R (二):融合 TCP 与 RDMA 的 SMC-R 通信 | 龙蜥技术

Bitmap bloomfilter BitSet details

Thread pool--

3. fiddler证书安装和抓取hettps设置

GIS与数学
随机推荐
asp.net framework配置swagger并支持上传文件
移动端自适应与响应式布局
VDO虚拟数据优化
Why do I like to use flying items for task management
Binarytree exercises constructing binary trees from traversal sequences of front order and middle order, middle order and back order | reconstructing binary trees 654, 105 and 106
深入理解Condition
双指针快慢指针||快乐数、寻找重复数202、287、|141、142、143、234、457
CorelDRAW插件-CPG插件开发-环境搭建-VS2017-TLB文件-CDR插件
2020 popular whole network series: This is a very suitable Android advanced - interview key and difficult data notes for collection and collection! Continuously update the high-quality interview links
How to get tuphub Today's hot list and heat?
arcengine读取栅格闪退
Solve command line is too long Shorten command line for........ error
Double pointer 𞓜 ordered array to reorder the linked list and remove elements 26, 27 and 83
ArcGIS版本更新对比
Blocking queue-
字符串的反转练习 344、541、557、151
天梯赛--L2-003 月饼 (25 分)
知识就是力量,但更重要的是运用知识的能力---网页端微信扫码支付-技术设计
2D conversion (move: translate, rotate: rotate, scale: scale, 2D conversion synthesis)
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA