primefaces - Primefaces GMap地理编码事件未显示标记
问题描述
当用户输入地址并按下按钮时,Primefaces 地理编码事件成功更改并居中地图,但地图不显示关联的标记。如何使该标记可见?
html代码:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=..."></script>
<h:form id="direccionForm">
<p:inputText id="address" />
<p:commandButton value="Localizar" icon="fa fa-search" onclick="geocode()" type="button" />
<p:gmap id="gmap" widgetVar="_gmap" center="#{manejadorComercio.gmapComercio.centerGeoMap}" zoom="15" type="hybrid" style="width:600px;height:400px" model="#{gmapComercio.model}" >
<p:ajax event="geocode" listener="#{manejadorComercio.gmapComercio.onGeocode}" update="@this" />
</p:gmap>
</h:form>
JS代码:
function geocode() {
var address = document.getElementById('direccionForm:address').value;
PF('_gmap').geocode(address);
}
Java代码:
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Scope;
@Name( "manejadorComercio" )
@Scope( ScopeType.CONVERSATION )
public class ManejadorComercio implements Serializable {
private GMapComercioModel gmapComercio;
@Create
public void inicializa() {
gmapComercio = new GMapComercioModel();
}
}
public class GMapComercioModel {
private MapModel model = new DefaultMapModel();
private String centerGeoMap = "40.4530541, -3.6905332";
public GMapComercioModel() {
model.addOverlay(new Marker(new LatLng(40.4530541, -3.6905332), "Bernabeu"));
}
public void onGeocode(GeocodeEvent event) {
List<GeocodeResult> results = event.getResults();
if (results != null && !results.isEmpty()) {
LatLng center = results.get(0).getLatLng();
centerGeoMap = center.getLat() + "," + center.getLng();
for (int i = 0; i < results.size(); i++) {
GeocodeResult result = results.get(i);
model.addOverlay(new Marker(result.getLatLng(), result.getAddress()));
}
}
}
}
提前致谢。
解决方案
愚蠢的错误,p:gmap组件的“模型”属性应该是
model="#{manejadorComercio.gmapComercio.model}
代替
model="#{gmapComercio.model}".
这样就可以了。
推荐阅读
- angular - 通过搜索过滤 ng-for 中的项目并为有结果的项目显示类别
- c# - 如何在 ViewModel 中设置从模型列表中获取和设置值的属性?
- php - PHP的'return'语句是否默认返回布尔值?
- java - 长类型的 Java Bean 验证
- databricks - 在 deltaLake 表上配置 TTL
- audio - 3D 定位音频和 Scenekit
- html - 由于文件格式或扩展名无效,无法在网页中打开下载的文件嵌入文件链接
- javascript - 四舍五入到小数点后 2 位 (Javascript)
- powershell - PowerShell - 如何删除字符串中重复的反斜杠
- cas - Soft Warehouse/TI 的“Derive”是否有任何 PC CAS 后代?