場所を検索すると地図が更新されますが、センタリング値は更新されません。
/* 以下に xhtml を示します */
<h:outputLabel value="Search Location :" for="acSimple" />
<p:autoComplete id="acSimple" minQueryLength="0" value="#{sampleMapProducer.searchString}" forceSelection="true" completeMethod="#{sampleMapProducer.complete}">
<p:ajax event="itemSelect" update="gmap_loc" process="#{sampleMapProducer.searchCenter}" />
<p:ajax process="@this" update="gmap_loc" />
</p:autoComplete>
<p:outputPanel id="gmapPanel" autoUpdate="true">
<p:gmap center="#{sampleMapProducer.searchCenter}" zoom="6" type="ROADMAP" style="width:100%;height:600px" model="#{sampleMapProducer.mapBySearch}" id="gmap_loc"></p:gmap>
</p:outputPanel>
マップの Bean コード:
private void clearMap (MapModel map)
{
for (Marker marker : map.getMarkers()) {
marker.setVisible(false);
}
}
/* 検索用の地図を取得 */
public MapModel getMapBySearch ()
{
clearMap(mapBySearch);
for (Marker markerIterator : markersList)
{
if (searchString == null || searchString.trim().equals(""))
{
mapBySearch.addOverlay(markerForLocation(markerIterator,BLUE_DOT));
}
else
{
if (markerIterator.getTitle().toLowerCase().contains(searchString.toLowerCase()))
{
mapBySearch.addOverlay(markerForLocation(markerIterator,BLUE_DOT));
}
}
}
return mapBySearch;
}
/* オートコンプリート文字列 */
public List<String> complete ( String searchString)
{
List<String> suggestedStrings = new ArrayList<String>();
for (String locationName : LOCATION_NAMES)
{
if (locationName.toLowerCase().contains(searchString.toLowerCase())) {
suggestedStrings.add(locationName);
}
}
this.searchString = searchString;
return suggestedStrings;
}
/* ロケーションセンターを取得 */
public String getLocationCenter ()
{
String center = "39,-98";
for (LocationGeocodeBean geoCode : GEO_CODES)
{
if (geoCode.getId().equals(selectedLocationId()))
{
if ((geoCode.getLatitude() != 0) && (geoCode.getLongitude() != 0))
{
center = String.format("%s,%s", geoCode.getLatitude(),geoCode.getLongitude()); }
return center;
}
}
}
return center;
}