首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌气象库

谷歌气象库
EN

Stack Overflow用户
提问于 2013-02-06 18:40:46
回答 1查看 2K关注 0票数 2

我正在使用谷歌图书馆的时间在地图上显示它。

我的问题是,显示的第一个窗口非常小,您必须滚动。如何控制此窗口的大小?

其次,我只想显示我给出的坐标的地图,并显示我想要的最短时间。我该怎么做?

这是我用here编写的代码

代码语言:javascript
复制
         function generartiempo(36.745,-3.87665,'mapatiempo') {
            var mapOptions = {
          zoom: 11,
          center: new google.maps.LatLng(lat,lng,true),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var infowindow = new google.maps.InfoWindow();
        var map = new google.maps.Map(document.getElementById('mapatiempo'),
            mapOptions);

        var weatherLayer = new google.maps.weather.WeatherLayer({
          temperatureUnits: google.maps.weather.TemperatureUnit.CELSIUS,
          windSpeedUnit: google.maps.weather.WindSpeedUnit.KILOMETERS_PER_HOUR
        });


        weatherLayer.setMap(weatherLayer.getMap() ? null : map);

        var cloudLayer = new google.maps.weather.CloudLayer();
        cloudLayer.setMap(map);

    }
<div id="mapatiempo"></div>
#mapatiempo {
width: 268px;
height: 200px;
border: 1px solid #AAAAA8;
margin-bottom: 5px;
margin-top: 15px;
}

有人能帮上忙吗?编辑示例:http://jsfiddle.net/webyseo/YW2K7/12/解决方案?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-06 23:48:40

没有用于定义默认infoWindow大小的选项。此外,infoWindow的大小受到地图大小的限制,它不能更大,因此您需要放大地图。

您可以做的是:用一个自定义的infoWindow覆盖默认的infoWindow并自己定义内容,这样它就可以放入一个较小的infoWindow中

自定义infoWindow的示例代码:(假设变量包含google.maps.Map)

代码语言:javascript
复制
    //create the weatherLayer
    var weatherLayer = new google.maps.weather.WeatherLayer({
      temperatureUnits: google.maps.weather.TemperatureUnit.FAHRENHEIT,
      clickable:true,
      suppressInfoWindows:true
    });

    //create InfoWondow-instance
    var weatherWindow=new google.maps.InfoWindow();

    //observe click-event
    google.maps.event.addListener(weatherLayer,'click',function(e){

      //hide infoindow
      weatherWindow.close();

      var content  = document.createElement('ul'),
          weather  = e.featureDetails.forecast,
          unit     = '°'+e.featureDetails.temperatureUnit.toUpperCase();

        //merge current weather and forecast
        weather.push(e.featureDetails.current);

        //create some content(here a short summary)
        for(var i = 0; i<weather.length; ++i){
          var item = content.appendChild(document.createElement('li'))
                      .appendChild(document.createTextNode(''))
              w    = weather[i];
              item.data='['+w.shortDay+']'+w.description+
                        '('+w.low+unit+'/'+w.high+unit+')';


        }
        //set content and position of the infoWindow
        weatherWindow.setOptions({position:e.latLng,content:content});
        //...and open the infowindow
         weatherWindow.open(map);
    });
    weatherLayer.setMap(map);

演示:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14727002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档