简体   繁体   English

将图片从GeoJSON文件添加到信息窗口? Google Maps JavaScript API

[英]Adding images to an info window from a GeoJSON file? Google maps javascript API

Basically, I want to display an info window from a marker that can show several information from a GeoJSON file, such as date, hour and type of event (I can do all of this by now)... but I also need a specific image for each marker info window . 基本上,我想从标记显示一个信息窗口,该窗口可以显示来自GeoJSON文件的多个信息,例如日期,小时和事件类型(我现在可以完成所有这些操作)... 但是我还需要一个特定的每个标记信息窗口的图像

  var infowindow = new google.maps.InfoWindow();

  map.data.addListener('click', function(event) {

  var myIMAGE = event.feature.getProperty("Image");
  var myDATE = event.feature.getProperty("Date");
  var myHOUR = event.feature.getProperty("Hour");     
  var myCATEGORY = event.feature.getProperty("Category");

  infowindow.setContent("<div style='width:150px; text-align: left;'>"+"<b>Category: </b>"+myCATEGORY +"<br>"+"<b>Date: </b>"+ myDATE +"<br>"+"<b>Hour: </b>"+myHOUR +"<br>" +"<b>Image:</b>" +"<br>" + "<img src= 'myIMAGEN' alt='Dale la Cara AC' >" + "</div>");

l know that the possible mistake is in: 我知道可能的错误在于:

+ "<img src= 'myIMAGE' alt='Dale la Cara AC'>"

This is my GeoJSON string: 这是我的GeoJSON字符串:

{"id":"MPBA001","properties":{"Image":"http://storage.googleapis.com/ops_geojson/Flecker/Icons/Atoyac/Marcador_BasuraEnBarrancas.png","Latitude":19.0225448527012,"Category":"Agua","Date":"21/03","Hour":"21:00pm","ID":"MPBA001","Longitude":-98.1973242759704}, "type":"Feature","geometry":{"type":"Point","coordinates":[-98.1973242759704,19.0225448527012]}}

Each info window has a different image within. 每个信息窗口中都有一个不同的图像。 Is there a way to call the link from my GeoJSON string to the 'src' value? 有没有一种方法可以调用从我的GeoJSON字符串到'src'值的链接? So I can display this image in my info window. 因此,我可以在我的信息窗口中显示此图像。

Thanks! 谢谢!

it should be: 它应该是:

+ "<img src= '" + myIMAGE + "' alt='Dale la Cara AC'>"

currently you set the src of the <img/> to the string myIMAGE and not the the value of the variable myIMAGE 当前,您将<img/>src设置为字符串myIMAGE而不是变量myIMAGE的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM