如何使我的地图边框更厚的Google Geomap?

时间:2015-02-13 18:57:08

标签: javascript html css geography

我正在使用我的deploying to google appengine的dhtml地图。现在我想让边框变得更暗更厚。怎么做到呢?我已经部署了这张地图

enter image description here

我的模型看起来如下

enter image description here我们可以尝试让我的地图看起来更像样机吗?我到目前为止的代码就是这个。

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
    <style xmlns="http://www.w3.org/2000/svg">
        path { fill: #ffc801; }
        :hover { fill: #fcafff; }
      </style>

    <script type='text/javascript' src='http://www.google.com/jsapi'></script>
    <script type='text/javascript'>google.load('visualization', '1', {'packages': ['geochart']});

      google.setOnLoadCallback(drawVisualization);

        function drawVisualization() {var data = new google.visualization.DataTable();

       data.addColumn('string', 'Country');
       data.addColumn('number', 'Value'); 
       data.addColumn({type:'string', role:'tooltip'});var ivalue = new Array();

       var options = {
       backgroundColor: {fill:'#FFFFFF',stroke:'#FFFFFF' ,strokeWidth:25 },
       colorAxis:  {minValue: 0, maxValue: 0,  colors: []},
       legend: 'none',    
       backgroundColor: {fill:'#FFFFFF',stroke:'#FFFFFF' ,strokeWidth:25 },   
       datalessRegionColor: '#ffc801',
       displayMode: 'regions', 
       enableRegionInteractivity: 'true', 
       resolution: 'provinces',
       sizeAxis: {minValue: 1, maxValue:1,minSize:10,  maxSize: 10},
       region:'IN',
       keepAspectRatio: true,
       width:600,
       height:400,
       tooltip: {textStyle: {color: '#444444'}, trigger:'focus', isHtml: false}   
       };
        var chart = new google.visualization.GeoChart(document.getElementById('visualization')); 
        google.visualization.events.addListener(chart, 'select', function() {
        var selection = chart.getSelection();
        if (selection.length == 1) {
        var selectedRow = selection[0].row;
        var selectedRegion = data.getValue(selectedRow, 0);
        if(ivalue[selectedRegion] != '') { document.location = ivalue[selectedRegion];  }
        }
        });
       chart.draw(data, options);
     }
     </script>

     <div id='visualization'></div>>
  </body>

</html>

更新

我根据答案改为代码。现在我没有得到我预期的结果。这是现在的代码。

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
    <style xmlns="http://www.w3.org/2000/svg">
        path { fill: #ffc801; }
        :hover { fill: #fcafff; }
      </style>

    <script type='text/javascript' src='http://www.google.com/jsapi'></script>
    <script type='text/javascript'>google.load('visualization', '1', {'packages': ['geochart']});

      google.setOnLoadCallback(drawVisualization);

        function drawVisualization() {var data = new google.visualization.DataTable();

       data.addColumn('string', 'Country');
       data.addColumn('number', 'Value'); 
       data.addColumn({type:'string', role:'tooltip'});var ivalue = new Array();

       var options = {
       backgroundColor: { fill: '#FFF', stroke: '#000', strokeWidth: 75 },
       colorAxis:  {minValue: 0, maxValue: 0,  colors: []},
       legend: 'none',
       datalessRegionColor: '#ffc801',
       displayMode: 'regions', 
       enableRegionInteractivity: 'true', 
       resolution: 'provinces',
       sizeAxis: {minValue: 1, maxValue:1,minSize:10,  maxSize: 10},
       region:'IN',
       keepAspectRatio: true,
       width:600,
       height:400,
       tooltip: {textStyle: {color: '#444444'}, trigger:'focus', isHtml: false}   
       };
        var chart = new google.visualization.GeoChart(document.getElementById('visualization')); 
        google.visualization.events.addListener(chart, 'select', function() {
        var selection = chart.getSelection();
        if (selection.length == 1) {
        var selectedRow = selection[0].row;
        var selectedRegion = data.getValue(selectedRow, 0);
        if(ivalue[selectedRegion] != '') { document.location = ivalue[selectedRegion];  }
        }
        });
       chart.draw(data, options);
     }
     </script>

     <div id='visualization'></div>
  </body>

</html>

当我运行上面的代码时,我会在地图周围出现一个黑暗区域,而不是更粗的边框。可以做些什么?

更新

如果我使用iframe,则缩放不会裁剪地图区域,并且悬停未按预期工作。

path {
  stroke: #555;
}
#wrapper2 { width: 450px; height: 450px; padding: 0; overflow: hidden; }

#scaled-frame { width: 400px; height: 400px; border: 0px; }

#scaled-frame {

zoom: 0.61;
overflow: hidden;
-moz-transform: scale(0.61);

-moz-transform-origin: 0 0;

-o-transform: scale(0.61);

-o-transform-origin: 0 0;

-webkit-transform: scale(0.61);

-webkit-transform-origin: 0 0;

}



@media screen and (-webkit-min-device-pixel-ratio:0) {

#scaled-frame  { zoom: 1;  }

}



<div id="wrapper2">
    <iframe id="scaled-frame" src="/_/mapframe.html" height="300" width="500" ></iframe>
</div>

enter image description here

3 个答案:

答案 0 :(得分:5)

在元素stroke上使用<path> CSS属性来获得更粗的边框, 这是SVG HTML5功能。

.css文件中添加以下内容:

path {
  stroke: #555;
}

要仅显示印度,您需要将scale属性设置为最适合您的HTML5 canavas的属性。查看您使用的框架API,并找出如何管理规模。

答案 1 :(得分:1)

根据文档(https://developers.google.com/chart/interactive/docs/gallery/geochart#coloring),您应该可以设置

backgroundColor: { fill: '#FFF', stroke: '#000', strokeWidth: 30 }

这会将地图区域设置为白色填充,边框宽度为30px的黑色边框。您应该使用strokeWidth值来使其达到您想要的大小。此外,看起来你已经定义了两次。删除其中一个backgroundColor定义。

答案 2 :(得分:1)

您是否尝试过更改

中的值
<style xmlns="http://www.w3.org/2000/svg">
    path { fill: #ffc801; }
    :hover { fill: #fcafff; }
  </style>

尝试在两个路径中添加笔划规则,并且:像这样悬停

path { fill: #ffac; stroke:#fff; }
:hover { fill: #fcafff; stroke:#000;}

此解决方案将使所选区域在未悬停时显示黑色笔划和白色笔划。但是,对于地图上的某些区域,它不能正常工作,您必须将一条边缘悬停以获得黑色笔划。但我相信这给了我们正确解决方案的暗示吗?

相关问题