Now In this post I am going to describe that how can we enable selection in thematic map and get selected location value in managed bean so here in this post I am extending that previous application
Hello all,
this post is about simple use of dvt:thematicMap component , this map is used for displaying some information of a particular geographic location such as population ,any trends or patterns
Map is called thematic because it doesn't include geographic details of location as rivers, ocean etc.
If you want to use geographic features then use <dvt:map>
Thematic map includes different basemap as world map and all continents map
for details see oracle docs - <dvt:thematicmap>
In this post i am just spotting locations using their latitude and longitude co-ordinates
So first step is create a fusion web application and drop a thematic map (world map) on page
then i have created a bean class to populate data in thematic map , this bean class contains properties (varaibles) for thematic map like Country Name,latitude and longitude
publicclassLocationDetail{private String location;// Name of Locationprivate String countryNm;// Name of Countryprivate String textDisp;// Additional Information to displayprivatefloat lattitude;// Latitude of locationprivatefloat longitude;// Longitude of LocationpublicLocationDetail(){super();}publicvoidsetLocation(String location){this.location= location;}public String getLocation(){return location;}publicvoidsetCountryNm(String countryNm){this.countryNm= countryNm;}public String getCountryNm(){return countryNm;}publicvoidsetTextDisp(String textDisp){this.textDisp= textDisp;}public String getTextDisp(){return textDisp;}publicvoidsetLattitude(float lattitude){this.lattitude= lattitude;}publicfloatgetLattitude(){return lattitude;}publicvoidsetLongitude(float longitude){this.longitude= longitude;}publicfloatgetLongitude(){return longitude;}}
created a managed bean and a List data structure to add location detail and added this List reference to thematic map component
then i have added a form on page to add new location by user, this form has 5 fields (Country Name, Location, Latitude, Longitude and Description) and a button to add this information to list
<af:panelBoxtext="Add New Location"id="pb1"showDisclosure="false"><f:facetname="toolbar"/><af:panelFormLayoutid="pfl1"rows="1"maxColumns="2"><f:facetname="footer"><af:buttontext="Add Location"id="b1"actionListener="#{viewScope.MapBean.addLocationButton}"/></f:facet><af:inputTextlabel="Country"id="it3"contentStyle="width:100px;font-weight:bold;color:navy;"binding="#{viewScope.MapBean.cntryNmBind}"/><af:inputTextlabel="Location"id="it4"contentStyle="width:100px;font-weight:bold;color:navy;"binding="#{viewScope.MapBean.locationBind}"/><af:inputTextlabel="Latitude"id="it1"contentStyle="width:100px;color:red;"binding="#{viewScope.MapBean.latitudeBind}"/><af:inputTextlabel="Longitude"id="it2"contentStyle="width:100px;color:red;"binding="#{viewScope.MapBean.longitudeBind}"/><af:inputTextlabel="Description"id="it5"contentStyle='width:200px;color:darkgreen;'binding="#{viewScope.MapBean.descriptionBind}"/></af:panelFormLayout></af:panelBox>
now see the managed bean code to add this information to list and to populate default locations
publicclassMapBean{//List to contain Location Detailprivate List<LocationDetail> mapDetail =new ArrayList<LocationDetail>();// Bindings of page component to access valueprivate RichInputText cntryNmBind;private RichInputText latitudeBind;private RichInputText longitudeBind;private RichInputText locationBind;private RichInputText descriptionBind;publicMapBean(){// Add Default location to map
LocationDetail location =new LocationDetail();
location.setCountryNm("India");
location.setLocation("Mumbai");
location.setTextDisp("Economic Capital of India");
location.setLongitude((float)72.8258);
location.setLattitude((float)18.9750);
mapDetail.add(location);
location =new LocationDetail();
location.setCountryNm("India");
location.setLocation("Kanpur");
location.setTextDisp("Industrial City in North India");
location.setLongitude((float)80.20);
location.setLattitude((float)26.28);
mapDetail.add(location);
System.out.println("List is-"+ mapDetail);}publicvoidsetMapDetail(List mapDetail){this.mapDetail= mapDetail;}public List getMapDetail(){return mapDetail;}/**Method to add new Location * @param actionEvent */publicvoidaddLocationButton(ActionEvent actionEvent){if(cntryNmBind.getValue()!=null&& latitudeBind.getValue()!=null&& longitudeBind.getValue()!=null&&
locationBind.getValue()!=null&& descriptionBind.getValue()!=null){
LocationDetail location =new LocationDetail();
location =new LocationDetail();
location.setCountryNm(cntryNmBind.getValue().toString());
location.setLocation(locationBind.getValue().toString());
location.setTextDisp(descriptionBind.getValue().toString());
location.setLongitude(Float.parseFloat((String) longitudeBind.getValue()));
location.setLattitude(Float.parseFloat((String) latitudeBind.getValue()));
mapDetail.add(location);}}publicvoidsetCntryNmBind(RichInputText cntryNmBind){this.cntryNmBind= cntryNmBind;}public RichInputText getCntryNmBind(){return cntryNmBind;}publicvoidsetLatitudeBind(RichInputText latitudeBind){this.latitudeBind= latitudeBind;}public RichInputText getLatitudeBind(){return latitudeBind;}publicvoidsetLongitudeBind(RichInputText longitudeBind){this.longitudeBind= longitudeBind;}public RichInputText getLongitudeBind(){return longitudeBind;}publicvoidsetLocationBind(RichInputText locationBind){this.locationBind= locationBind;}public RichInputText getLocationBind(){return locationBind;}publicvoidsetDescriptionBind(RichInputText descriptionBind){this.descriptionBind= descriptionBind;}public RichInputText getDescriptionBind(){return descriptionBind;}
you can see in thematicMap map source - how bean variables are used to point latitude, longitude etc
Run this application, you will see default location are marked at first time
now add any other location using 'Add New Location' form
See this video how locations are added to thematic map using their latitude and longitude
and finally after adding all location , map looks like this