arcgis for .net 100.1 如何设置地图的边界

需求:例如我设置了地图边界,当鼠标拖拽地图到达地图边界后就无法继续拖拽
如何设置地图的边界?
已邀请:

谢峥

赞同来自: 朱新颖

自己写了点代码,将就着把功能实现了
public partial class MainWindow : Window
{

// 创建加载地图
public MainWindow()
{
InitializeComponent();

// 创建地图
Initialize();
}
List<MapPoint> list = new List<MapPoint>();
Polygon polygon;
Graphic point = new Graphic();
double x1;
double x2;
double y1;
double y2;
private void Initialize()
{
Map myMap = new Map(BasemapType.OpenStreetMap, 40.04, 116.59,10);
MyMapView.Map = myMap;
x1 = 116.59 - 5;
y1 = 40.04 + 5;
x2 = 116.59 + 5;
y2 = 40.04 - 5;
list.Add(new MapPoint(x1,y1 ,SpatialReferences.Wgs84));
list.Add(new MapPoint(x2, y1, SpatialReferences.Wgs84));
list.Add(new MapPoint(x2, y2, SpatialReferences.Wgs84));
list.Add(new MapPoint(x1,y2 , SpatialReferences.Wgs84));
polygon = new Polygon(list);

point.Geometry = new MapPoint(116.59, 40.04, SpatialReferences.Wgs84);
point.Symbol = new SimpleMarkerSymbol() { Color = System.Windows.Media.Colors.Red,Size = 10 };

var graphicsOverlay = new GraphicsOverlay();
graphicsOverlay.Graphics.Add(point);

graphicsOverlay.Graphics.Add(new Graphic(polygon,new SimpleFillSymbol() { }));
MyMapView.GraphicsOverlays.Add(graphicsOverlay);

MyMapView.ViewpointChanged += MyMapView_ViewpointChanged;

MyMapView.InteractionOptions = new MapViewInteractionOptions();
}

private async void MyMapView_ViewpointChanged(object sender, EventArgs e)
{
if (MyMapView.InteractionOptions.IsPanEnabled)
{
var exent = MyMapView.GetCurrentViewpoint(0);
if (exent == null) return;
var center = exent.TargetGeometry.Extent.GetCenter();
var center84 = GeometryEngine.Project(center, SpatialReferences.Wgs84) as MapPoint;
point.Geometry = center84;

if (!GeometryEngine.Disjoint(polygon, center84))
{
//text.Text = center84.ToString();
}
else
{
MyMapView.InteractionOptions.IsPanEnabled = false;
if (center84.X < x1)
center84 = new MapPoint(x1, center84.Y, SpatialReferences.Wgs84);
else if (center84.X > x2)
center84 = new MapPoint(x2, center84.Y, SpatialReferences.Wgs84);
if (center84.Y < y2)
center84 = new MapPoint(center84.X, y2, SpatialReferences.Wgs84);
else if (center84.Y > y1)
center84 = new MapPoint(center84.X, y1, SpatialReferences.Wgs84);
var tmp = await MyMapView.SetViewpointCenterAsync(center84);
if (tmp)
MyMapView.InteractionOptions.IsPanEnabled = true;
}
}
}
}

朱新颖

赞同来自:

设置不了,已经向Esri询问过,见截图。

增强.jpg

 

要回复问题请先登录注册