开发者

Include remoted Library (API 4.5 Mapy.cz) to Google Chrome Extension

开发者 https://www.devze.com 2023-03-19 06:54 出处:网络
I am confused. I\'am trying to make little chrome extension (popup) and I need connect to remoted API.

I am confused. I'am trying to make little chrome extension (popup) and I need connect to remoted API. This is, what I would use, if it is a standard web page:

<script type="text/javascript" src="http://api4.mapy.cz/loader.js"></script>
<script type="text/javascript">Loader.load();</script>

I experimented with including new element script to head (not works for me). But I couldn't believe, there is no开发者_如何学JAVA easier way...

Please, show me the best way.


EDIT:

Linking the API loader is fine and works. Thanks to @serg. So, my code of popup looks like this:

<script type="text/javascript" src="http://api4.mapy.cz/loader.js"></script>
<script type="text/javascript">
    Loader.load();
    var center = SMap.Coords.fromWGS84(16.61574, 49.20315);
</script>

Object Loader is defined and it is OK. Loader should load the whole API either object SMap. But SMap is undefined. What next?


If you need to make ajax requests to this remote API, you need to list API domain in the permissions in your manifest:

{
  "permissions": [
    "http://api4.mapy.cz/"
  ],
}


Finally I ask developer from Mapy.cz and they gave the solution. Instead of using Loader.load() which cause including additional script and async load - use this way:

Loader.async = true;
Loader.load(null, null, function(){
    alert(123); // it works...
    // custom code calling objects etc. from API
    // ...
});

Final Example of usage

0

精彩评论

暂无评论...
验证码 换一张
取 消