[英]Google Map API - Custom Prototype marker Image not showing from today
请查看下面的代码,直到今天早上(2014年8月26日),它都能正常工作。 之后该图像不可见。 所有功能都运行良好。
function vehicleMarker(_description,_lat,_lng) {
this._contentHTML = _description;
this._markeroption = { position: new google.maps.LatLng(_lat, _lng),
map: ObjViewmap.map,
draggable: false
};
this.setOptions(this._markeroption);
this.updateLoc=function(_lat,_lng){
this.setPosition(new google.maps.LatLng(_lat, _lng));
};
google.maps.event.addListener(this, 'click', function (evt) {
//click code here
});
this.disposeMarker=function(){
google.maps.event.clearInstanceListeners(this);
this.setMap(null);
};
this.SetVehicleImage = function (vtype) {
var imageurl = 'images/vehicle/' + vtype.toLowerCase() + '.png';
var image_a = new google.maps.MarkerImage(imageurl, new google.maps.Size(32, 32),
new google.maps.Point(0, 0), new google.maps.Point(0, 32));
this.setIcon(image_a);
this.getIcon().anchor.x = 16;
this.getIcon().anchor.y = 16;
};
}
vehicleMarker.prototype = new google.maps.Marker();
//----------------------------------------------------------------------------
var v=new vehicleMarker('testdesc',11.555334,76.333223);
v.SetVehicleImage('car');
如果我删除v.SetVehicleImage('car'); ,仍未显示google默认标记。
如果我删除原型,代码将起作用。 这是一个有效的代码,请检查。
JSFiddle中的示例代码http://jsfiddle.net/prajithmp/90v8vqn6/1
刚刚推出了新版本的API。 您要求的版本是3.9,而最近的版本是3.16。 使用MarkerWithLabel的“继承”可以:
/**
* @param {Function} childCtor Child class.
* @param {Function} parentCtor Parent class.
* @private
*/
function inherits(childCtor, parentCtor) {
/* @constructor */
function tempCtor() {}
tempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor();
/* @override */
childCtor.prototype.constructor = childCtor;
}
function MarkerX() {
// Call the parent constructor. It calls Marker.setValues to initialize, so all
// the new parameters are conveniently saved and can be accessed with get/set.
// Marker.set triggers a property changed event (called "propertyname_changed")
// that the marker label listens for in order to react to state changes.
google.maps.Marker.apply(this, arguments); // this.setOptions(markeroption);
var _image = {
url: "http://login.avlview.com/images/RouteFenceA.png",
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34)
};
this.setIcon(_image);
}
inherits(MarkerX,google.maps.Marker);
var marker = new MarkerX();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.