2014-02-21 61 views
0

我將使用primeface gmap創建地圖。 我有我的JSF頁面的代碼,如圖PM出現在網站:PrimeFaces地圖中的標記

<h:head> 
    <title>Facelet Title</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
     type="text/javascript"></script> 
</h:head> 
<h:body> 
    <h:body> 
<f:view contentType="text/html"> 
    <h1>Google Map</h1> 
    <p:gmap center="36.890257,30.707417" zoom="13" type="HYBRID" model="#{mapBean.simpleModel}" style="width:600px;height:400px"> 
    </p:gmap>  
</f:view> 

而且我mapBean是:

package mesbeans; 

import java.io.Serializable; 
import org.primefaces.model.map.DefaultMapModel; 
import org.primefaces.model.map.LatLng; 
import org.primefaces.model.map.MapModel; 
import org.primefaces.model.map.Marker; 

public class MapBean implements Serializable { 

    private MapModel simpleModel; 

    public MapBean() { 
     simpleModel = new DefaultMapModel(); 

     //Shared coordinates 
     LatLng coord1 = new LatLng(36.879466, 30.667648); 
     LatLng coord2 = new LatLng(36.883707, 30.689216); 
     LatLng coord3 = new LatLng(36.879703, 30.706707); 
     LatLng coord4 = new LatLng(36.885233, 30.702323); 

     //Basic marker 
     simpleModel.addOverlay(new Marker(coord1, "Konyaalti")); 
     simpleModel.addOverlay(new Marker(coord2, "Ataturk Parki")); 
     simpleModel.addOverlay(new Marker(coord3, "Karaalioglu Parki")); 
     simpleModel.addOverlay(new Marker(coord4, "Kaleici")); 
    } 

    public MapModel getSimpleModel() { 
     return simpleModel; 
    } 
} 

當我運行應用程序,只有地圖顯示沒有標記?

回答

0

您的MapBean無法在jsf頁面中識別。爲了識別它,請使用@Named。所以你的bean應該如下。

import org.primefaces.model.map.DefaultMapModel; 
import org.primefaces.model.map.LatLng; 
import org.primefaces.model.map.MapModel; 
import org.primefaces.model.map.Marker; 

import javax.inject.Named 

@Named 
public class MapBean implements Serializable { 
    private MapModel simpleModel;  
    ...... 
0

您需要創建RINIT方法和其分配的座標,因爲執行該法第一和加載所有數據在JSF