使用C#编写KML - ScreenOverlay [英] Writing a KML using C# - ScreenOverlay

查看:128
本文介绍了使用C#编写KML - ScreenOverlay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我在C#中制作的程序在Google地图上覆盖叠加层。我似乎无法弄清楚代码,以获得覆盖的位置,我想要它。它只是坐在页面中间,无论我尝试什么。



这是我的代码:

  kml.WriteStartElement( ScreenOverlay的); 
kml.WriteElementString(name,elephant);
kml.WriteStartElement(Icon);
kml.WriteElementString(href,images / elephant.jpg);

//这是我在下面找不到的部分

kml.WriteStartElement(overlayXY,x ='0'y ='0'xunits = 'fraction'yunits ='fraction'/);
kml.WriteStartElement(screenXY,x ='0'y ='0'xunits ='像素'yunits ='像素'/);
kml.WriteStartElement(rotationXY,x ='0'y ='0'xunits ='fraction'yunits ='fraction'/);
kml.WriteStartElement(size,x ='0'y ='0'xunits ='像素'yunits ='像素'/);

kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();

这段代码是我最近的尝试。它虽然没有工作。 大象图像仍然保留在屏幕中间。如果你使用的是 System.Xml.XmlTextWriter 类生成KML输出,然后WriteStartElement()的第二个参数是元素名称空间,而不是属性,Icon元素必须在启动overlayXY元素之前结束,否则生成的输出是无效的KML。



语法如下:

  [C#] 
public void WriteStartElement(
字符串localName,
字符串ns
);

您需要将代码更改为:

  XmlTextWriter kml = new XmlTextWriter(...)
kml.Formatting = Formatting.Indented;
kml.WriteStartElement(kml,http://www.opengis.net/kml/2.2);
kml.WriteStartElement(ScreenOverlay);
kml.WriteElementString(name,elephant);
kml.WriteStartElement(Icon);
kml.WriteElementString(href,images / elephant.jpg);
kml.WriteEndElement(); // Icon

kml.WriteStartElement(overlayXY);
kml.WriteAttributeString(x,0);
kml.WriteAttributeString(y,0);
kml.WriteAttributeString(xunits,fraction);
kml.WriteAttributeString(yunits,fraction);
kml.WriteEndElement(); // overlayXY

kml.WriteStartElement(screenXY);
kml.WriteAttributeString(x,0);
kml.WriteAttributeString(y,0);
kml.WriteAttributeString(xunits,pixels);
kml.WriteAttributeString(yunits,pixels);
kml.WriteEndElement(); // screenXY
...
kml.WriteEndElement(); // ScreenOverlay
kml.WriteEndElement(); // kml



提示:当您使用应用程序比谷歌地球),你应该总是验证你的KML。您可以将您的KML发布到 Galdos KML验证工具,该工具不仅会向KML XML Schema报告任何错误,还会报告任何错误也与OGC KML规范有关。

I am trying to get an overlay on google maps using a program I am making in C#. I can't seem to figure out the code to get the position of the overlay where I want it. It just sits right in the middle of the page no matter what I try.

Here is my code:

kml.WriteStartElement("ScreenOverlay");
kml.WriteElementString("name", "elephant");
kml.WriteStartElement("Icon");
kml.WriteElementString("href", "images/elephant.jpg");

//This is the part I can't figure out below

kml.WriteStartElement("overlayXY", "x='0' y='0' xunits='fraction' yunits='fraction'/");
kml.WriteStartElement("screenXY", "x='0' y='0' xunits='pixels' yunits='pixels'/");
kml.WriteStartElement("rotationXY", "x='0' y='0' xunits='fraction' yunits='fraction'/");
kml.WriteStartElement("size", "x='0' y='0' xunits='pixels' yunits='pixels'/");

kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();
kml.WriteEndElement();

That code was my latest attempt. It didn't work though. The "elephant" image still remains in the middle of the screen. I'm a beginner (if it wasn't obvious!).

解决方案

If you're using the System.Xml.XmlTextWriter class in C# to generate KML ouput then the second argument of WriteStartElement() is the element namespace not the attributes and the Icon element must end before starting the overlayXY element otherwise the generated output is invalid KML.

The syntax is this:

[C#]
public void WriteStartElement(
 string localName,
 string ns
);

You need instead to change the code into this:

  XmlTextWriter kml = new XmlTextWriter(...)
  kml.Formatting = Formatting.Indented;
  kml.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
  kml.WriteStartElement("ScreenOverlay");
  kml.WriteElementString("name", "elephant");
  kml.WriteStartElement("Icon");
  kml.WriteElementString("href", "images/elephant.jpg");
  kml.WriteEndElement(); // Icon

  kml.WriteStartElement("overlayXY");    
  kml.WriteAttributeString("x", "0");
  kml.WriteAttributeString("y", "0");
  kml.WriteAttributeString("xunits", "fraction");
  kml.WriteAttributeString("yunits", "fraction");
  kml.WriteEndElement(); // overlayXY

  kml.WriteStartElement("screenXY");
  kml.WriteAttributeString("x", "0");
  kml.WriteAttributeString("y", "0");
  kml.WriteAttributeString("xunits", "pixels");
  kml.WriteAttributeString("yunits", "pixels");
  kml.WriteEndElement(); // screenXY
  ...
  kml.WriteEndElement(); // ScreenOverlay
  kml.WriteEndElement(); // kml


TIP: When you generate KML with an application (other than Google Earth) you should always validate your KML. You can post your KML to Galdos KML Validator, which will report any errors not only to the KML XML Schema but also pertaining to the OGC KML Specifiation.

这篇关于使用C#编写KML - ScreenOverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆