0

我正在使用 javascript 和 v3 的 maps API 从 Fusion Table 中提取一些数据。我已经成功地向某些点添加了一些自定义标记,但现在我试图将我创建的标记“默认”到从我的表格中名为“图标”的列中指定的图标。我没有使用融合表层,而是在数据的 for 循环中创建标记。我表中的图标列包含以下条目:“poi”、“star”等...

有什么方法可以使用名称字符串以某种方式获取像融合表层那样的“默认”图标?或者,有谁知道我在哪里可以找到默认融合表图标(例如 POI 和星号)的绝对位置,以便我可以在脚本中定义它们的路径?

这是一些示例代码。如果有人知道谷歌上图标的绝对 URL,我可以编写一个函数来根据“图标”列中的字符串输入它。

      //if there's an image, use it as marker, else use default      
  if(row[3] != ''){
      // Create the marker
      var marker = new google.maps.Marker({
        map: map, 
        position: coordinate,
        icon: new google.maps.MarkerImage(row[3])
      });      
  } else {
      // Create the marker
      var marker = new google.maps.Marker({
        map: map, 
        position: coordinate

        //icon: row[2] (row[2] is the Icon column. 
        // I'm assuming I'll just need a conditional to check
        // for the name (such as 'poi') and then to put in the absolute URL for each respectively
        // the problem is I don't know the absolute URL's for these icons. Thanks.
      });
        }
4

1 回答 1

1

我正在寻找几乎完全相同的过程。虽然,我所做的只是让我在 Fusion Table 中的列描述标记,因此,在你的情况下,这将是“Poi”、“Star”等。我的则是“照片”、“视频”、“歌曲”。 " 然后,代码如下:

  var image = new google.maps.MarkerImage('img/CF_Orange.png',
  new google.maps.Size(25, 25),
  new google.maps.Point(0,0),
  new google.maps.Point(12.5,12.5));

  var image2 = new google.maps.MarkerImage('img/CF_Purple.png',
  new google.maps.Size(25, 25),
  new google.maps.Point(0,0),
  new google.maps.Point(12.5,12.5));

  var image3 = new google.maps.MarkerImage('img/CF_Green.png',
  new google.maps.Size(25, 25),
  new google.maps.Point(0,0),
  new google.maps.Point(12.5,12.5));

if(row[5] == 'photo'){
  var marker = new google.maps.Marker({
    map: map, 
    position: coordinate,
    icon: image
  });      
} else if(row[5] == 'video'){
  var marker = new google.maps.Marker({
    map: map, 
    position: coordinate,
    icon: image2
  });
} else {
  var marker = new google.maps.Marker({
    map: map, 
    position: coordinate,
    icon: image3
  });
    }
于 2011-07-19T12:34:05.063 回答