public static KmlGeometry[] ParseGeometryChildren(XElement xml, XmlNamespaceManager namespaces) { List <KmlGeometry> temp = new List <KmlGeometry>(); foreach (XElement element in xml.Elements()) { switch (element.Name.LocalName) { case "extrude": case "tessellate": case "altitudeMode": continue; case "Point": temp.Add(KmlPoint.Parse(element)); break; case "LineString": temp.Add(KmlLineString.Parse(element)); break; case "Polygon": temp.Add(KmlPolygon.Parse(element)); break; case "MultiGeometry": temp.Add(KmlMultiGeometry.Parse(element)); break; } } return(temp.ToArray()); }
/// <summary> /// 创建线图元 /// </summary> /// <param name="kml">kml对象</param> /// <param name="gmapOverlay">图层</param> /// <returns></returns> public IMFElement CreateElement(Kml kml, GMapOverlay gmapOverlay) { KmlLineString line = kml.Placemark.Graph as KmlLineString; if (line == null) { return(null); } if (line.PositionList == null || line.PositionList.Count == 0) { return(null); } // 画线 Line_GMap lineRoute = new Line_GMap(kml.Placemark.Name, line); // 将图元添加到图层 if (gmapOverlay.Control.InvokeRequired) { gmapOverlay.Control.Invoke(new Action(delegate { gmapOverlay.Routes.Add(lineRoute); })); } else { gmapOverlay.Routes.Add(lineRoute); } return(lineRoute); }
/// <summary> /// 构造函数 /// </summary> /// <param name="name">图元名称</param> /// <param name="line">线属性</param> public Line_GMap(string name, KmlLineString line) : base(name) { this.ElementName = name; this.ElementType = ElementTypeEnum.Line; this.Description = line.Description; // 鼠标经过可见 base.IsHitTestVisible = true; List <PointLatLng> pointList = new List <PointLatLng>(); foreach (MapLngLat latLng in line.PositionList) { PointLatLng p = new PointLatLng(latLng.Lat, latLng.Lng); pointList.Add(p); } this.Points.AddRange(pointList); this.ElementName = name; float penWidth = line.Width > 0 ? line.Width : 1; Color penColor = line.Color; mPen = new Pen(penColor, penWidth); isFlash = false; // 计时器 flashTimer = new System.Timers.Timer(); flashTimer.Elapsed += flashTimer_Elapsed; flashTimer.Interval = 500; base.Tag = this; }
/// <summary> /// 鼠标左键双击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void mapControl_eventLButtonDbClick(object sender, _DHOSOFTMapControlEvents_eventLButtonDbClickEvent e) { if (!isControl && listPoints.Count >= 2) { if (!string.IsNullOrEmpty(tempName)) { mapControl.MgsDelObject(tempName); } //if (listPoints.Count < 2) return; Kml kml = new Kml(); KmlLineString line = new KmlLineString(); line.PositionList = listPoints; line.Color = System.Drawing.Color.Red; line.Width = 3; kml.Placemark.Name = "mgis_line" + Utils.ElementIndex; kml.Placemark.Graph = line; IMFElement element = null; layer.AddElement(kml, out element); lineElement = element as IMFLine; RegistCommondExecutedEvent(); ReleaseCommond();//修改 陈静 listPoints.Clear(); isFinish = true; } }
/// <summary> /// 创建线图元 /// </summary> /// <param name="kml">线的kml</param> /// <param name="layer">图层</param> /// <returns></returns> public Core.Interface.IMFElement CreateElement(Core.Model.Kml kml, ILayer layer) { KmlLineString line = kml.Placemark.Graph as KmlLineString; if (line == null) { return(null); } if (line.PositionList == null || line.PositionList.Count < 1) { return(null); } CompositeGraphicsLayerClass graphicLayer = layer as CompositeGraphicsLayerClass; if (graphicLayer == null) { return(null); } Line_ArcMap lineElement = new Line_ArcMap(mapControl, line, mapFactory); lineElement.Opacity = 50; lineElement.ElementType = ElementTypeEnum.Line; graphicLayer.AddElement(lineElement, 0); return(lineElement); }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1 && !isControl) { downPoint = new MapLngLat(e.mapX, e.mapY); if (listMapPoints.Count == 0) { listMapPoints.Add(downPoint); Kml kmlLine = new Kml(); kmlLine.Placemark.Name = "arc_line" + Utils.ElementIndex; KmlLineString line = new KmlLineString(); line.PositionList = listMapPoints; line.Color = Color.Gray; line.Width = 2; kmlLine.Placemark.Graph = line; IMFElement element = null; layer.AddElement(kmlLine, out element); lineElement = element as IMFLine;//绘制完成后得到该图元 isFinish = false; } //若重复点击同一个点则不添加 else if (listMapPoints.Find(p => p.Lng == downPoint.Lng && p.Lat == downPoint.Lat) == null) { listMapPoints.Add(downPoint); } } }
// 更新目标航迹 private void UpdateTrackPoint(Model3D model) { List <TrackPoint> trackPoints = trackMgr.GetTrackPoints(model.ModelName); if (trackPoints == null || trackPoints.Count <= 1) { return; // 如果没有点,或者最多只有一个点,则返回不进行航迹绘制 } var layer = mapLogic.AddLayer(model.LayerName); if (layer == null) { return; } string lineName = model.ModelName + "line"; var line = layer.GetElement(lineName); if (line == null) { Kml kmlLine = new Kml(); kmlLine.Placemark.Name = lineName; KmlLineString linekml = new KmlLineString(); linekml.Color = Color.Red; linekml.Width = 1; List <MapLngLat> plist = new List <MapLngLat>(); for (int i = 0; i < trackPoints.Count; i++) { var point = new MapLngLat(trackPoints[i].Position.Lng, trackPoints[i].Position.Lat, trackPoints[i].Position.Alt); plist.Add(point); } linekml.PositionList = plist; linekml.Rasterize = false; kmlLine.Placemark.Graph = linekml; var result = layer.AddElement(kmlLine); } else { IMFLine lineElement = line as IMFLine; if (line == null) { return; } List <MapLngLat> plist = new List <MapLngLat>(); for (int i = 0; i < trackPoints.Count; i++) { var point = new MapLngLat(trackPoints[i].Position.Lng, trackPoints[i].Position.Lat, trackPoints[i].Position.Alt); plist.Add(point); } lineElement.UpdatePosition(plist); } }
// 更新航迹 private void UpdateTrackPoint(Plane plane) { List <TrackPoint> trackPoints = trackMgr.GetTrackPoints(plane.Name); if (trackPoints == null || trackPoints.Count <= 1) { return; } var layer = mapLogic.AddLayer(plane.LayerName); if (layer == null) { return; } string lineName = plane.Name + "line"; var line = layer.GetElement(lineName); if (line == null) { Kml kmlLine = new Kml(); kmlLine.Placemark.Name = lineName; KmlLineString lineKml = new KmlLineString(); lineKml.Color = System.Drawing.Color.Blue; lineKml.Width = 1; List <MapLngLat> plist = new List <MapLngLat>(); for (int i = 0; i < trackPoints.Count; i++) { var point = new MapLngLat(trackPoints[i].Position.Lng, trackPoints[i].Position.Lat, trackPoints[i].Position.Alt); plist.Add(point); } lineKml.PositionList = plist; kmlLine.Placemark.Graph = lineKml; var ret = layer.AddElement(kmlLine); } else { IMFLine lineElement = line as IMFLine; if (line == null) { return; } List <MapLngLat> plist = new List <MapLngLat>(); for (int i = 0; i < trackPoints.Count; i++) { var point = new MapLngLat(trackPoints[i].Position.Lng, trackPoints[i].Position.Lat, trackPoints[i].Position.Alt); plist.Add(point); } lineElement.UpdatePosition(plist); } }
/// <summary> /// 鼠标单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void mapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1 && !isControl) { downPoint = new MapLngLat(e.mapX, e.mapY); if (listMapPoints.Count == 0) { ResultEventArgs(" "); listMapPoints.Add(downPoint); switch (measureType) { case "distance": Kml kmlLine = new Kml(); kmlLine.Placemark.Name = "mea_line"; KmlLineString line = new KmlLineString(); line.PositionList = listMapPoints; line.Color = Color.Gray; line.Width = 2; kmlLine.Placemark.Graph = line; IMFElement element = null; layer.AddElement(kmlLine, out element); measureLine = element as IMFLine; //绘制完成后得到该图元 isFinish = false; break; case "area": Kml kml = new Kml(); kml.Placemark.Name = "mea_arcPolygon"; Color outlineColor = Color.Blue; Color fillColor = Color.Black; kml.Placemark.Graph = new KmlPolygon() { FillColor = fillColor, OutLineColor = outlineColor, OutLineSize = 1, PositionList = listMapPoints }; IMFElement element1 = null; layer.AddElement(kml, out element1); measurePolygon = element1 as IMFPolygon; isFinish = false; break; } } else { listMapPoints.Add(downPoint); } if (segmentLength != 0) { //长度 toltalLength += segmentLength; } } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = true; if (isFinish == true) { ReleaseCommond(); return; } if (pointIndex == 0)//第一个点 { var startPoint = gmapControl.FromLocalToLatLng(e.X, e.Y); Kml kmlLine = new Kml(); kmlLine.Placemark.Name = lineName; KmlLineString line = new KmlLineString(); line.Argb = Color.Green.ToArgb(); line.Width = 2; List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(startPoint.Lng, startPoint.Lat)); pList.Add(new MapLngLat(startPoint.Lng, startPoint.Lat)); line.PositionList = pList; kmlLine.Placemark.Graph = line; mapLogic.GetLayer(layerName).AddElement(kmlLine); gmapRoute = mapLogic.GetLayer(layerName).GetElement(lineName) as GMapRoute; pointIndex++; } else { // 释放资源 isFinish = true; ReleaseCommond(); // 发布完成事件 if (CommondExecutedEvent != null) { MessageEventArgs msg = new MessageEventArgs() { ToolType = ToolTypeEnum.Draw }; CommondExecutedEvent(lineName, msg); } } } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Clicks == 2) { return; } if (e.Button == MouseButtons.Left) { if (isFinish == true) { ReleaseCommond(); return; } var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); var maplngLat = new MapLngLat(lngLat.Lng, lngLat.Lat); if (pointIndex == 0)//第一个点 { listMapPoints = new List <MapLngLat>(); //加线 Kml kmlLine = new Kml(); kmlLine.Placemark.Name = lineName; KmlLineString line = new KmlLineString(); line.Argb = Color.Green.ToArgb(); line.Width = 2; List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(lngLat.Lng, lngLat.Lat)); line.PositionList = pList; //string.Format("{0},{1}", lngLat.Lng, lngLat.Lat); kmlLine.Placemark.Graph = line; layerCollection.GetLayer(layerName).AddElement(kmlLine); listMapPoints.Add(maplngLat); pointIndex++; } else { pointIndex++; if (!listMapPoints.Contains(maplngLat)) { listMapPoints.Add(maplngLat); } } isMouseDown = true; } }
private void 添加ToolStripMenuItem1_Click(object sender, System.EventArgs e) { Kml kml = new Kml(); kml.Placemark.Name = "line"; KmlLineString linekml = new KmlLineString(); List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(101, 23)); pList.Add(new MapLngLat(15, 50)); linekml.PositionList = pList; kml.Placemark.Graph = linekml; mapLogic.GetLayer(drawLayerName).AddElement(kml, out element); lineElement = element as IMFLine; }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseDown(object sender, MouseEventArgs e) { TimeSpan span = DateTime.Now - fistTimer; if (span.TotalMilliseconds < 170) { return; } fistTimer = DateTime.Now; if (e.Clicks == 2 || e.Button != MouseButtons.Left || mouseDown) { return; } var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); var maplngLat = new MapLngLat(lngLat.Lng, lngLat.Lat); if (listMapPoints.Count == 0) { //加线 Kml kmlLine = new Kml(); kmlLine.Placemark.Name = "draw_line" + Utils.ElementIndex; KmlLineString line = new KmlLineString(); line.Color = Color.Green; line.Width = 2; List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(lngLat.Lng, lngLat.Lat)); line.PositionList = pList; //string.Format("{0},{1}", lngLat.Lng, lngLat.Lat); kmlLine.Placemark.Graph = line; IMFElement element = null; drawn = layer.AddElement(kmlLine, out element); lineElement = element as IMFLine; listMapPoints.Add(maplngLat); gmapControl.MouseMove += gmapControl_MouseMove; } else { if (!listMapPoints.Contains(maplngLat)) { listMapPoints.Add(maplngLat); lineElement.AddPoint(maplngLat); } } }
/// <summary> /// 鼠标按下,绘制第一个点,并注册鼠标移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); if (index == 0) { //添加点 MapLngLat point = new MapLngLat(lngLat.Lng, lngLat.Lat); marker = new EditMarker(lngLat); marker.Tag = "点"; marker.ToolTipText = string.Format("起点\n经度:{0}\n纬度:{1}\n角度:{2}°", lngLat.Lng, lngLat.Lat, 0); marker.ToolTipMode = MarkerTooltipMode.Always; mapOverlay.Markers.Add(marker); //添加线 KmlLineString linekml = new KmlLineString(); linekml.Color = Color.Green; linekml.Width = 3; List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(lngLat.Lng, lngLat.Lat)); pList.Add(new MapLngLat(lngLat.Lng, lngLat.Lat)); linekml.PositionList = pList; lineRoute = new Line_GMap("measure_Angle", linekml); mapOverlay.Routes.Add(lineRoute); pointList[0] = point; //注册移动事件 gmapControl.MouseMove += new System.Windows.Forms.MouseEventHandler(gmapControl_MouseMove); index++; } else if (index == 1) { index++; gmapControl.MouseMove -= gmapControl_MouseMove; RegistCommandExcuteEvent(); ReleaseCommond();//修改 陈静 } else if (index == 2) { index = 0; mapOverlay.Markers.Remove(marker); mapOverlay.Routes.Remove(lineRoute); } } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mapControl_OnMouseDown(object sender, IGlobeControlEvents_OnMouseDownEvent e) { if (e.button == 1) //鼠标左键 { MapLngLat lnglat = this.SceneToGeographyPoint(e.x, e.y); lnglat.Alt = lnglat.Alt * -1; pointList.Add(lnglat); if (pointList.Count == 2) { kml = new Kml(); kml.Placemark.Name = "辅助线"; KmlLineString lineKml = new KmlLineString(); lineKml.Rasterize = true; lineKml.Description = "辅助线"; lineKml.PositionList = pointList; lineKml.Color = Color.FromArgb(70, Color.Orange); kml.Placemark.Graph = lineKml; layer.AddElement(kml); kml.Placemark.Name = "绘制面" + Utils.Index; polygonKml = new KmlPolygon(); polygonKml.Rasterize = true; polygonKml.Description = "手动绘制的面"; polygonKml.FillColor = Color.FromArgb(70, Color.Orange); kml.Placemark.Graph = polygonKml; } else if (pointList.Count == 3) //更新面 { layer.RemoveElement("辅助线"); polygonKml.PositionList = pointList; kml.Placemark.Graph = polygonKml; drawn = layer.AddElement(kml, out polygonElement); } else if (pointList.Count > 3) { layer.RemoveElement(polygonElement); polygonKml.PositionList = pointList; kml.Placemark.Graph = polygonKml; drawn = layer.AddElement(kml, out polygonElement); } layer.Refresh(); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="_mapControl">地图控件</param> /// <param name="kmlLine">线</param> /// <param name="_mapFactory">地图工厂</param> public Line_ArcMap(AxMapControl _mapControl, KmlLineString kmlLine, FactoryArcMap _mapFactory) { this.mapControl = _mapControl; this.mapFactory = _mapFactory; Dosomething(new Action(delegate { lineSymbol = new SimpleLineSymbolClass(); IColor color = new RgbColorClass() { Transparency = kmlLine.Color.A, Red = kmlLine.Color.R, Green = kmlLine.Color.G, Blue = kmlLine.Color.B }; lineSymbol.Color = color; lineSymbol.Width = kmlLine.Width; lineSymbol.Style = esriSimpleLineStyle.esriSLSDash; IPolyline polyLine = new PolylineClass(); pointCollection = polyLine as IPointCollection; IPoint p = new PointClass(); foreach (var item in kmlLine.PositionList) { p.PutCoords(item.Lng, item.Lat); p.Z = item.Alt; pointCollection.AddPoint(p); } base.Symbol = lineSymbol; base.Geometry = (IGeometry)pointCollection; }), true); //记录颜色、宽度、坐标集合 outLineColor = kmlLine.Color; outLineWidth = kmlLine.Width; pointList = new List <MapLngLat>(); pointList = kmlLine.PositionList; flashTimer = new Timer(); flashTimer.Elapsed += new ElapsedEventHandler(flashTimer_Elapsed); }
/// <summary> /// 构造函数 /// </summary> /// <param name="kml">kml对象</param> /// <param name="_mapControl">地图控件</param> public Line_Mgis(Kml kml, AxHOSOFTMapControl _mapControl) { this.mapControl = _mapControl; KmlLineString kmlLine = kml.Placemark.Graph as KmlLineString; if (kml.Placemark.Name == null || kmlLine.PositionList == null) { return; } this.symbolName = kml.Placemark.Name; this.listPoint = kmlLine.PositionList; int count = kmlLine.PositionList.Count(); float[] vertex = new float[count * 2]; IntPtr ptrVert = Marshal.AllocHGlobal(sizeof(float) * count * 2); for (int i = 0; i < count; i++) { vertex[2 * i] = (float)kmlLine.PositionList[i].Lng; vertex[2 * i + 1] = (float)kmlLine.PositionList[i].Lat; } Marshal.Copy(vertex, 0, ptrVert, vertex.Length); mapControl.MgsDrawLineSymByJBID(symbolName, 10, (ulong)(ptrVert.ToInt64()), count); Marshal.FreeHGlobal(ptrVert); mapControl.MgsUpdateSymColor(symbolName, kmlLine.Color.R, kmlLine.Color.G, kmlLine.Color.B, kmlLine.Color.A); mapControl.MgsUpdateSymLineWidth(symbolName, kmlLine.Width); Update();//刷新 this.ElementType = ElementTypeEnum.Line; this.width = kmlLine.Width; this.bOutLineColor = kmlLine.Color; flashTimer = new Timer(); flashTimer.Elapsed += new ElapsedEventHandler(flashTimer_Elapsed); flashTimer.Interval = 500; }
/// <summary> /// 创建线图元 /// </summary> /// <param name="kml">线的kml</param> /// <param name="layer">图元所在的图层</param> /// <returns></returns> public IMFElement CreateElement(Kml kml, ILayer layer) { KmlLineString lineKml = kml.Placemark.Graph as KmlLineString; if (lineKml.PositionList == null || lineKml.PositionList.Count < 1) { return(null); } int index = -1; //图层 IGlobeGraphicsLayer graphicLayer = layer as IGlobeGraphicsLayer; if (graphicLayer == null) { return(null); } //图元 Line_ArcGlobe lineElement = null; Dosomething((Action) delegate() { //属性 GlobeGraphicsElementPropertiesClass properties = new GlobeGraphicsElementPropertiesClass(); properties.Rasterize = lineKml.Rasterize; //添加图元 lineElement = new Line_ArcGlobe(graphicLayer, lineKml); graphicLayer.AddElement(lineElement, properties, out index); lineElement.Index = index; //指定索引 lineElement.ElementName = kml.Placemark.Name; }, true); return(lineElement); }
/// <summary> /// 构造函数 /// </summary> /// <param name="_graphcisLayer">图层</param> /// <param name="lineKml">线的kml</param> public Line_ArcGlobe(IGlobeGraphicsLayer _graphcisLayer, KmlLineString lineKml) { graphcisLayer = _graphcisLayer; this.ElementType = ElementTypeEnum.Line; //图元类型 this.Description = lineKml.Description; //描述 #region 位置 IPolyline polyLine = new PolylineClass(); IPointCollection pointCollection = polyLine as IPointCollection; IPoint p = new PointClass(); foreach (var item in lineKml.PositionList) { p.PutCoords(item.Lng, item.Lat); p.Z = item.Alt; pointCollection.AddPoint(p); } IGeometry geometry = (IGeometry)pointCollection; (geometry as IZAware).ZAware = true; base.Geometry = (IGeometry)pointCollection; #endregion #region 符号 pLineSymbol = new SimpleLineSymbolClass(); if (lineKml.Color.ToArgb() == 0) //符号颜色 { IColor color = new RgbColorClass() { Transparency = Color.Red.A, Red = Color.Red.R, Green = Color.Red.G, Blue = Color.Red.B }; pLineSymbol.Color = color; } else { IColor color = new RgbColorClass() { Transparency = lineKml.Color.A, Red = lineKml.Color.R, Green = lineKml.Color.G, Blue = lineKml.Color.B }; pLineSymbol.Color = color; } if (lineKml.Width == 0) //符号宽度 { lineKml.Width = 2; } pLineSymbol.Width = lineKml.Width; pLineSymbol.Style = (esriSimpleLineStyle)lineKml.LineStyle; //线的样式 base.Symbol = pLineSymbol; #endregion flashTimer = new System.Timers.Timer(); flashTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTimer_Elapsed); flashTimer.Interval = 1000; }
/// <summary> /// 调用此方法 /// </summary> /// <param name="xmlname">xml名称</param> /// <param name="filename">导出文件名</param> /// <param name="lst">数据</param> /// <returns></returns> public static int CreateKml(string xmlname, string filename, List <dataFormat> lst) { List <KmlPlacemark> ls = new List <KmlPlacemark>(); foreach (dataFormat d in lst) { string type = d.type; string coords = d.coordinates.Trim(); string styleUrl = d.styleUrl; string name = d.name; if (string.IsNullOrEmpty(name)) { name = ""; } string description = d.description; if (string.IsNullOrEmpty(description)) { description = ""; } if (type == "point") { if (string.IsNullOrEmpty(styleUrl)) { styleUrl = "#downArrowIcon"; } KmlPoint p = new KmlPoint(coords); KmlPlacemark placemark = new KmlPlacemark(name, description, styleUrl, p, null, null); ls.Add(placemark); } else if (type == "line") { if (string.IsNullOrEmpty(styleUrl)) { styleUrl = "#blue"; } KmlLineString line = new KmlLineString(coords.Split(';').ToList()); KmlPlacemark placemark = new KmlPlacemark(name, description, styleUrl, null, line, null); ls.Add(placemark); } else if (type == "polygon") { if (string.IsNullOrEmpty(styleUrl)) { styleUrl = "#blue"; } KmlPolygon polygon = new KmlPolygon(coords.Split(';').ToList()); KmlPlacemark placemark = new KmlPlacemark(name, description, styleUrl, null, null, polygon); ls.Add(placemark); } } try { KmlDocument document = new KmlDocument(xmlname, filename, ls); Kml kml = new Kml(document); kml.GenerateKmlFile("a.kml"); return(1); } catch (Exception e) { return(0); } }
private void AddFeatureToDisplay(KmlFeature feature, bool sky) { KmlDocument doc = feature as KmlDocument; if (doc != null) { sky = doc.sky; } if (!(feature is KmlNetworkLink)) { if (feature.visibility == false) { return; } else if (feature is KmlPlacemark) { KmlPlacemark placemark = (KmlPlacemark)feature; KmlStyle style = placemark.Style.GetStyle(placemark.Selected); Color lineColor = Color.White; if (style != null) { lineColor = style.LineStyle.Color; } if (placemark.geometry is KmlPoint) { placemark.Point = (KmlPoint)placemark.geometry; AddPlacemark(placemark); } else if (placemark.geometry is KmlMultiGeometry) { KmlMultiGeometry geo = (KmlMultiGeometry)placemark.geometry; AddMultiGeometry(sky, placemark, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo); } else if (placemark.geometry is KmlPolygon) { KmlPolygon geo = (KmlPolygon)placemark.geometry; if (geo.OuterBoundary != null) { AddLines(sky, geo.OuterBoundary as KmlLineList, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo.extrude); // to do 3d work and subtract inner rings } } else if (placemark.geometry is KmlLineString) { KmlLineString geo = (KmlLineString)placemark.geometry; List <Vector3d> vertexList = new List <Vector3d>(); for (int i = 0; i < (geo.PointList.Count); i++) { vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius))); } for (int i = 0; i < (geo.PointList.Count - 1); i++) { if (sky) { lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates()); } else { lines.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates()); } } } } if (feature is KmlGroundOverlay && feature.visibility) { AddGroundOverlay(feature as KmlGroundOverlay); } if (feature is KmlScreenOverlay && feature.visibility) { AddScreenOverlay(feature as KmlScreenOverlay); } } if (feature.visibility) { if (feature is KmlContainer) { KmlContainer container = (KmlContainer)feature; if (container.children != null) { foreach (KmlFeature child in container.children) { AddFeatureToDisplay(child, sky); } } } else { if (feature is KmlNetworkLink) { KmlNetworkLink netLink = (KmlNetworkLink)feature; if (netLink.LinkRoot != null) { foreach (KmlFeature child in netLink.LinkRoot.children) { AddFeatureToDisplay(child, sky); } } } } } }
public override void LoadDetails(XmlNode node, KmlRoot owner) { base.LoadDetails(node, owner); foreach (XmlNode child in node.ChildNodes) { KmlGeometry geometry = null; switch (child.Name) { case "Point": { geometry = new KmlPoint(); geometry.LoadDetails(child, owner); } break; case "LineString": { geometry = new KmlLineString(); geometry.LoadDetails(child, owner); } break; case "LinearRing": { geometry = new KmlLinearRing(); geometry.LoadDetails(child, owner); } break; case "Polygon": { geometry = new KmlPolygon(); geometry.LoadDetails(child, owner); } break; case "MultiGeometry": { geometry = new KmlMultiGeometry(); geometry.LoadDetails(child, owner); } break; } if (geometry != null) { Children.Add(geometry); } } if (node["extrude"] != null) { extrude = node["extrude"].InnerText.Trim() == "1"; } if (node["altitudeMode"] != null) { altitudeMode = (altitudeModeEnum)Enum.Parse(typeof(altitudeModeEnum), node["altitudeMode"].InnerText.Trim()); } }
// 添加波束图元 private bool AddBeamElement(Beam beam, Model3D model) { var coverLayer = mapLogic.AddLayer(coverLayerName); var beamLayer = mapLogic.AddLayer(beam.BeamLayerName); if (beamLayer == null) { return(false); } string elementName = beam.BeamName; List <MapLngLat> pointListPolygon = new List <MapLngLat>(); List <MapLngLat> pointListCover = new List <MapLngLat>(); pointListPolygon.Add(model.Coordinate); //pointListCover.Add(new MapLngLat(beam.CenterPoint.Lng, beam.CenterPoint.Lat, 100000)); for (double tempAngle = -180; tempAngle <= 180; tempAngle = tempAngle + beam.StepValue) { var p = Utils.GetPointByDistanceAndAngle(beam.Radius, beam.CenterPoint, tempAngle); if (p != null) { pointListPolygon.Add(p); pointListCover.Add(new MapLngLat(p.Lng, p.Lat, 100000)); } } if (coverLayer != null) { // 创建覆盖图元 Kml polygonCover = new Kml(); polygonCover.Placemark.Name = elementName + "cover"; polygonCover.Placemark.Graph = new KmlPolygon() { Description = elementName + "cover", PositionList = pointListCover, OutLineColor = Color.Red, FillColor = Color.FromArgb(20, Color.Blue), OutLineSize = 2 }; coverLayer.AddElement(polygonCover); // 线 Kml kmlLine = new Kml(); kmlLine.Placemark.Name = elementName + "cover_line"; KmlLineString linekml = new KmlLineString(); linekml.Color = Color.Blue; linekml.Width = 2; linekml.PositionList = pointListCover; linekml.Rasterize = false; kmlLine.Placemark.Graph = linekml; coverLayer.AddElement(kmlLine); } // 创建波束图元 Kml polygonKml = new Kml(); polygonKml.Placemark.Name = elementName; polygonKml.Placemark.Graph = new KmlPolygon() { Description = elementName, PositionList = pointListPolygon, OutLineColor = Color.Red, FillColor = Color.FromArgb(beamAlpha, Color.YellowGreen), OutLineSize = 3 }; if (beamLayer.AddElement(polygonKml)) { EventPublisher.PublishElementAddEvent(this, new ElementAddEventArgs(beam.BeamLayerName, elementName)); } beamLayer.Refresh(); // 波束整体刷新 return(true); }
public virtual GeoJsonLineString Convert(KmlLineString lineString) { double[][] coordinates = lineString.Select(x => new [] { x.Longitude, x.Latitude }).ToArray(); return(new GeoJsonLineString(coordinates)); }
/// <summary> /// 鼠标单击,开始测量 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && gmapControl.CanDragMap == false) { if (isFinish == true) { foreach (var item in markerList) { mapOverlay.Markers.Remove(item); } mapOverlay.Routes.Remove(lineRoute); isFinish = false; //ReleaseCommond(); //return; } string name = string.Format("point_{0}", pointIndex); var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); if (pointIndex == 0) // 第一个点 { // 加点 marker = new EditMarker(lngLat); marker.ToolTipMode = MarkerTooltipMode.Always; marker.ToolTipText = string.Format("起点\n经度:{0}\n纬度:{1}\n", Math.Round(lngLat.Lng, 6), Math.Round(lngLat.Lat, 6)); mapOverlay.Markers.Add(marker); marker.ToolTip.Format.Alignment = StringAlignment.Near; // 加线 KmlLineString linekml = new KmlLineString(); linekml.Color = Color.Green; linekml.Width = 3; List <MapLngLat> pList = new List <MapLngLat>(); pList.Add(new MapLngLat(lngLat.Lng, lngLat.Lat)); linekml.PositionList = pList; lineRoute = new Line_GMap("measure_line", linekml); mapOverlay.Routes.Add(lineRoute); pointIndex++; } else { pointIndex++; // 添加点 lineRoute.Points.Add(lngLat); lineRoute.AddPoint(new MapLngLat(lngLat.Lng, lngLat.Lat)); gmapControl.Refresh(); // 添加Marker marker = new EditMarker(lngLat); mapOverlay.Markers.Add(marker); distance = lineRoute.Distance; distance = Math.Round(distance, 3); marker.ToolTipMode = MarkerTooltipMode.Always; marker.ToolTipText = string.Format("点{0}\n经度:{1}\n纬度:{2}\n距离:{3}(公里)", pointIndex, Math.Round(lngLat.Lng, 6), Math.Round(lngLat.Lat, 6), distance); marker.ToolTip.Format.Alignment = StringAlignment.Near; } markerList.Add(marker); } }