OpenLayers 标签问题

发布于 2024-11-03 00:43:39 字数 531 浏览 1 评论 0原文

我对 OpenLayers.Feature.Vector 上的标签有一个大问题。当我使用 Canvas 渲染器时,所有标签都位于功能的 externalGraphic 下。您可以在这里看到:

http://jsfiddle.net/67aaJ/

不知道如何强制标签涂在标记上。使用 SVG 渲染器在标记上添加标签是否很容易,但在这种情况下,当存在多个标记时,标签看起来很混乱。看起来第一个渲染器绘制了所有图形和所有标签。示例:

http://jsfiddle.net/6kXYh/1/

我正在寻找解决方案(渲染器没关系)显示带有标签的标记,但没有“标签冲突”,假设我们在一个位置有 5 个标记,但具有不同的标签,我希望看到最后添加的功能 externalGraphic 及其标签,以前的功能(和标签)应该在最后一项之下。

请帮忙!谢谢。

I have a big problem with labels over OpenLayers.Feature.Vector. When I use Canvas renderer all labels are under the externalGraphic of feature. What you can see here:

http://jsfiddle.net/67aaJ/

Do not know how to force labels to be painted over markers. Is it easy to have labels over markers using let say SVG renderer, but in this case labels look messy when there is more than one marker in place. It looks like first renderer paint all graphic and than all labels. Example:

http://jsfiddle.net/6kXYh/1/

I am looking for a solution (renderer does not matter) to display markers with labels over it but without "labels colisions", let say we have 5 markers in one position but with different labels I am expecting to see last added feature externalGraphic and its label, previous features (and labels) should be under last one.

Please help! Thank you.

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

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

发布评论

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

评论(2

檐上三寸雪 2024-11-10 00:43:39

据我所知,OpenLayers 没有任何标签冲突检测功能。我想你必须自己做或者依赖后端的一些地图软件。

OpenLayers don't have any label collision detection that I'm aware of. I suppose you will have to do it yourself or rely on some mapping software in the backend.

记忆消瘦 2024-11-10 00:43:39

很抱歉回答一个非常老的问题,但对于其他遇到这个问题的人来说,另一种解决方案可能是使用集群策略并标记集群。对于具有超过 1 个特征的集群,您可以用逗号分隔或 \n 分隔。例如这里的代码:

var style = new OpenLayers.Style({
  label: "${type}",
  fillColor: "#ffcc66",
  fillOpacity: 0.8,
  strokeColor: "#cc6633",
  strokeWidth: 2,
  strokeOpacity: 0.8
}, {
  context: {
     type: function(feature) {
       // concatenate labels and return
       return "the label";
     }
   }
});

改编自:
http://openlayers.org/dev/examples/strategy-cluster.html

Apologies for answering a very old question, but for others coming upon this question, an alternative solution could be to use the Cluster Strategy and label the cluster. for clusters with more than 1 feature, you could comma separate or \n separate. Eg code here:

var style = new OpenLayers.Style({
  label: "${type}",
  fillColor: "#ffcc66",
  fillOpacity: 0.8,
  strokeColor: "#cc6633",
  strokeWidth: 2,
  strokeOpacity: 0.8
}, {
  context: {
     type: function(feature) {
       // concatenate labels and return
       return "the label";
     }
   }
});

adaped from:
http://openlayers.org/dev/examples/strategy-cluster.html

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