/// <summary> /// Zoom map to a feature layer's extent. If its SR is different than the base map's, re-project the extent /// </summary> private void MenuItemZoomTo_Click(object sender, MenuItemClickEventArgs e) { HideConextMenu(); if (e.ItemTag is LivingMapLayer) { LivingMapLayer mapConfig = e.ItemTag as LivingMapLayer; Envelope extent = this.MapControl.Layers[mapConfig.ID].FullExtent; if (!SpatialReference.AreEqual(extent.SpatialReference, this.MapControl.SpatialReference, false)) { GeometryTool.ProjectEnvelope(this.AppConfig.GeometryService, extent, this.MapSRWKID, (s, g) => { if (g.ProjectedGeometry != null) { this.MapControl.ZoomTo(g.ProjectedGeometry); } }); } else { this.MapControl.ZoomTo(extent); } } else if (e.ItemTag is TOCNodeInfo) { TOCNodeInfo nodeInfo = e.ItemTag as TOCNodeInfo; if (nodeInfo.LayerExtent == null) { this.IsBusy = true; Layer layer = this.MapControl.Layers[nodeInfo.MapID]; string layerUrl = (nodeInfo.IsTiledMap) ? (layer as ArcGISTiledMapServiceLayer).Url : (layer as ArcGISDynamicMapServiceLayer).Url; ArcGISLayerInfoReader layerInfoReader = new ArcGISLayerInfoReader(layerUrl + "/" + nodeInfo.LayerID); layerInfoReader.InfoReady += (obj, arg) => { if (!SpatialReference.AreEqual(arg.LayerInfo.Extent.SpatialReference, this.MapControl.SpatialReference, false)) { GeometryTool.ProjectEnvelope(this.AppConfig.GeometryService, arg.LayerInfo.Extent, this.MapSRWKID, (s, g) => { this.IsBusy = false; if (g.ProjectedGeometry != null) { nodeInfo.LayerExtent = g.ProjectedGeometry as Envelope; this.MapControl.ZoomTo(nodeInfo.LayerExtent); } }); } else { this.IsBusy = false; nodeInfo.LayerExtent = nodeInfo.LayerExtent = arg.LayerInfo.Extent; this.MapControl.ZoomTo(nodeInfo.LayerExtent); } }; } else { this.MapControl.ZoomTo(nodeInfo.LayerExtent); } } }
private void DrawObject_DrawComplete(object sender, DrawEventArgs e) { if (this.DrawWidget == this.GetType()) { string viewURL = ""; MapPoint point = e.Geometry as MapPoint; AddLocationGraphic(point); if (GeometryTool.IsGeographicSR(this.MapSRWKID)) { viewURL = GetViewContentURL(point.X, point.Y); OpenSteetViewWindow(viewURL); } if (GeometryTool.IsWebMercatorSR(this.MapSRWKID)) { point = point.WebMercatorToGeographic(); viewURL = GetViewContentURL(point.X, point.Y); OpenSteetViewWindow(viewURL); } else { if (geoService == null) { geoService = new GeometryService(this.AppConfig.GeometryService); geoService.ProjectCompleted += new EventHandler <GraphicsEventArgs>(GeometryService_ProjectCompleted); } geoService.ProjectAsync(this.GraphicsLayer.Graphics, new SpatialReference(2446)); } } }
private void ExtractButton_Click(object sender, RoutedEventArgs e) { if (clipByExtent) { GraphicCollection clipGraphics = new GraphicCollection(); clipGraphics.Add(new Graphic() { Geometry = GeometryTool.EnvelopeToPolygon(this.MapControl.Extent) }); CreateGPParamsAndExtract(clipGraphics); } else { if (needGeneralized) { GeneralizeParameters genParam = new GeneralizeParameters() { DeviationUnit = LinearUnit.Meter, MaxDeviation = 10 }; geometryService.GeneralizeAsync(this.GraphicsLayer.Graphics, genParam); } else { CreateGPParamsAndExtract(this.GraphicsLayer.Graphics); } } }
private void Query_ResultReady(object sender, QueryResultEventArgs args) { this.ClearGraphics(2); // Toggle to Results Panel if (args.Results != null && args.Results.Features.Count > 0) { isFirstLoad = true; // Suppress filter results by map extent or pan map QueryResultMessage.Visibility = Visibility.Collapsed; FeatureSet fset = args.Results; Symbol symbol = ChooseSymbol(fset.GeometryType.ToString(), false); GeoFeatureCollection dataset = new GeoFeatureCollection(args.QueryLayer.OutputFields, args.QueryLayer.OutputLabels, fset.DisplayFieldName, args.QueryLayer.Title); foreach (Graphic feature in fset.Features) { feature.Symbol = symbol; feature.Geometry.SpatialReference = fset.SpatialReference; this.GraphicsLayer.Graphics.Add(feature); dataset.Add(feature); } this.FeatureSets.Add(dataset); this.GraphicsTipTemplate = args.QueryLayer.MapTipTemplate; this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(this.GraphicsLayer.FullExtent, 0.25)); } else { QueryResultMessage.Visibility = Visibility.Visible; QueryResultMessage.Text = string.Format("Sorry! {0}", (string.IsNullOrEmpty(args.ErrorMsg)) ? "No features are found." : args.ErrorMsg); } this.IsBusy = false; }
void ShootRay(Vector3 mousePos) { Vector3 from, clickWorldPoint, normalDir; GeometryTool.GetShootingRay(mousePos, out from, out clickWorldPoint, out normalDir); //debug用 voxelBuilder.SetClickPointOnRay(clickWorldPoint); voxelBuilder.SetClickNormalDir(normalDir); int nowFloor, nowY, nowX; //mahjongMap的平面朝向是固定的,所以不作座標變換 bool isHit = voxelBuilder.DoClick(from, normalDir, out nowFloor, out nowY, out nowX); if (!isHit) { return; } var funptr = DoWhat(); for (var y = 0; y < voxelBuilder.GetAddCountY(); ++y) { for (var x = 0; x < voxelBuilder.GetAddCountX(); ++x) { var node = voxelBuilder.GetVoxel(nowFloor, nowY + 2 * y, nowX + 2 * x); if (node == null) { continue; } voxelBuilder.DoOperation(node, funptr); } } }
public void SetParameter(IMultiPolygon sSection, IMultiPolygon eSection, IPolyline polyline) { try { base._cullModel = gviCullFaceMode.gviCullNone; this.SetColorRender(new uint[] { uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue }); if ((sSection != null) && (eSection != null)) { IPolygon geometry = sSection.GetGeometry(0) as IPolygon; if (geometry != null) { if (geometry.QueryNormal().Z < 0.0) { GeometryTool.ReversePolygon(ref geometry); } this._pillarSection = new PillarSection(geometry); DrawGeometry.GetPolylineVtxs(polyline, ref this._x, ref this._y, ref this._z, ref this._route); } } } catch (Exception exception) { SystemLog.Instance.Log(exception.StackTrace); } }
/// <summary> /// Set an initial map extent after all map layers are initialized /// </summary> private void InitializeMapExtent() { MapConfig mapConfig = CurrentApp.AppConfig.MapConfig; if (mapConfig.InitialExtent != null) { InitMapExtent = mapConfig.InitialExtent.ToEnvelope(this.MapSRWKID); } if (mapConfig.FullExtent != null) { FullMapExtent = mapConfig.FullExtent.ToEnvelope(this.MapSRWKID); } // If OverviewMap exits, initialize Map extent here, otherwise in OverviewMapWidget if (string.IsNullOrEmpty(this.CurrentApp.AppConfig.OverviewMapConfigFile)) { if (InitMapExtent != null) { myMap.Extent = InitMapExtent; } else if (FullMapExtent != null) { myMap.Extent = FullMapExtent; } // Initial set does not fire ExtentChange event double ratioScaleResolution = GeometryTool.RatioScaleResolution(myMap.Extent.GetCenter().Y, this.MapSRWKID, this.MapUnits); MapScale = ratioScaleResolution * myMap.Resolution; } }
/// <summary> /// Create element chart and add it into an Elememt Layer in the Map /// </summary> private void CreateElementChart(Graphic graphic, string displayValue) { ChartQueryLayer chartLayer = queryTool.QueryLayer as ChartQueryLayer; string[] outFields = chartLayer.OutputFields.Split(','); string[] outLabels = chartLayer.OutputLabels.Split(','); string title = string.Format("{0} - {1}", displayValue, chartLayer.Title); bool isPercentDependent = chartLayer.ChartOutput.DependentIsPercentage; string dependentAxisTitle = chartLayer.ChartOutput.DependentAxisTitle; Chart chart = null; switch (chartLayer.ChartOutput.ChartType) { case "Bar": case "Column": chart = CreateSingleBarChart(graphic, chartLayer.ChartOutput.ChartType, outFields, outLabels, title, dependentAxisTitle); break; case "Pie": chart = CreateSinglePieChart(graphic, outFields, outLabels, title, dependentAxisTitle, isPercentDependent); chart.Background = new SolidColorBrush(Color.FromArgb(204, 240, 240, 255)); break; } Envelope ext = GeometryTool.ExpandGeometryExtent(graphic.Geometry, 0.10); ElementLayer.SetEnvelope(chart, ext); elementLayer.Children.Clear(); elementLayer.Children.Add(chart); this.MapControl.ZoomTo(ext); }
List <int> getAllNeighborTriangelIndex(ref Vector3 movablePos, int overlapCount, out Collider nearestC) { // 只有1個的話 if (overlapCount == 1) { var c = colliderList[0]; nearestC = c; return(c.GetComponent <GravitySensor>().neighborTriangleIndex); } // 找出最近的GS(1個以上) // 有甜甜圈的交界處的GravitySensor,會漏掉一些相鄰資訊 var vertexInfoList = new List <VertexInfo>(); for (int i = 0; i < overlapCount; i++) { Collider c = colliderList[i]; var vPos = c.transform.position; var vNormal = c.transform.forward; vertexInfoList.Add(new VertexInfo() { position = vPos, normal = vNormal, distance = (vPos - movablePos).sqrMagnitude, collider = c }); } vertexInfoList.Sort( (VertexInfo a, VertexInfo b) => { if (a.distance < b.distance) { return(-1); } else { return(1); } } ); nearestC = vertexInfoList[0].collider; // 最近的2個 var gs0 = vertexInfoList[0].collider.GetComponent <GravitySensor>(); var gs1 = vertexInfoList[1].collider.GetComponent <GravitySensor>(); var distance_0_1 = (gs0.transform.position - gs1.transform.position).magnitude; if (GeometryTool.floatEqual(distance_0_1, 0)) { // Debug.Log("GravitySensor合體"); List <int> list = new List <int>(); list.AddRange(gs0.neighborTriangleIndex); list.AddRange(gs1.neighborTriangleIndex); return(list); } else { return(gs0.neighborTriangleIndex); } }
/// <summary> /// Zoom map to a specific graphic /// </summary> public void ZoomToGraphics() { if (graphicsLayer != null) { // Expand the extent in case only one point graphic available in the graphics layer this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(this.GraphicsLayer.FullExtent, 0.25)); } }
private void FeatureLayer_UpdateCompleted(object sender, EventArgs e) { if (agisFeatureLayer.FullExtent != null) { // Expand this extent in case only one point is selected this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(agisFeatureLayer.FullExtent, 0.0)); } }
private void MyMap_ExtentChanged(object sender, ExtentEventArgs e) { this.CurrentApp.SetWindowStatus(string.Format("Map Extent: [{0:f}, {1:f}] - [{2:f}, {3:f}]", e.NewExtent.XMin, e.NewExtent.YMin, e.NewExtent.XMax, e.NewExtent.YMax)); double ratioScaleResolution = GeometryTool.RatioScaleResolution(e.NewExtent.GetCenter().Y, this.MapSRWKID, this.MapUnits); this.MapScale = ratioScaleResolution * myMap.Resolution; }
private void DrawObject_DrawComplete(object sender, DrawEventArgs e) { if (this.DrawWidget == this.GetType()) { Graphic graphic = null; if (this.drawMode == "Freepoly") { // Create a Graphic with the newly closed Polygon graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = GeometryTool.FreehandToPolygon(e.Geometry as Polyline), Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_FILL] as FillSymbol }; } else { // Create a Graphic with the drawn geometry graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Geometry = e.Geometry; switch (e.Geometry.GetType().Name) { case "MapPoint": graphic.Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_MARKER] as MarkerSymbol; break; case "Polyline": graphic.Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_LINE] as LineSymbol; break; case "Envelope": case "Polygon": graphic.Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_FILL] as FillSymbol; break; } } if (lstGeoQueryLayer.SelectedIndex == -1) { MessageBox.Show("Please select a feature layer to query against"); return; } if (this.GraphicsLayer == null) { MessageBox.Show("GraphicsLayer for this widget is not created. Please set property HasGraphics 'true'."); return; } if (graphic != null) { this.IsBusy = true; // Temporarily show the draw object this.ClearGraphics(1); this.AddGraphic(graphic); queryTool.QueryLayer = widgetConfig.QueryLayers[lstGeoQueryLayer.SelectedIndex]; queryTool.LayerInfo = (lstGeoQueryLayer.SelectedItem as ComboBoxItem).Tag as ArcGISLayerInfo; queryTool.Search(graphic.Geometry, this.MapSRWKID); } } }
Vector3 getInterpolationNormal(List <int> triIndexList, ref Vector3 movablePos, ref Vector3 headUp) { var triCount = triIndexList.Count; for (var i = 0; i < triCount; ++i) { var triIndex = triIndexList[i]; int v0Index = triangles[3 * triIndex]; int v1Index = triangles[3 * triIndex + 1]; int v2Index = triangles[3 * triIndex + 2]; var v0 = vertices[v0Index]; var v1 = vertices[v1Index]; var v2 = vertices[v2Index]; var parentPos = transform.position; v0 += parentPos; v1 += parentPos; v2 += parentPos; var N = GeometryTool.CalculateTriangleNormal(ref v0, ref v1, ref v2); // 擊中三角形所在的平面 Vector3 hitPos; if (!GeometryTool.RayHitPlane(movablePos, -N, N, v0, out hitPos)) { continue; } bool isGetValue; float a, b, r; GeometryTool.CalculateBarycentricCoordinates(ref v0, ref v1, ref v2, ref hitPos, out isGetValue, out a, out b, out r); if (!isGetValue) { continue; } if (!GeometryTool.isInTriangle(a, b, r)) { continue; } Debug.DrawLine(v0, v1, Color.red); Debug.DrawLine(v1, v2, Color.green); Debug.DrawLine(v2, v0, Color.blue); var n0 = normals[v0Index]; var n1 = normals[v1Index]; var n2 = normals[v2Index]; Debug.DrawRay(v0, n0 * 5); Debug.DrawRay(v1, n1 * 5); Debug.DrawRay(v2, n2 * 5); var normal = GeometryTool.CalculateInterpolationValueByBarycentricCoordinates(ref n0, ref n1, ref n2, a, b, r); return(normal.normalized); } return(headUp); }
void GenerateFromBlender(Vector3 pos, Vector3 size) { Vector3 xDir = transform.right; Vector3 zDir = transform.up; var xLen = 0.5f * size.x; var zLen = 0.5f * size.y; GeometryTool.Generate(pos, xDir, zDir, xLen, zLen, points); }
void GenerateRectDefault(Vector3 pos, Vector3 size) { Vector3 xDir = transform.right; Vector3 zDir = transform.forward; var xLen = 0.5f * size.x; var zLen = 0.5f * size.z; GeometryTool.Generate(pos, xDir, zDir, xLen, zLen, points); }
public void TestIsIntersect() { Vector3 p0 = P0.position; Vector3 p1 = P1.position; Vector3 p2 = P2.position; Vector3 p3 = P3.position; bool result = GeometryTool.IsIntersect(p0, p1, p2, p3); Debug.Log(result); }
private void ShrinkBondLinesPass1(Progress pb) { // so that they do not overlap label characters if (_convexHulls.Count > 1) { pb.Show(); } pb.Message = "Clipping Bond Lines - Pass 1"; pb.Value = 0; pb.Maximum = _convexHulls.Count; foreach (var hull in _convexHulls) { pb.Increment(1); // select lines which start or end with this atom var targeted = from l in _bondLines where (l.StartAtomId == hull.Key | l.EndAtomId == hull.Key) select l; foreach (BondLine bl in targeted.ToList()) { Point start = new Point(bl.Start.X, bl.Start.Y); Point end = new Point(bl.End.X, bl.End.Y); bool outside; var r = GeometryTool.ClipLineWithPolygon(start, end, hull.Value, out outside); switch (r.Length) { case 3: if (outside) { bl.Start = new Point(r[0].X, r[0].Y); bl.End = new Point(r[1].X, r[1].Y); } else { bl.Start = new Point(r[1].X, r[1].Y); bl.End = new Point(r[2].X, r[2].Y); } break; case 2: if (!outside) { // This line is totally inside so remove it! _bondLines.Remove(bl); } break; } } } }
private void Test_MouseDown(object sender, OpenTK.Input.MouseButtonEventArgs e) { if (e.Mouse.LeftButton == OpenTK.Input.ButtonState.Pressed) { list.Add(new Point2D(e.Mouse.X, e.Mouse.Y)); if (list.Count == 4) { GeometryTool.AddQuat(list); } } }
bool NodeIsIntersectWithColliderRects(QuadTreeConnectedNode node, IRect[] colliderRects) { for (var i = 0; i < colliderRects.Length; ++i) { var rect = colliderRects[i]; if (GeometryTool.IsIntersect(node, rect)) { return(true); } } return(false); }
bool NodeCenterIsInColliderRects(QuadTreeConnectedNode node, IRect[] colliderRects) { for (var i = 0; i < colliderRects.Length; ++i) { var rect = colliderRects[i]; if (GeometryTool.IsContainCenterPoint(rect, node)) { return(true); } } return(false); }
public static void GetShootingRay(Vector3 mousePos, out Vector3 from, out Vector3 clickWorldPoint, out Vector3 normalDir) { var camera = Camera.current; if (camera.orthographic) { GeometryTool.GetGetShootingRayOrthographic(mousePos, out from, out clickWorldPoint, out normalDir); } else { GeometryTool.GetShootingRayPerspective(mousePos, out from, out clickWorldPoint, out normalDir); } }
bool rayHitPlane(Vector3 from, Vector3 dir, SphereTerrain sTerrain, out Vector3 hitPoint) { if (!GeometryTool.RayHitPlane(from, dir, sTerrain.getPlaneNormal(), sTerrain.getPlanePoint(), out hitPoint)) { return(false); } var localHitPoint = sTerrain.transform.InverseTransformPoint(hitPoint); var half = 1023.0f * 0.5f; var inRect = Mathf.Abs(localHitPoint.x) < half && Mathf.Abs(localHitPoint.z) < half; controller.hitOnPlane.position = inRect ? hitPoint : Vector3.zero; return(inRect); }
private void AddressCandidate_Click(object sender, MouseButtonEventArgs e) { if (sender is TextBlock) { TextBlock block = sender as TextBlock; if (block.Tag != null && block.Tag is MapPoint) { MapPoint location = (MapPoint)block.Tag; HighlightSelectedGraphic(location, block.Text); this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(this.SelectedGraphic.Geometry, 0.5)); } } }
public void OnSceneGUI() { Vector3 from, dir; GeometryTool.GetShootingRay(Event.current.mousePosition, out from, out dir); Vector3 hitPoint, hitNormal; controller.from.position = from; var isHitSphere = rayHitSphere(from, dir, out hitPoint, out hitNormal); if (!isHitSphere) { return; } if (Event.current.button == 1)//right button { Vector3 hitOnPlane; var hitTerrain = getHitPlane(hitPoint, hitNormal, out hitOnPlane); if (hitTerrain == null) { Debug.Log("no hit plane"); return; } if (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) { // Debug.Log(hitTerrain.name); isUsingBrush = true; hitTerrain.setBrushLocalPosFrom(hitOnPlane); hitTerrain.useBrush(true); hitTerrain.updateNeighborsBrush(true); Event.current.Use(); // 中斷鏡頭的旋轉 return; } if (isUsingBrush == true) { isUsingBrush = false; hitTerrain.setBrushLocalPosFrom(hitOnPlane); hitTerrain.useBrush(false); hitTerrain.updateNeighborsBrush(false); } } }
public GeometryOperation(GeoController geoController, ToolController toolController, StateController stateController, Tool tool) { this.geoController = geoController; this.toolController = toolController; this.stateController = stateController; this.tool = tool; Type type = Type.GetType(tool.Name + "GeometryTool"); if (type != null) { geometryTool = (GeometryTool)Activator.CreateInstance(type); } }
public static bool IsIntersect(IRect a, IRect b) { //如果任2邊相交 for (var i = 0; i < 4; ++i) { Vector3 p0, p1; GetEdge(a, i, out p0, out p1); for (var k = 0; k < 4; ++k) { Vector3 p2, p3; GetEdge(b, k, out p2, out p3); if (GeometryTool.IsIntersect(p0, p1, p2, p3)) { return(true); } } } return(false); }
bool rayHitSphere(Vector3 from, Vector3 dir, out Vector3 hitPoint, out Vector3 hitNormal) { var shereWorldCenter = controller.getSphereWorldCenter(); // 先射球 var R = SphereTerrain.R; var isHit = GeometryTool.RayMarchingSphere(from, dir, shereWorldCenter, R, out hitPoint, out hitNormal); if (isHit) { var tangent = Vector3.zero; Vector3.OrthoNormalize(ref hitNormal, ref tangent); controller.to.rotation = Quaternion.LookRotation(hitNormal, tangent); controller.to.position = hitPoint; } else { controller.to.position = from + dir * 1000.0f; controller.to.rotation = Quaternion.identity; } return(isHit); }
public bool DoClick(Vector3 from, Vector3 dir, out int floor, out int y, out int x, bool onlyUseVoxel = false) { floor = -1; x = -1; y = -1; bool hit = GeometryTool.RayHitPlane(from, dir, Vector3.up, transform.position + GetNowFlowerHeight(), out hitPoint); if (!hit) { return(false); } var voxel = GetHitVoxel(hitPoint); if (voxel == null) { return(false); } if (onlyUseVoxel) { if (!voxel.IsUse()) { return(false); } } bool hitSphere = voxel.IsHit(hitPoint); if (!hitSphere) { return(false); } x = voxel.x; y = voxel.y; floor = voxel.floor; return(true); }
private void RSSTitleLink_Click(object sender, System.Windows.RoutedEventArgs e) { if (sender is SimpleLinkButton) { if (selectedRssItemPanel != null) { TextBlock oldRssDesc = selectedRssItemPanel.FindName("RssDescription") as TextBlock; oldRssDesc.Visibility = Visibility.Collapsed; HyperlinkButton oldRssLink = selectedRssItemPanel.FindName("RssHyperlink") as HyperlinkButton; oldRssLink.Visibility = Visibility.Collapsed; } SimpleLinkButton titleLink = sender as SimpleLinkButton; StackPanel rssItemStack = titleLink.Parent as StackPanel; selectedRssItemPanel = rssItemStack; TextBlock textRssDesc = rssItemStack.FindName("RssDescription") as TextBlock; if (textRssDesc != null) { textRssDesc.Visibility = Visibility.Visible; } HyperlinkButton btnRssLink = rssItemStack.FindName("RssHyperlink") as HyperlinkButton; if (btnRssLink != null) { btnRssLink.Visibility = Visibility.Visible; } ESRI.ArcGIS.Client.Geometry.Geometry geometry = titleLink.Tag as ESRI.ArcGIS.Client.Geometry.Geometry; this.MapControl.ZoomTo(GeometryTool.ExpandGeometryExtent(geometry, 0.10)); /* If other widgets need to know the SelectedGraphic */ this.SelectedGraphic = new Graphic(); this.SelectedGraphic.Geometry = geometry; this.SelectedGraphic.Attributes.Add("Title", titleLink.Text); this.SelectedGraphic.Attributes.Add("Description", textRssDesc.Text); this.SelectedGraphic.Attributes.Add("Link", btnRssLink.NavigateUri.AbsoluteUri); } }