以下のコードは、演習 11 終了時の MapLocatorHandler.egl ファイルのテキストです。
package handlers;
import com.ibm.egl.rui.widgets.Box;
import com.ibm.egl.rui.widgets.GridLayout;
import com.ibm.egl.rui.widgets.GridLayoutData;
import com.ibm.egl.rui.widgets.GridLayoutLib;
import com.ibm.egl.rui.widgets.HyperLink;
import com.ibm.egl.rui.widgets.TextLabel;
import egl.ui.rui.Event;
import dojo.widgets.DojoButton;
import dojo.widgets.DojoComboBox;
import interfaces.GooglePlacesService;
import services.PlaceSearchResponse;
import utils.dialog.DojoDialogLib;
import utils.map.GoogleMap;
import utils.map.MapMarker;
handler MapLocatorHandler type RUIhandler{initialUI =[ui
], onConstructionFunction = start, cssFile = "css/MortgageUIProject.css", title = "MapLocatorHandler"}
ui GridLayout{columns = 3, rows = 3, cellPadding = 4, children =[localMap,
listingBox, typeButton, typeComboBox, typeLabel, introLabel
]};
introLabel TextLabel{layoutData = new GridLayoutData{row = 1, column = 1, horizontalSpan = 3}, text = "Search for places in San Francisco:"};
typeLabel TextLabel{layoutData = new GridLayoutData{row = 2, column = 1}, text = "Type:"};
typeComboBox DojoComboBox{layoutData = new GridLayoutData{row = 2, column = 2}, value = "mortgage", inputRequired = true, width = "100", onChange ::= checkForEnter, values =[
"bar", "food", "restaurant", "cafe", "movie_theater", "mortgage",
"bank", "atm"]};
typeButton DojoButton{layoutData = new GridLayoutData{row = 2, column = 3}, text = "Search", onClick ::= buttonClicked};
listingBox Box{layoutData = new GridLayoutData{row = 3, column = 1, verticalAlignment = GridLayoutLib.VALIGN_TOP, horizontalSpan = 2}, padding = 8, columns = 1, width = "150"};
localMap GoogleMap{layoutData = new GridLayoutData{row = 3, column = 3}, width = 400, height = 400};
lookupService GooglePlacesService{@restbinding};
function start()
end
function checkForEnter(event Event in)
if(event.ch == 13)
search();
end
end
function buttonClicked(event Event in)
search();
end
function search()
localMap.zoom = 10;
localMap.removeAllMarkers();
// show an initial marker, as necessary to display the map at all
localMap.addMarker(new MapMarker{ latitude = "37.47", longitude = "-122.26", address = "I am here!", description = "San Francisco"});
// Call the remote Google service, passing the type value
call lookupService.getSearchResults( typeComboBox.value ) returning to showResults
onException displayError;
end
function showResults(retResult PlaceSearchResponse in)
linkListing HyperLink[0];
for(i int from 1 to retResult.result.getSize() by 1)
newLink HyperLink{padding = 4, text = retResult.result[i].name, href = "#"};
newLink.setAttribute("title", retResult.result[i].vicinity );
newLink.setAttribute("lat",
retResult.result[i].geometry.location.lat);
newLink.setAttribute("lng",
retResult.result[i].geometry.location.lng);
newLink.onClick ::= mapAddress;
linkListing.appendElement(newLink);
end
listingBox.setChildren(linkListing);
end
function mapAddress(e Event in)
// Show the marker when the user clicks the link
businessAddress string = e.widget.getAttribute("address") as string;
businessName string = e.widget.getAttribute("title") as string;
lat string = e.widget.getAttribute("lat") as string;
lng string = e.widget.getAttribute("lng") as string;
localMap.addMarker( new MapMarker{ latitude = lat,
longitude = lng, address = businessAddress, description = businessName});
end
function displayError(ex AnyException in)
DojoDialogLib.showError("Google Service",
"Cannot invoke Google Places service: " + ex.message, null);
end
end