如何使用Google Maps API绘制南非各省的较暗边界

时间:2013-10-21 13:15:01

标签: javascript google-maps google-maps-api-3 google-api

我正在使用Google Maps API。我来自南非,想要展示一张南非地图,其边界清楚地标明了各省。我在南非的网页上有地图,但我不知道如何让用户看到各省的边界更加明显。有一些点缀的浅灰色线条,我假设它是各省的边界线?

我的地图HTML容器:

<div id="map-canvas"></div>

我的JavaScript:

<script type="text/javascript">
     var map;

     function initialize() {
          var mapOptions = {
               center: new google.maps.LatLng(-33.49559749315654, 20.93444836718755),
               zoom: 8,
               mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          map = new google.maps.Map(document.getElementById("map-canvas"),
               mapOptions);
     }

     google.maps.event.addDomListener(window, 'load', initialize);
</script>

如何让南非各省的边界线变得更暗。

1 个答案:

答案 0 :(得分:0)

您需要自己绘制边框。

最简单的方法:使用FusionTablesLayer,这是一个包含省份几何图形的融合表:https://www.google.com/fusiontables/DataSource?docid=16L-UK_1OZxGw6DlKR8V8yP4XZrtmNdOMugRRNrQ#map:id=3

用法:

<script type="text/javascript">
  function initialize() {
     var map = new google.maps.Map(document.getElementById('map-canvas'), {
      center: new google.maps.LatLng(-33.49559749315654, 20.93444836718755),
               zoom: 4,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    //create the layer
    layer = new google.maps.FusionTablesLayer({
      map: map,
      //the layer doesn't need to be clickable
      clickable:false,
      query: {
      //column with the geometry
        select: "col2",
      //table-ID
        from: "16L-UK_1OZxGw6DlKR8V8yP4XZrtmNdOMugRRNrQ",
        where: ""
      },
      styles: [{
        polygonOptions: {
        //border-color
        strokeColor: "#000000",
        //border-width
        strokeWeight: 2,
        //hide the fill
        fillOpacity:0.0001
      }}]
    });
  }

  google.maps.event.addDomListener(window, 'load', initialize);
</script>