1
我想知道是否有人能够帮助我。动态添加图像到Infowindow
我用下面的代码加载图像到HTML页面,这是pertient到当前的“位置”和“用户”的ID。
<div id="galleria">
<?php
$dirlist = getFileList($galleryPath, true);
$x = 0;
foreach($dirlist as $file) {
if((preg_match("/\.jpg$/", $file['name'])) or (preg_match("/\.jpeg$/", $file['name'])) or (preg_match("/\.png$/", $file['name'])) or (preg_match("/\.bmp$/", $file['name'])) or (preg_match("/\.gif$/", $file['name']))) {
echo "<img src='{$file['name']}' />";
$x = 1;
}
}
if ($x == 0) {
echo "<img src='images/noimage.jpg' />";
}
?>
</div>
这工作正常,但我有两个方面的困难。我试图仅显示第一张图片,并将该图片放在“Infowindow”而不是主页面上。但我必须绝对诚实,并说我甚至不知道从哪里开始。为了达到这一点,我花了几天的时间。
下面的代码是摘录从创建标记和Infowindow的脚本。
downloadUrl("loadlocationfinds.php?locationid=<?php echo $lid?>", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
var findid = markers[i].getAttribute("findid");
var locationid = markers[i].getAttribute("locationid");
var findosgb36lat = markers[i].getAttribute("findosgb36lat");
var findosgb36lon = markers[i].getAttribute("findosgb36lon");
var findcategory = markers[i].getAttribute("findcategory");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("findosgb36lat")),
parseFloat(markers[i].getAttribute("findosgb36lon")));
var html = "<span class='h3 orange'><strong>" + 'Item Found: ' + "</strong></span><br>" + finddescription + "<br>";
var icon = customIcons[findcategory] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
title: 'Click to view details',
icon: icon.icon,
shadow: icon.shadow,
formfindosgb36lat: findosgb36lat,
formfindosgb36lon: findosgb36lon,
formfindcategory: findcategory,
});
bounds.extend(point);
map.fitBounds(bounds);
bindInfoWindow(marker, map, infoWindow, html);
google.maps.event.addListener(marker, "click", function() {
document.getElementById('findosgb36lat').value = this.formfindosgb36lat;
document.getElementById('findosgb36lon').value = this.formfindosgb36lon;
document.getElementById('findcategory').value = this.formfindcategory;
});
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker, html);
});
}
我只是想知道是否有人也许可以看看这个,请,并提供一点点帮助,使我能够在“Infowindwow”中只显示前图像。
非常感谢和最亲切的问候
嗨@david strachan,感谢您花时间回复我的帖子。我将我的'var HTML'行更改为: 'var html =“”+“项实测值:'+ “
” + finddescription + “
”; html + =“”alt = \“My Image \”height = \“y \”width = \“x \”>
“' 但是,我必须做错了什么,因为地图不再创建该页面。 我只是想知道你是否可能能够提供在何处伊夫出了错一些指导。非常感谢和亲切的问候 – IRHM
嗨@大卫斯特拉坎。我只是想给你一个更新,我已经成功地得到了图像转化为信息窗口,但我无法调整图像使用你的建议,我的“无功HTML”行如下:。 'VAR HTML =“的” +“发现商品:“+ ”
“ + finddescription +”
“; 的html + = “<?PHP的echo” “?> HEIGHT = \” 10px的\ “WIDTH = \ ”10px的\“>
”' 我只是想知道你是否有可能来看看这个,请,让提供一些方向我可能会出错的地方? 许多的感谢和亲切的问候 – IRHM
我正要张贴关于您的拼写错误,但你打我给它。是否更改'高度= \“10px \”width = \“10px \”'为不同的值不能解决此问题 –