[英]Add google maps to fiori sapui5 app
I want to add google maps to my Fiori app. 我想将Google地图添加到我的Fiori应用程序中。 At this moment, I'm able to add google maps to my UI5 app by adding a
<script>
tag in index.html
and successfully call the map to render. 目前,我可以通过在
index.html
添加<script>
标记将google地图添加到我的UI5应用中,并成功调用该地图进行渲染。 But when it comes to Fiori Launchpad, which launch my app not by index.html
but Component.js
, then it doesn't work. 但是,当涉及到Fiori Launchpad时,它不是通过
index.html
而是通过Component.js
来启动我的应用程序的,则它不起作用。 I've been working around but no hope. 我一直在努力,但没有希望。 Any suggestions?
有什么建议么?
You could try to create a wrapper custom control that is responsible for the renndering of the map. 您可以尝试创建包装器自定义控件,该控件负责映射地图。 Then you can place this control inside your view XML.
然后,您可以将此控件放入视图XML中。
There is also this post: https://blogs.sap.com/2014/07/01/google-maps-library-for-ui5/ 也有此帖子: https : //blogs.sap.com/2014/07/01/google-maps-library-for-ui5/
You can try below code in controller file. 您可以在控制器文件中尝试以下代码。
Instead of script in index file, load script once view is rendered 在呈现视图后加载脚本,而不是索引文件中的脚本
onAfterRendering: function() { var me = this; this.loadGoogleMaps("google map API script", me.setMapData.bind(me)); }, // setMapData is a callback function for setting data such as longitude and lattitude loadGoogleMaps: function(scriptUrl, callbackFn) { var script = document.createElement('script'); script.onload = function() { callbackFn(); } script.src = scriptUrl; document.body.appendChild(script); },
In this way you can use it inside Fiori launchpad. 这样,您可以在Fiori启动板中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.