When I put this code in a script.js file and include it runs fine,
but when I implement this code in a javascript file loaded by requirejs the createMapOnOverlay function is not found which is called from outside like this:
var overlay = new AlarmOverlay(...);
overlay.createMapOnOverlay(..);
alarmoverlay.js:
AlarmOverlay.prototype = new google.maps.OverlayView();
/* constructor */
function AlarmOverlay(bounds, alarmNumber, alarmCssClass) {
// initialize all properties for an alarm
this.bounds = bounds;
this.alarmNumber = alarmNumber;
this.alarmCssClass = alarmCssClass;
}
AlarmOverlay.prototype.createMapOnOverlay = function(map) {
// Explicitly call setMap on this overlay
this.map = map;
this.setMap(map);
};
AlarmOverlay.prototype.onAdd = function () {
};
AlarmOverlay.prototype.draw = function () {
};
I have to put the above code in this below script.js file which is loaded by requirejs: but the below code does not work
define(function() {
return function AlarmOverlay(bounds, alarmNumber, alarmCssClass) {
var self = this;
self.prototype = new google.maps.OverlayView();
self.bounds = bounds;
self.alarmNumber = alarmNumber;
self.alarmCssClass = alarmCssClass;
//AlarmOverlay.prototype.createMapOnOverlay = function(map) {
self.map = map;
self.setMap(map);
//};
AlarmOverlay.prototype.onAdd = function() {
};
AlarmOverlay.prototype.draw = function() {
};
};
});
How do I have to derive from the google OverlayView that I can call the createMapOnOverlay function from outside which should call the setMap from the base class?
When I put this code in a script.js file and include it runs fine,
but when I implement this code in a javascript file loaded by requirejs the createMapOnOverlay function is not found which is called from outside like this:
var overlay = new AlarmOverlay(...);
overlay.createMapOnOverlay(..);
alarmoverlay.js:
AlarmOverlay.prototype = new google.maps.OverlayView();
/* constructor */
function AlarmOverlay(bounds, alarmNumber, alarmCssClass) {
// initialize all properties for an alarm
this.bounds = bounds;
this.alarmNumber = alarmNumber;
this.alarmCssClass = alarmCssClass;
}
AlarmOverlay.prototype.createMapOnOverlay = function(map) {
// Explicitly call setMap on this overlay
this.map = map;
this.setMap(map);
};
AlarmOverlay.prototype.onAdd = function () {
};
AlarmOverlay.prototype.draw = function () {
};
I have to put the above code in this below script.js file which is loaded by requirejs: but the below code does not work
define(function() {
return function AlarmOverlay(bounds, alarmNumber, alarmCssClass) {
var self = this;
self.prototype = new google.maps.OverlayView();
self.bounds = bounds;
self.alarmNumber = alarmNumber;
self.alarmCssClass = alarmCssClass;
//AlarmOverlay.prototype.createMapOnOverlay = function(map) {
self.map = map;
self.setMap(map);
//};
AlarmOverlay.prototype.onAdd = function() {
};
AlarmOverlay.prototype.draw = function() {
};
};
});
How do I have to derive from the google OverlayView that I can call the createMapOnOverlay function from outside which should call the setMap from the base class?
Share Improve this question asked May 16, 2013 at 14:27 ElisabethElisabeth 21.3k57 gold badges211 silver badges325 bronze badges1 Answer
Reset to default 6in AlarmOverlay.js:
define(['google'], function(google) {
AlarmOverlay.prototype = new google.maps.OverlayView();
/* constructor */
function AlarmOverlay(bounds, alarmNumber, alarmCssClass) {
// initialize all properties for an alarm
this.bounds = bounds;
this.alarmNumber = alarmNumber;
this.alarmCssClass = alarmCssClass;
}
AlarmOverlay.prototype.createMapOnOverlay = function(map) {
// Explicitly call setMap on this overlay
this.map = map;
this.setMap(map);
};
AlarmOverlay.prototype.onAdd = function () {
};
AlarmOverlay.prototype.draw = function () {
};
return AlarmOverlay;
}
and in main js file:
require(['AlarmOverlay'], function(AlarmOverlay) {
var overlay = new AlarmOverlay(...);
overlay.createMapOnOverlay(..);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745199793a4616268.html
评论列表(0条)