async public static void AddMapOverlays(IMapView mapView) { // Create overlay layer for markers var dataSource = new LocalVectorDataSource(proj); var overlayLayer = new VectorLayer(dataSource); mapView.Layers.Add(overlayLayer); // Create line style, and line poses var lineStyleBuilder = new LineStyleBuilder(); lineStyleBuilder.Width = 8; var linePoses = new MapPosVector(); // proj.FromWgs84 returns (spherical) Mercator projection linePoses.Add(proj.FromWgs84(new MapPos(0, 0))); linePoses.Add(proj.FromWgs84(new MapPos(0, 80))); linePoses.Add(proj.FromWgs84(new MapPos(45, 45))); var line = new Line(linePoses, lineStyleBuilder.BuildStyle()); dataSource.Add(line); // Create balloon popup var balloonPopupStyleBuilder = new BalloonPopupStyleBuilder(); balloonPopupStyleBuilder.CornerRadius = 3; balloonPopupStyleBuilder.TitleFontName = "Helvetica"; balloonPopupStyleBuilder.TitleFontSize = 55; balloonPopupStyleBuilder.TitleColor = new Color(200, 0, 0, 255); balloonPopupStyleBuilder.StrokeColor = new Color(200, 120, 0, 255); balloonPopupStyleBuilder.StrokeWidth = 1; balloonPopupStyleBuilder.PlacementPriority = 1; var popup = new BalloonPopup( proj.FromWgs84(new MapPos(0, 20)), balloonPopupStyleBuilder.BuildStyle(), "Title", "Description"); dataSource.Add(popup); // Load NML file model from a file BinaryData modelFile = AssetUtils.LoadAsset("fcd_auto.nml"); // set location for model, and create NMLModel object with this var modelPos = proj.FromWgs84(new MapPos(24.646469, 59.423939)); var model = new NMLModel(modelPos, modelFile); mapView.FocusPos = modelPos; mapView.Zoom = 15; // Oversize it 20*, just to make it more visible (optional) model.Scale = 20; // Add metadata for click handling (optional) model.SetMetaDataElement("ClickText", new Variant("Single model")); // Add it to normal datasource dataSource.Add(model); // Create and set map listener mapView.MapEventListener = new MapListener(dataSource); await AnimateModel(model); }
public static void RotateElementInPosition(XYZ placementPoint, Connector conOnFamilyToConnect, Connector start, Element element) { #region Geometric manipulation //http://thebuildingcoder.typepad.com/blog/2012/05/create-a-pipe-cap.html //Select the OTHER connector MEPCurve hostPipe = start.Owner as MEPCurve; Connector end = (from Connector c in hostPipe.ConnectorManager.Connectors //End of the host/dummy pipe where c.Id != start.Id && (int)c.ConnectorType == 1 select c).FirstOrDefault(); XYZ dir = (start.Origin - end.Origin); // rotate the cap if necessary // rotate about Z first XYZ pipeHorizontalDirection = new XYZ(dir.X, dir.Y, 0.0).Normalize(); //XYZ pipeHorizontalDirection = new XYZ(dir.X, dir.Y, 0.0); XYZ connectorDirection = -conOnFamilyToConnect.CoordinateSystem.BasisZ; double zRotationAngle = pipeHorizontalDirection.AngleTo(connectorDirection); Transform trf = Transform.CreateRotationAtPoint(XYZ.BasisZ, zRotationAngle, placementPoint); XYZ testRotation = trf.OfVector(connectorDirection).Normalize(); if (Math.Abs(testRotation.DotProduct(pipeHorizontalDirection) - 1) > 0.00001) { zRotationAngle = -zRotationAngle; } Line axis = Line.CreateBound(placementPoint, placementPoint + XYZ.BasisZ); ElementTransformUtils.RotateElement(element.Document, element.Id, axis, zRotationAngle); //Parameter comments = element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS); //comments.Set("Horizontal only"); // Need to rotate vertically? if (Math.Abs(dir.DotProduct(XYZ.BasisZ)) > 0.000001) { // if pipe is straight up and down, // kludge it my way else if (dir.X.Round3() == 0 && dir.Y.Round3() == 0 && dir.Z.Round3() != 0) { XYZ yaxis = new XYZ(0.0, 1.0, 0.0); //XYZ yaxis = dir.CrossProduct(connectorDirection); double rotationAngle = dir.AngleTo(yaxis); //double rotationAngle = 90; if (dir.Z.Equals(1)) { rotationAngle = -rotationAngle; } axis = Line.CreateBound(placementPoint, new XYZ(placementPoint.X, placementPoint.Y + 5, placementPoint.Z)); ElementTransformUtils.RotateElement(element.Document, element.Id, axis, rotationAngle); //comments.Set("Vertical!"); } else { #region sloped pipes double rotationAngle = dir.AngleTo(pipeHorizontalDirection); XYZ normal = pipeHorizontalDirection.CrossProduct(XYZ.BasisZ); trf = Transform.CreateRotationAtPoint(normal, rotationAngle, placementPoint); testRotation = trf.OfVector(dir).Normalize(); if (Math.Abs(testRotation.DotProduct(pipeHorizontalDirection) - 1) < 0.00001) { rotationAngle = -rotationAngle; } axis = Line.CreateBound(placementPoint, placementPoint + normal); ElementTransformUtils.RotateElement(element.Document, element.Id, axis, rotationAngle); //comments.Set("Sloped"); #endregion } } #endregion }