onInit: function() { this.oVBI = null; var oController = this; var oModel = new sap.ui.model.json.JSONModel(); var data = $.getJSON("media/Tour.json", function(data){ oModel.setData(data); oController.oData = data; }); this.getView().setModel(oModel); this.oVBI = this.getView().byId(this.createId("VBITour")); var oModelCharts = new sap.ui.model.json.JSONModel(); sap.ui.getCore().setModel(oModel); },
In function onInit
we create a JSONModel
, and initialize the JSONModel
with the data from the Logistic Tour Sample. The model will serve as data container for our Logistic Tour Sample.
<vbm:GeoMap id="VBITour" width="100%" height="100%" centerPosition='8.6948125;49.4042720;0' zoomlevel="6" /> .... <vbm:vos> <vbm:Spots id="spots" items="{/Spots}"> <vbm:items> <vbm:Spot key="{key}" icon="{icon}" position="{position}" tooltip="{tooltip}" ...... image="{image}" scale="{scale}" click= "onClickSpot"> </vbm:Spot> </vbm:items> </vbm:Spots> <vbm:Routes id="routes" items="{/Routes}"> <vbm:items> <vbm:Route key="{key}" position="{poslist}" tooltip= "{tooltip}" color= "{color}" colorBorder="{colorBorder}" ...... start="{start}" end="{end}" hotDeltaColor="RHLSA(0;0;1;1)" /> </vbm:items> </vbm:Routes> </vbm:vos> </vbm:GeoMap>
Next we define a GeoMap
control on the XML-view
with some settings for size and a initial section of the map to show. We define a Spots aggregation
as child of the VOs aggregation. We initialize the attribute items in of the Spots aggregation we via
template binding to an array of spots in the model. The attributes of the template object are bound to
model attributes. Besides bound attributes, the template can also have attributes with static values,
such as contenSize, which will than be equal for all instances in the aggregation. We proceed the same
way for the aggregation of routes.
onClickSpot : function(evt) { var sLabelText = evt.getSource().getLabelText(); if ( sLabelText == "Heidelberg" ){ this.DetailWindowGen(evt, 0 ) } else if ( sLabelText == "Zürich" ){ this.DetailWindowGen(evt, 2 ) } else if ( sLabelText == "Wien" ){ this.DetailWindowGen(evt, 1 ) } else if ( sLabelText == "Paris" ){ this.DetailWindowGen(evt, 3 ) } else { // Berlin Store this.DetailWindowGen(evt, 4 ) } },
With the click event on a Spot we receive the properties of the clicked Spot as parameter. We use this information to open a Detailwindow with a Microchart at the corresponding Spot. The microchart shows the utilization/inventory situation of the site.
There is also a "Plan Route" button at the bottom of the Detailwindow, raising a "Press" event.new sap.ui.layout.HorizontalLayout({ content : { path : "/Chart/Buttons", template : new sap.m.Button({ text : '{text}', press : function() { oController.onPlanRoute( oSpot )} }) } }) ...... onPlanRoute : function( oSpot ) { if ( oSpot.getProperty("labelText") == "Berlin"){ this.PlanBerlinRoute( oSpot ); } }
From the event press
we receive the origin Spot with all its parameters. These are routed
to the onPlanRoute
event handler.
For the Berlin site (which shows shortage of inventory) this call is routed to the function calculateRoute
which
is a wrapper of a Webservice for routeplanning.
calculateRoute : function(oRouteStart, oRouteEnd, sTypeOfTransport, sRoutingMethod, sColor, oModel, oPin ){ ...... // Call Routing Webservice, // receive the results data in a string sRoute ...... oModel.oData.Routes[0].poslist = sRoute; var oRoute = oModel.oData.Routes[0]; oRoute.poslist = sRoute; oRoute.linewidth = "5"; oRoute.color = "RGB(97,166,86)"; oRoute.colorBorder = "RGBA(255,255,255,255)"; oRoute.tooltip = sTooltip; oModel.setData(oData); };
The calculateRoute
function takes a bunch of parameters for the Webservice, most important
the Start- and Endpoint of the route. It returns with routing string sRoute, containing the concatenated waypoints.
The result is is written back to the model, replacing the former unplanned route. Thereafter a re-render is triggered. Also the inventory situation is updated.