首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fitBounds中的PrimeFaces gmap组件

fitBounds中的PrimeFaces gmap组件
EN

Stack Overflow用户
提问于 2014-04-14 13:01:57
回答 2查看 1.8K关注 0票数 3

是否有方法在由fitBounds gmap组件创建的谷歌地图对象中调用PrimeFaces方法?我尝试了下面的代码,但是得到了javascript错误:TypeError: primefacesMap.fitBounds is not a functionfitBounds似乎被PrimeFaces框架的布尔属性覆盖。

代码语言:javascript
复制
<h:head>
  <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"/>
  <script type="text/javascript">
//<![CDATA[
  function initPrimefacesComponent(){
    var primefacesMap = gmtls.getMap();
    var bounds = new google.maps.LatLngBounds();
    var points = [
      new google.maps.LatLng(41.3, 2),
      new google.maps.LatLng(41.309, 2)
      ];
    // Extend bounds with each point
    for (var i = 0; i < points.length; i++) {
      bounds.extend(points[i]);
      new google.maps.Marker({position: points[i], map: primefacesMap});
    }
    // Apply fitBounds
    primefacesMap.fitBounds(bounds); 
  }
//]]>
  </script>
</h:head>

<h:body onload="initPrimefacesComponent();" >
  <p:gmap center="41.3, 2" zoom="15" type="ROADMAP"   widgetVar="gmtls"
    style="width:600px;height:400px" />  
</h:body>

下面是为没有素数面而创建的google对象工作的代码:

代码语言:javascript
复制
<h:head>
  <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"/>
  <script type="text/javascript">
//<![CDATA[
  function initOriginalMap() {
    var mapOptions = {
      center: new google.maps.LatLng(41.3, 2),
      zoom: 15
    };
    var originalMap = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);
    var bounds = new google.maps.LatLngBounds();
    var points = [
      new google.maps.LatLng(41.3, 2),
      new google.maps.LatLng(41.309, 2)
      ];

    // Extend bounds with each point
    for (var i = 0; i < points.length; i++) {
      bounds.extend(points[i]);
      new google.maps.Marker({position: points[i], map: originalMap});
    }

    // Apply fitBounds
    originalMap.fitBounds(bounds); 
  }
  google.maps.event.addDomListener(window, 'load', initOriginalMap);
//]]>
  </script>
</h:head>

<h:body >
  <div id="map-canvas" style="width:600px;height:400px"/>
</h:body>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-15 10:58:00

要使fitBounds在PrimeFaces中工作,我必须通过原始源再次重写映射的fitBounds属性:

代码语言:javascript
复制
//remember the property set by PrimeFaces
var tmp = map.fitBounds;

//replace the code by the one provided by google maps api
map.fitBounds = google.maps.Map.prototype.fitBounds;

//execute fitBounds function
this.fitBounds(bounds);

//restore PrimeFaces property (probably PrimeFaces use it somehow)
this.fitBounds = tmp;
票数 6
EN

Stack Overflow用户

发布于 2019-09-11 12:28:59

我提交了一份公共关系报告,以便在PF 7.1+中对此进行本地修正。fitBounds方法现在就在小部件本身上了。

https://github.com/primefaces/primefaces/pull/5132

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

https://stackoverflow.com/questions/23060823

复制
相关文章

相似问题

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