具有外部样式的 openlayers kml

发布于 2024-10-27 12:35:26 字数 645 浏览 7 评论 0原文

我正在尝试将我的 kml 样式移动到外部文档以与 OpenLayers 一起使用。当样式直接包含在 kml 文件中时,它们才有效。

起初我以为我可以使用带有 styleUrl 标签的直接 kml 来实现此目的:

<styleUrl>http://localhost/map.kml#myIcon</styleUrl>

但是,当我尝试这样做时,map.kml 文件永远不会被请求,并且标记不会显示。我已经验证 styleUrl 网址有效。

我正在使用以下方式加载 KML:

new OpenLayers.Layer.GML('Name', 'kml_path', {
  format: OpenLayers.Format.KML,
    formatOptions: {
      extractStyles: true,
      extractAttributes: true
    },
    projection: map.displayProjection
});

OpenLayers.Format.KML API 中有一些名为“styles”和“styleBaseUrl”的诱人选项,但我找不到任何有关它们的用途或如何使用它们的文档。有人有这些方面的经验吗?

I'm trying to move my kml styles to an external document for use with OpenLayers. The styles work when they are included directly in the kml file.

At first I thought I could use straight kml for this with the styleUrl tag:

<styleUrl>http://localhost/map.kml#myIcon</styleUrl>

However, when I try to do that, the map.kml file never gets requested, and the markers don't show up. I've verified that the styleUrl url works.

I'm loading my kml using:

new OpenLayers.Layer.GML('Name', 'kml_path', {
  format: OpenLayers.Format.KML,
    formatOptions: {
      extractStyles: true,
      extractAttributes: true
    },
    projection: map.displayProjection
});

There are some tantalizing options called 'styles' and 'styleBaseUrl' in the OpenLayers.Format.KML API, but I cannot find any documentation about what they are for or how to use them. Does anyone have any experience with these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤单情人 2024-11-03 12:35:26

一种方法是,拥有一个带有样式的单独的 SLD 外部文件,并将其应用到您的 GML 图层。

查看 SLD OpenLayers 代码示例,网址为 http://openlayers.org/dev/examples/sld .html 并将示例图层替换为您的图层,并替换 sld-tasmania.xml 文件中的样式。这样,您就不需要 formatOptions 中的 extractStyles 选项。

One way could be, have a separate SLD external file with styles and apply it to your GML layer.

Take a look at the SLD OpenLayers code example at http://openlayers.org/dev/examples/sld.html and just replace the example layers with your layer and replace the styles in the sld-tasmania.xml file. This way, you would not need the option extractStyles in the formatOptions.

绅士风度i 2024-11-03 12:35:26

在 formatOptions 中,尝试添加 maxDepth:10 或某个此类整数。这是 api 定义。

maxDepth:{Integer} 递归加载外部 KML URL 的最大深度 默认为 0:不进行外部提取

如果默认为 0,我怀疑它会下载 0 个外部 kml 文件。

In formatOptions, try adding maxDepth:10 or some such integer. Here is the api definition.

maxDepth:{Integer} Maximum depth for recursive loading external KML URLs Defaults to 0: do no external fetching

With it defaulting to 0, I would suspect that it downloads 0 external kml files.

早茶月光 2024-11-03 12:35:26

我真的没有任何关于 KML 的经验,所以如果这完全关闭,我很抱歉。我刚刚阅读了 KML 图层的代码,尤其是样式部分。从您的 styleUrl 标记来看,基于 KML.js 中的代码,styleBaseUrl 应该是 http://localhost/map.kml :

parseStyleMaps():

this.styles[(options.styleBaseUrl || "") + "#" + id] =
                    this.styles[(options.styleBaseUrl || "") + styleUrl];

parseStyles():

var styleName = (options.styleBaseUrl || "") + "#" + style.id;

styles 参数似乎在每次代码读取数据时都会被初始化和重写,所以我认为这不会有任何好处。

I really don't have any experience on KML, so I'm sorry if this is totally off. I just read the code for KML layers, especially the style portions. From your styleUrl tag it looks as the styleBaseUrl should be http://localhost/map.kml, based on the code in KML.js:

parseStyleMaps():

this.styles[(options.styleBaseUrl || "") + "#" + id] =
                    this.styles[(options.styleBaseUrl || "") + styleUrl];

parseStyles():

var styleName = (options.styleBaseUrl || "") + "#" + style.id;

The styles parameter seems to be initialized and rewritten each time the code reads the data, so that won't do any good I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文