-->

Wrap google-closure-library variables for angular

2019-08-30 04:14发布

问题:

So, following on from this question

I now have my module both in bower and npm, I can import it fine to my project and declare it in app.module, even attempt to use it in my controller:

index.html:

<script src="bower_components/google-closure-library/closure/goog/base.js"></script>

app.module.js:

angular
        .module('drugQualityDataManagerApp', [
            'ngStorage',
            'ngResource',
            'ngCookies',
            'ngAria',
            'web-gl-earth2',

uploadData.controller.js:

$scope.initializeMapWebGL = function(){
                var earth = new webGlEarth.map('earth_div');
                webGlEarth.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(earth);

                var marker = webGlEarth.marker([51.5, -0.09]).addTo(earth);
                marker.bindPopup("<b>Hello world!</b><br>I am a popup.<br /><span style='font-size:10px;color:#999'>Tip: Another popup is hidden in Cairo..</span>", {maxWidth: 150, closeButton: true}).openPopup();

                var marker2 = webGlEarth.marker([30.058056, 31.228889]).addTo(earth);
                marker2.bindPopup("<b>Cairo</b><br>Yay, you found me!", {maxWidth: 120, closeButton: false});

                var markerCustom = webGlEarth.marker([50, -9], '/img/logo-webglearth-white-100.png', 100, 24).addTo(earth);

                earth.setView([51.505, 0], 6);
            };

uploadData.html:

<style>
    html, body{padding: 0; margin: 0; background-color: black;}
    #earth_div{top: 0; right: 0; bottom: 0; left: 0; position: absolute !important;}
</style>
<title>WebGL Earth API: Markers</title>
<body onload="initialize()">
<div id="earth_div"></div>
</body>

But, of course, that wasn't going to be quite that straight forward, the issue comes from the webglearth2's dependencies, this app relies strongly on google-closure-library, and angular doesn't like that, I've tried wrapping the main.js file like:

(function () {
    'use strict';
    angular.module('web-gl-earth2', []).provider('webGlEarth');

I added google-closure-library to my bower_components and to app.module.js, but I still get the dreaded:

Uncaught ReferenceError: goog is not defined

So, I'm left with the question: Is there an automagic wrapper out there that will help me integrate this module in angular, or am I doomed to re-write the whole source code to make it "angular likeable"?