[英]How can I receive a value of property from constructor object in sap ui5 js view
I coded an object constructor in util.Common.js file which enable me to receive this object from everywhere. 我在util.Common.js文件中编码了一个对象构造函数,使我可以从任何地方接收此对象。 Here my object constructor taken from javascript google maps examples
这里我的对象构造函数取自javascript google maps示例
jQuery.sap.declare("util.Common");
util.Common = {
/** @constructor */
MercatorProjection : function() {
this.TILE_SIZE = 256;
this.pixelOrigin_ = new google.maps.Point(this.TILE_SIZE / 2,
this.TILE_SIZE / 2);
this.pixelsPerLonDegree_ = this.TILE_SIZE / 360;
this.pixelsPerLonRadian_ = this.TILE_SIZE / (2 * Math.PI);
Map.prototype.googlemap = null;
this.createMap = function(mapOptions){
Map.prototype.mapOptions = mapOptions;
Map.prototype.googlemap = new google.maps.Map(Map.prototype.map_canvas_div.getDomRef(),
Map.prototype.mapOptions);
};
this.createInfoWindowContent = function(map) {
var numTiles = 1 << map.getZoom();
var projection = new MercatorProjection();
var worldCoordinate = projection.fromLatLngToPoint(chicago);
var pixelCoordinate = new google.maps.Point(
worldCoordinate.x * numTiles,
worldCoordinate.y * numTiles);
var tileCoordinate = new google.maps.Point(
Math.floor(pixelCoordinate.x / TILE_SIZE),
Math.floor(pixelCoordinate.y / TILE_SIZE));
return [
'Chicago, IL',
'LatLng: ' + chicago.lat() + ' , ' + chicago.lng(),
'World Coordinate: ' + worldCoordinate.x + ' , ' +
worldCoordinate.y,
'Pixel Coordinate: ' + Math.floor(pixelCoordinate.x) + ' , ' +
Math.floor(pixelCoordinate.y),
'Tile Coordinate: ' + tileCoordinate.x + ' , ' +
tileCoordinate.y + ' at Zoom Level: ' + map.getZoom()
].join('<br>');
};
...
},
...
};
and I'm trying to reach one of properties of object from home.js like that : 并且我试图像这样从home.js到达对象的属性之一:
var me = new util.Common.MercatorProjection();
var mapOptions = {
zoom: 3,
center: chicago
};
me.createMap(mapOptions);
var coordInfoWindow = new google.maps.InfoWindow();
coordInfoWindow.setContent(me.createInfoWindowContent(me.googlemap));
coordInfoWindow.setPosition(me.chicago);
coordInfoWindow.open(me.googlemap);
var listener1 = new google.maps.event.addListener(me.googlemap, 'zoom_changed', function() {
coordInfoWindow.setContent(icm.Google.Charts.values.chart.createInfoWindowContent(me.googlemap));
coordInfoWindow.open(me.googlemap);
But when I write 但是当我写
me.googlemap
me.googlemap
it says googlemap is undefined and it couldn't create info window but I created it in createMap function so it shouldn't be undefined I think I just reached this value wrongly so I don't know how I can reach this value. 它说googlemap是未定义的,它不能创建信息窗口,但是我在createMap函数中创建了它,所以它不应该是未定义的,我认为我刚刚错误地达到了该值,所以我不知道如何达到该值。 Any suggestion would be very nice thanks in advance.
任何建议将是非常好的,谢谢。
If you look at your code, you're defining googlemap
as a property of Map
: 如果您查看代码,则将
googlemap
定义为Map
的属性:
Map.prototype.googlemap = null;
Yet, your object name is MercatorProjection
: 但是,您的对象名称是
MercatorProjection
:
MercatorProjection : function() {
...
I assume you want googlemaps
to be a property of MercatorProjection
(I'm not even sure what Map
is?) - if you adjust your code accordingly (changing references to Map
to references to MercatorProjection
), your references to me.googlemap
further on will work. 我假设您希望
googlemaps
是MercatorProjection
的属性(我什至不知道Map
是什么?)-如果您相应地调整代码(将Map
的引用更改为MercatorProjection
的引用),则对me.googlemap
的引用将继续工作。
Unrelated to your question, but if you're working with Google Maps and UI5, take a look at openui5-googlemaps . 与您的问题无关,但是如果您使用的是Google Maps和UI5,请查看openui5-googlemaps 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.