[英]Openlayers: feature.get returns the attributes path
I have an openlayers map with a point layer that on click on a feature opens a popup. 我有一个带点图层的openlayers地图,在单击要素时会打开一个弹出窗口。 Inside the popup I show a clickable link that is supposed to lead to a url that is stored inside the attribute table of the layer. 在弹出窗口中,我显示了一个可单击的链接,该链接应该指向存储在图层的属性表中的URL。
But if I click the layer a link opens to a path like "C:/Users/user/.../URL". 但是,如果单击该层,则会打开一个指向“ C:/ Users / user /.../ URL”之类的路径的链接。 The URL is all I want to have, but the browser also opens the path to where the project is saved. URL是我想要的,但浏览器还会打开保存项目的路径。
My code: 我的代码:
map.on('click', function(event) {
var feature = map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
if (layer === knoten) {
return feature;
}
});
if (feature != null) {
var pixel = event.pixel;
var coord = map.getCoordinateFromPixel(pixel);
popup.setPosition(coord);
$(elementPopup).attr('data-content', '<b>1: </b>' + ' ' + feature.get('ERHEB_NR') +
'</br><b>2: </b>' + '   ' + '<a id="link" target="_blank" rel="noopener noreferrer">Link</a>');
$(elementPopup).popover({'placement': 'top', 'html': true});
$(elementPopup).popover('show');
document.getElementById('link').href = feature.get('KATASTER')
}
else {
$(elementPopup).popover({'html': true});
$(elementPopup).popover('hide');
}
});
If I substitute '<a id="link" target="_blank" rel="noopener noreferrer">Link</a>'
for feature.get('KATASTER')
the correct link appears (but since since it is not inside the statement it is not clickable). 如果我将'<a id="link" target="_blank" rel="noopener noreferrer">Link</a>'
替换为feature.get('KATASTER')
,则会显示正确的链接(但因为它不在内部该语句不可点击)。
What about intializing the popever with the content
option, instead updating only the link? 如何使用content
选项初始化popever而不是仅更新链接?
map.on('click', function(event) {
var feature = map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
if (layer === knoten) {
return feature;
}
});
// Always hide the popover
$(elementPopup).popover('hide');
if (feature != null) {
var pixel = event.pixel;
var coord = map.getCoordinateFromPixel(pixel);
popup.setPosition(coord);
$(elementPopup).popover({
placement: 'top',
animation: false,
html: true,
trigger: 'focus',
title: "",
content: '<b>1: </b>' + ' ' + feature.get('ERHEB_NR') +
'</br><b>2: </b>' + '   ' + '<a id="link" target="_blank" href="'+feature.get('KATASTER')+'" rel="noopener noreferrer">Link</a>'
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.