首页 > 解决方案 > Leaflet - 个性化工具提示

问题描述

我正在尝试个性化传单工具提示以仅显示某些功能。

我的代码如下

var source = L.WMS.source(
  "http://13.59.209.218:8080/geoserver/ec2_3/wms?",
  options
);
var LandMaps = source.getLayer("ec2_3:PLOTSEDIT", {
  onEachFeature: function (feature, layer) {
    if (feature.properties) {
      var content =
        "<table class='table table-striped table-bordered table-condensed'>" +
        "<tr><th>ID</th><td>" + feature.properties.id + "</td></tr>" +
        "<tr><th>Plot No</th><td>" + feature.properties.plotno_1 + "</td></tr>" +
        "<tr><th>FR Source</th><td>" + feature.properties.frsrcname + "</td></tr>" +
        "<tr><th>More Details</th><td><a href= 'MoreDetails.html' target='_blank'></a></td></tr>" +
        "<table>";
      layer.bindPopup(content);
      console.log(feature.properties);
    }
  },
});
LandMaps.addTo(map);

结果仍然是默认工具提示,没有任何格式。如何使用我的代码指定自定义工具提示。我已经为您的测试提供了测试地理服务器。

问候,

詹姆士

标签: javascriptleaflettooltipgisgeoserver

解决方案


WMS 没有 onEachFeature 参考。

经过一番搜索,我发现只需在 Geoserver 上使用 WFS 并在 WEBINF 的 web.xml 文件中启用 JSONP。

这是我使用的代码

在此处输入链接描述


推荐阅读