首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

有没有人帮小弟我看一上这人有关问题

2012-12-30 
有没有人帮我看一下这人问题.本帖最后由 a291410855 于 2012-12-07 15:36:44 编辑function RSLabelMarker(

有没有人帮我看一下这人问题.
本帖最后由 a291410855 于 2012-12-07 15:36:44 编辑


function RSLabelMarker(latlng, text, image, map, click) {

    // Now initialize all properties.
    this.latlng_ = latlng;
    this.text_ = text;
    this.image_ = image;
    this.map_ = map;
    this.click_ = click;

    // We define a property to hold the image's
    // div. We'll actually create this div
    // upon receipt of the add() method so we'll
    // leave it null for now.
    this.div_ = null;

    // Explicitly call setMap() on this overlay
    this.setMap(map);
}

RSLabelMarker.prototype = new google.maps.OverlayView();


RSLabelMarker.prototype.onAdd = function () {

    // Note: an overlay's receipt of onAdd() indicates that
    // the map's panes are now available for attaching
    // the overlay to the map via the DOM.

    // Create the DIV and set some basic attributes.
    var div = document.createElement('DIV');


    div.style.position = "absolute";
    // Create an IMG element and attach it to the DIV.
    var img = document.createElement("img");
    img.src = this.image_;
    img.style.width = "100%";
    img.style.height = "100%";
    img.style.marginLeft = "3px";
    img.style.cursor = "pointer";
    img.onclick = this.click_;
    var d = document.createElement("div");
    d.innerHTML = this.text_;
    d.style.backgroundColor = "#F4E09C";
    d.style.color = "red";
    d.style.border = "solid 1px #475EAA";
    d.style.fontSize = "11";
    div.appendChild(img);
    div.appendChild(d);
    // Set the overlay's div_ property to this DIV
    this.div_ = div;

    // We add an overlay to a map via one of the map's panes.
    // We'll add this overlay to the overlayImage pane.
    var panes = this.getPanes();
    panes.overlayLayer.appendChild(div);
}


RSLabelMarker.prototype.draw = function () {

    // Size and position the overlay. We use a southwest and northeast


    // position of the overlay to peg it to the correct position and size.
    // We need to retrieve the projection from this overlay to do this.
    var overlayProjection = this.getProjection();

    // Retrieve the southwest and northeast coordinates of this overlay
    // in latlngs and convert them to pixels coordinates.
    // We'll use these coordinates to resize the DIV.
    var p = overlayProjection.fromLatLngToDivPixel(this.latlng_);

    // Resize the image's DIV to fit the indicated dimensions.
    var div = this.div_;
    var size = new google.maps.Size(-16, -16);
    div.style.left = (p.x + size.width) + 'px';
    div.style.top = (p.y + size.height) + 'px';
    div.style.width = '32px';
    div.style.height = '32px';
}

RSLabelMarker.prototype.onRemove = function () {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
}

// Note that the visibility property must be a string enclosed in quotes
RSLabelMarker.prototype.hide = function () {
    if (this.div_) {
        this.div_.style.visibility = "hidden";
    }
}

RSLabelMarker.prototype.show = function () {
    if (this.div_) {
        this.div_.style.visibility = "visible";
    }
}

RSLabelMarker.prototype.toggle = function () {
    if (this.div_) {
        if (this.div_.style.visibility == "hidden") {
            this.show();
        } else {
            this.hide();
        }
    }
}

RSLabelMarker.prototype.toggleDOM = function () {
    if (this.getMap()) {
        this.setMap(null);
    } else {
        this.setMap(this.map_);
    }
}

//这里如何实现像google.maps.marker.setPosition那样的功能.我现在的处理办法是把点toggleDOM掉然后重新new一个.
RSLabelMarker.prototype.setPosition = function (latlng) {
    //var overlayProjection = this.getProjection();
    //var p = overlayProjection.fromLatLngToDivPixel(latlng);
    //var size = new google.maps.Size(-16, -16);
    //this.div_.style.left = (p.x + size.width) + 'px';
    //this.div_.style.top = (p.y + size.height) + 'px';


}

//这里如何实现像google.maps.marker.setPosition那样的功能.我现在的处理办法是把点toggleDOM掉然后重新new一个.
[解决办法]
"像google.maps.marker.setPosition那样的功能"是要实现什么?去掉然后重新new一个这又是什么情况,不能直接修改这个点的属性?
[解决办法]
你确定你的表述能说清楚你想做什么?

只感觉继承方式不好,特定情况下该会有问题,因为不是用当前对象调用父类构造函数

热点排行