
@UI.selectionPresentationVariant: [
{ qualifier: 'List',
text: 'List2' }
]
"views": {
"paths": [
{
"key": "tableView",
"annotationPath": "com.sap.vocabularies.UI.v1.SelectionVariant#List"
},
...
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m">
<Button
core:require="{ handler: 'zgeomovingobjectlistcustomtabv43/ext/fragment/GeoMapListView.controller'}"
text="GeoMapListView" press="handler.onPress" />
</core:FragmentDefinition>
sap.ui.define([
"sap/m/MessageToast"
], function(MessageToast) {
'use strict';
return {
onPress: function(oEvent) {
MessageToast.show("Custom handler invoked.");
}
};
});
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:vbm="sap.ui.vbm"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:commons="sap.ui.commons"
xmlns:l="sap.ui.layout"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1">
<vbm:GeoMap
id="GeoMapControllerId"
class="zgeo_movingobject-GeoMap"
width="100%"
height="99%"
initialPosition="9.933573;51.898695;0"
centerPosition="{GeoMapSettings>/centerPosition}"
zoomlevel="{GeoMapSettings>/zoomlevel}"
core:require="{handler: 'zgeomovingobjectlistcustomtabv42/ext/fragment/GeomapListViewHandler'}">
<vbm:vos>
<vbm:Spots id="zdummy5"
click="onClickItem"
posChangeable="true"
scaleChangeable="false"
items="{path: 'GeoMapSpots>/MovingObject'}">
<vbm:items>
<vbm:Spot
id="Spot"
position="{GeoMapSpots>GeoLongitude};{GeoMapSpots>GeoLatitude};0"
tooltip="{GeoMapSpots>ObjectTypeText}: {GeoMapSpots>ObjectId} - Long.:{GeoMapSpots>GeoLongitude}, Lat.:{GeoMapSpots>GeoLatitude}"
type="Success"
icon="shipping-status"
text="{GeoMapSpots>ObjectTypeText}: {GeoMapSpots>ObjectId}"
contentOffset="0;0"
click="handler.onSpotClick">
</vbm:Spot>
</vbm:items>
</vbm:Spots>
</vbm:vos>
</vbm:GeoMap>
</core:FragmentDefinition>
sap.ui.define([],
function() {
"use strict";
return {
onSpotClick: function(oControlEvent){
//Get Moving Object Id
var oGeoMapViewSpotEvent = oControlEvent.getSource();
var oGeoMapSpotBindingContext = oGeoMapViewSpotEvent.getBindingContext('GeoMapSpots');
var MovingObjectId = oGeoMapSpotBindingContext.getProperty('ObjectId');
//Navigate to Object Page
var oExtensionAPI = this;
var oRouting = oExtensionAPI.getRouting();
oRouting.navigateToRoute(
'MovingObjectObjectPage',
{ key : MovingObjectId });
}
}; //Event Handler Object
}); //End function
sap.ui.define(['sap/ui/core/mvc/ControllerExtension'], function (ControllerExtension) {
'use strict';
return ControllerExtension.extend('zgeomovingobjectlistcustomtabv43.ext.controller.MovingObjectListCtlrExt', {
// this section allows to extend lifecycle hooks or hooks provided by Fiori elements
override: {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf zgeomovingobjectlistcustomtabv43.ext.controller.MovingObjectListCtlrExt
*/
onInit: function () {
// you can access the Fiori elements extensionAPI via this.base.getExtensionAPI
var oModel = this.base.getExtensionAPI().getModel();
}
}
});
});
sap.ui.define(['sap/ui/core/mvc/ControllerExtension'], function (ControllerExtension) {
'use strict';
return ControllerExtension.extend('zgeomovingobjectlistcustomtabv42.ext.controller.MovingObjectListCtlrExt', {
override: {
onInit : function(){
},
onBeforeRendering: function() {
},
onAfterRendering: function() {
this.zz_ExtensionAPI = this.base.getExtensionAPI();
this.zz_GeomapViewTab = this.zz_ExtensionAPI.byId("fe::CustomTab::GeoMapViewKey");
this.zz_GeomapController = this.zz_ExtensionAPI.byId("fe::CustomTab::GeoMapViewKey--GeoMapControllerId");
//This is a work around for keeping a reference to this Controller Extension
Window.zzMovingObjectListCtlExt = this;
this.zz_refreshGeoMap.bind(this);
this.zz_setMapConfiguration();
this.zz_setInitialGeoMapPosition();
},
onViewNeedsRefresh: function(mParameters) {
//Not mParameters.filterConditions will be used, but extensionAPI.createFiltersFromFilterConditions(mFilterConditions).
//When the parameter mFilterConditions is not filled, it will retrieve the filter from the Smart Filter bar.
//Because that one contains the filters in a format which can be used in a model.
this.zz_refreshGeoMap();
//TODO: Undo make Geo Map Grey
},
onPendingFilters: function(mParameters) {
//TODO: Make Geo Map Grey
}
},
zz_setMapConfiguration: function(){
//Set Map configuration
var oMapConfig = {
"MapProvider": [{
"name": "OSM",
"type": "",
"description": "",
"tileX": "256",
"tileY": "256",
"maxLOD": "20",
"copyright": "OpenStreetMap",
"Source": [{
"id": "s1",
"url": "https://a.tile.openstreetmap.org/{LOD}/{X}/{Y}.png"
}]
}],
"MapLayerStacks": [{
"name": "DEFAULT",
"MapLayer": [{
"name": "OSMLayter",
"refMapProvider": "OSM",
"opacity": "1.0",
"colBkgnd": "RGB(255,255,255)"
}]
}]
};
this.zz_GeomapController.setMapConfiguration(oMapConfig);
this.zz_GeomapController.setRefMapLayerStack("DEFAULT");
},
zz_setInitialGeoMapPosition: function(oEvent){
var oGeoMapSettingsData = {
centerPosition: "0;0",
zoomlevel : 1
}
var oGeoMapSettingsModel = new sap.ui.model.json.JSONModel(oGeoMapSettingsData);
this.zz_GeomapController.setModel(null, 'GeoMapSettings');
this.zz_GeomapController.setModel(oGeoMapSettingsModel, 'GeoMapSettings');
},
zz_refreshGeoMap: async function(){
//Read data
var oMovingObjectsData = await this.zz_readModelData();
//Set Geo Map Spots model
var oNewModel = new sap.ui.model.json.JSONModel(oMovingObjectsData);
this.zz_GeomapController.setModel(null, 'GeoMapSpots');
this.zz_GeomapController.setModel(oNewModel, 'GeoMapSpots');
//Set Map Position
var oGeoMapSettingsData = this.zz_getGeoMapSettingsData(oMovingObjectsData);
var oGeoMapSettingsModel = new sap.ui.model.json.JSONModel(oGeoMapSettingsData);
this.zz_GeomapController.setModel(null, 'GeoMapSettings');
this.zz_GeomapController.setModel(oGeoMapSettingsModel, 'GeoMapSettings');
},
zz_readModelData : async function(){
//See url: https://www.sapui5tutors.com/2023/06/filtering-sapui5-odata-v4-expanded.html?m=1
//Get to filter array via Extension API
var oControllerExtension = this;
var oExtensionApi = oControllerExtension.base.getExtensionAPI();
var oFilters = oExtensionApi.createFiltersFromFilterConditions();
var aFilters = oFilters.filters;
//Create model
var oCurrentGeoMapModel = new sap.ui.model.odata.v4.ODataModel({
groupId : "$direct",
serviceUrl: "/sap/opu/odata4/sap/zgeo_movingobject_sb_v4/srvd/sap/zgeo_movingobject_sd/0001/",
synchronizationMode: "None",
operationMode : sap.ui.model.odata.OperationMode.Server
});
var movingObjectBinding = oCurrentGeoMapModel.bindList("/MovingObject");
movingObjectBinding.filter(aFilters, false);
//Read data
var aMovingObjectsContextArray = await movingObjectBinding.requestContexts();
//Convert data
var Result = { "MovingObject": []};
aMovingObjectsContextArray.map(
function(MovingObjectContext){
var MovingObjectData = MovingObjectContext.getObject();
Result.MovingObject.push(MovingObjectData);
}
);
return Result;
},
zz_getGeoMapSettingsData : function(oMovingObjectsData){
if(oMovingObjectsData.MovingObject.length == 0){
return {
centerPosition: "0;0",
zoomlevel : 1 };
}
//Determine shortest side
var iWidthPx = this.zz_GeomapController.$().width();
var iHeightPx = this.zz_GeomapController.$().height();
//Longitude
var oLongitudeRange = this.zz_getLongitudeRange(oMovingObjectsData);
var iDistance = Math.abs(oLongitudeRange.Left - oLongitudeRange.Right);
var iLongitudeZoomLevel = this.zz_calculateZoomLevel(iDistance, iWidthPx, 1);
var iCenterLongitude = (oLongitudeRange.Left + oLongitudeRange.Right ) /2;
//Latitude
var oLatitudeRange = this.zz_getLatitudeRange(oMovingObjectsData);
var iDistance = Math.abs(oLatitudeRange.Left - oLatitudeRange.Right);
var iLatitudeZoomLevel = this.zz_calculateZoomLevel(iDistance, iHeightPx, 0.8);
var iCenterLatitude = (oLatitudeRange.Left + oLatitudeRange.Right ) /2;
//Determine Zoom Level
if(iLongitudeZoomLevel < iLatitudeZoomLevel){
var iZoomlevel = iLongitudeZoomLevel;
}else{
var iZoomlevel = iLatitudeZoomLevel;
}
//Set Geo Map Settings
var oGeoMap = {
centerPosition: `${iCenterLongitude};${iCenterLatitude}`,
zoomlevel : iZoomlevel }
oGeoMap.ItemCountText = "Test";
return oGeoMap;
},
zz_getLongitudeRange : function(oMovingObjectsData){
var oLongitudeRange = {
Left : 0,
Right : 0
}
for (let i = 0; i < oMovingObjectsData.MovingObject.length; i++) {
var MovingObject = oMovingObjectsData.MovingObject[i];
if(i === 0){
oLongitudeRange.Left = Number(MovingObject.GeoLongitude);
oLongitudeRange.Right = Number(MovingObject.GeoLongitude);
}else{
if(Number(MovingObject.GeoLongitude) < oLongitudeRange.Left ){ oLongitudeRange.Left = Number(MovingObject.GeoLongitude) };
if(Number(MovingObject.GeoLongitude) > oLongitudeRange.Right){ oLongitudeRange.Right = Number(MovingObject.GeoLongitude) };
}
}
return oLongitudeRange;
},
zz_getLatitudeRange : function(oMovingObjectsData){
var oLatitudeRange = {
Left : 0,
Right : 0
}
for (let i = 0; i < oMovingObjectsData.MovingObject.length; i++) {
var MovingObject = oMovingObjectsData.MovingObject[i];
if(i === 0){
oLatitudeRange.Left = Number(MovingObject.GeoLatitude);
oLatitudeRange.Right = Number(MovingObject.GeoLatitude);
}else{
if(Number(MovingObject.GeoLatitude) < oLatitudeRange.Left ){
oLatitudeRange.Left = Number(MovingObject.GeoLatitude) };
if(Number(MovingObject.GeoLatitude) > oLatitudeRange.Right){
oLatitudeRange.Right = Number(MovingObject.GeoLatitude) };
}
}
return oLatitudeRange;
},
zz_calculateZoomLevel : function(iDistance, iLengthPx, iCorrectionFactor){
//When wanting to zoom out more, then iCorrectionFactor < 1.
var LongitudeZoomLevel = 0;
var iFactor = ( iLengthPx / 500 ) * iCorrectionFactor;
if(iDistance <= 0.001 * iFactor ){ LongitudeZoomLevel = 19 } else
if(iDistance <= 0.002 * iFactor ){ LongitudeZoomLevel = 18 } else
if(iDistance <= 0.004 * iFactor ){ LongitudeZoomLevel = 17 } else
if(iDistance <= 0.008 * iFactor ){ LongitudeZoomLevel = 16 } else
if(iDistance <= 0.015 * iFactor ){ LongitudeZoomLevel = 15 } else
if(iDistance <= 0.03 * iFactor ){ LongitudeZoomLevel = 14 } else
if(iDistance <= 0.06 * iFactor ){ LongitudeZoomLevel = 13 } else
if(iDistance <= 0.12 * iFactor ){ LongitudeZoomLevel = 12 } else
if(iDistance <= 0.25 * iFactor ){ LongitudeZoomLevel = 11 } else
if(iDistance <= 0.5 * iFactor ){ LongitudeZoomLevel = 10 } else
if(iDistance <= 1 * iFactor ){ LongitudeZoomLevel = 9 } else
if(iDistance <= 2 * iFactor ){ LongitudeZoomLevel = 8 } else
if(iDistance <= 4 * iFactor ){ LongitudeZoomLevel = 7 } else
if(iDistance <= 8 * iFactor ){ LongitudeZoomLevel = 6 } else
if(iDistance <= 16 * iFactor ){ LongitudeZoomLevel = 5 } else
if(iDistance <= 30 * iFactor ){ LongitudeZoomLevel = 4 } else
if(iDistance <= 60 * iFactor ){ LongitudeZoomLevel = 3 } else
if(iDistance <= 120 * iFactor ){ LongitudeZoomLevel = 2 } else
{ LongitudeZoomLevel = 1 };
return LongitudeZoomLevel;
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |