javascript - 将 geojson 属性设为链接
问题描述
我有一个包含 geojson 的外部 js 脚本。在该 geojson 对象中有属性,其中一个属性是 url。我需要在弹出窗口中将该网址显示为可点击的链接。现在,我的弹出窗口中有 url,但它只是显示为字符串。
我试图将 geojson 属性存储到一个名为 assemblyWebsite 的新变量中,然后将 assemblyWebsite 输入到我的弹出窗口中。尽管如此,它仍然具有作为字符串的变量。考虑到 url 取决于用户点击的多边形,我无法弄清楚如何将该变量变成可点击的链接。有几个不同的 url,每个弹出窗口不能是一个 url。
function onEachFeature(feature, layer) {
var assemblyWebsite = feature.properties.QnsPubAdvocateResults_URL
layer.bindPopup('<h4>Assembly District</h4>' + ' ' + feature.properties.AssemDist + '</b><br />' + 'Website:' + ' ' + assemblyWebsite);
};
解决方案
您可以使用 href 像链接一样显示。
var layerGroup = L.geoJSON(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup('<h4>Assembly District</h4>' + ' ' + feature.properties.AssemDist + '</b><br />' + 'Website:' + ' ' + '<a href="'+
assemblyWebsite + '">Visit Website</a>' );
}
}).addTo(map);
推荐阅读
- python - 实现具有重复值的二叉搜索树
- ios - 如何在简单的计算中避免 Nil / nan
- angular - 为什么即使我取消订阅,我仍然从我的 webflux spring boot 获取数据?
- javascript - 开发服务器返回响应错误码:500 react native
- avl-tree - 如何获得 AVL 树的高度?
- python - 圆形面积函数
- excel - 将每个 excel 列数据保存到单独的文本文件中
- java - 获得响应后如何开始解析 HTML 页面而不等待 JavaScript (Java HtmlUnit)?
- javascript - NetBeans 9.0 Mac OSX 找不到 HTML/JS 项目模板
- django - Django 查询集过滤和注释