网站的地图/ Fusion Tables中图标的颜色和颜色以及线宽没有变化

时间:2013-07-04 20:21:33

标签: colors width google-fusion-tables polyline

我正在尝试在Google地图上创建斯德哥尔摩地铁的地图。 我创建了一个KML文件:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
   <Document>
    <name>Stockholm's subway: line line Nr.11</name>
    <description>Map of Stockholm's subway: line Nr.T-11 "Akalla - Kungstr&#228;dg&#229;rden"</description>
    <Style id="blueLine"> 
      <LineStyle>
        <color>483D8B</color>
        <width>2</width>
      </LineStyle>
    </Style>
    <Placemark>
      <styleUrl>#blueLine</styleUrl>
      <LineString>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <coordinates>17.912350,59.414813,0
        17.925637,59.410259,0
        17.942434,59.402864,0
        17.969320,59.375223,0
        17.983280,59.366738,0
        17.998652,59.359052,0
        18.003989,59.347479,0
        18.017318,59.336963,0
        18.032405,59.334372,0
        18.042068,59.330300,0
        18.059263,59.330947,0
        18.073294,59.330784,0</coordinates>
      </LineString>
    </Placemark>
    <Placemark>
      <name>Akalla</name>
      <Point>
        <coordinates>17.912350,59.414813,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Husby</name>
      <Point>
        <coordinates>17.925637,59.410259,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Kista</name>
      <Point>
        <coordinates>17.942434,59.402864,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Hallonbergen</name>
      <Point>
        <coordinates>17.969320,59.375223,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>N&#228;ckrosen</name>
      <Point>
        <coordinates>17.983280,59.366738,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Solna centrum</name>
      <Point>
        <coordinates>17.998652,59.359052,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>V&#228;stra skogen</name>
      <Point>
        <coordinates>18.003989,59.347479,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Stadshagen</name>
      <Point>
        <coordinates>18.017318,59.336963,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Fridhemsplan</name>
      <Point>
        <coordinates>18.032405,59.334372,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>R&#229;dhuset</name>
      <Point>
        <coordinates>18.042068,59.330300,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>T-centralen</name>
      <Point>
        <coordinates>18.059263,59.330947,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Kungstr&#228;dg&#229;rden</name>
      <Point>
        <coordinates>18.073294,59.330784,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

这个文件导入了Fusion Tables并创建了一个地图 https://www.google.com/fusiontables/embedviz?q=select+col2+from+1qOgLRMpis-JxxfNEk_OyGR9mLu9atHiEnePWx5I&viz=MAP&h=false&lat=59.37122726416546&lng=18.102341958496122&t=1&z=11&l=col2&y=2&tmplt=2

在样式中,我更改了折线的宽度(4)和颜色(蓝色)以及图标(蓝色)的颜色。 我使用JavaScript代码调用了地图:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Map of Stockholm's subway line T-11: 
    "Akalla - Kungstr&#228;dg&#229;rden"</title>
    <link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=en"></script>
    <script>
function initialize() {

  var map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: new google.maps.LatLng(59.347479,18.003989),
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var layer = new google.maps.FusionTablesLayer({
    query: {
      select: 'location',
      from: '1qOgLRMpis-JxxfNEk_OyGR9mLu9atHiEnePWx5I'
    },
    heatmap: {
      enabled: false
    }
  });

  layer.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas" style="width=100%"></div>
  </body>
</html>

但是图标和颜色以及折线宽度的颜色没有变化 - 保持红色。 我的错是什么?

1 个答案:

答案 0 :(得分:0)

如果您使用Google Fusion Tables UI指定样式,则必须指定在使用JavaScript加载FusionTablesLayer时要用于显示的styleId。否则使用默认样式。你可以找到关于这个in the docs的详细信息。

var layer = new google.maps.FusionTablesLayer({
  query: {
    select: 'location'
    from: '1qOgLRMpis-JxxfNEk_OyGR9mLu9atHiEnePWx5I'
  },
  styleId: 2
});

我创建了一个jsFiddle with the code above

通过向Fusion Table添加多个“地图视图”,您可以指定更多样式。默认样式为1,后面的每个样式都会获得一个id + 1。

或者你也可以specify the style directly with JavaScript