0

我正在尝试在 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 =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>

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

4

1 回答 1

0

如果您使用 Google Fusion Tables UI 指定样式,则必须指定在styleId使用 JavaScript 加载 FusionTablesLayer 时要使用的样式。否则使用默认样式。您可以在 docs中找到有关此内容的详细信息。

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

用上面的代码创建了一个 jsFiddle

通过向 Fusion Table 添加多个“地图视图”,您可以指定更多样式。默认样式是1,每个后续都有一个 id + 1。

或者,您也可以直接使用 JavaScript 指定样式

于 2013-07-23T08:57:10.153 回答