是否有方法在由fitBounds gmap组件创建的谷歌地图对象中调用PrimeFaces方法?我尝试了下面的代码,但是得到了javascript错误:TypeError: primefacesMap.fitBounds is not a function。fitBounds似乎被PrimeFaces框架的布尔属性覆盖。
<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对象工作的代码:
<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>发布于 2014-04-15 10:58:00
要使fitBounds在PrimeFaces中工作,我必须通过原始源再次重写映射的fitBounds属性:
//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;发布于 2019-09-11 12:28:59
我提交了一份公共关系报告,以便在PF 7.1+中对此进行本地修正。fitBounds方法现在就在小部件本身上了。
https://stackoverflow.com/questions/23060823
复制相似问题