开发者

encapsulate gmap's InfoWindow into a function isn't going to work

开发者 https://www.devze.com 2023-03-10 21:58 出处:网络
if i create gmap\'s marker and infowindow in the same function without calling other function. i works well.
  1. if i create gmap's marker and infowindow in the same function without calling other function. i works well.

  2. BUT now, if i want to encapsulate some operations in a function createMarkerInfoWin(), how can i do...

i tried like this:

1) call function onLoad() when page loading.

function onLoad(){
    loadmap();
    var marker =   createMarkerInfoWin(); //i want to encapsulate some operations in it
    marker.setMap(map);  
    ...

}

2)

function createMarkerInfoWin(){
    var marker = new marker();
    var info = new infoWindow();
    var html = "<div>....</div>";  //infowindow's content

    Event.addlistener(marker,'click', function(){
       info.open(html,marker);
    });
    return marker;
}

it isn't going to work. marker is showed on the map, but infowindow not when click the marker.

So i guess: the object info's mem is going to be recycled when f开发者_运维百科unction return.

hi, everybody, is there a better way to encapsulate the create operation in a function? i just don't want to put all the code in the function onLoad().

tks...

0

精彩评论

暂无评论...
验证码 换一张
取 消