I suggest looking at the tutorials from Mike Williams (<http://
econym.org.uk/gmap/>). Study what he says about the createMarker()
function, including where it's called and where it (the function) is
defined.

Then be sure you understand function closure (See Mike's article at
<http://econym.org.uk/gmap/closure.htm>. That will answer most of your
questions, although this might not be immediately obvious.

Then, a few comments on the code you posted:

1. Don't do that. We can't see the whole context of its execution, so
beyond obvious problems like typos you'll just hear guesswork. This is
especially true with a language like Javascript, which has so much
code built on global ("see everywhere") variables. Instead, post a
link to your map, simplified if necessary to show the problem. OK if
it doesn't work. That's what we want to look at.

2. One of my guesses from the code you posted: the createmarker
function doesn't create any marker. Because it also doesn't initialize
the variable markerme, it's not clear out of context whether the
listeners have a chance of doing anything.

3. I'm not sure it's optimal to attach event listeners to the
*markers* to switch the infowindow from view to edit mode. Much
easier: the view html could have a button that calls a method to close
the infowindow and re-open it in edit mode. Other ways possible, too.
Look at some examples...

On Jun 2, 10:43 pm, wiryono <[email protected]> wrote:
> Hi
> I have a lot of marker in my map
> and each map have almost the same GEvent
>
> this is my simple code in creating a marker ( i use js prototype ) :
>
> function createmarker () {
> GEvent.addListener(markerme, 'click', function() {
>         map.panTo(markerme.getPoint());
>         map.panDirection(0,0);
>         //calling class infowindow
>        map.openInfoWindow( ......)
>
>         GEvent.addListener(markerme,'infowindowopen',function() {
>         if($('editInfo')) {
>                 GEvent.addDomListener($('editInfo'), 'click', function() {
>                  //Calling class edit event
>                GEvent.trigger(markerme,'click');
>                });
>         }
>
>         if($('cancelInfo')) {
>                 GEvent.addDomListener($('cancelInfo'), 'click', function() {
>                 //calling class cancel info
>                 GEvent.trigger(markerme,'click');
>                 });
>           }
>        });});
>
> then i add it to the map
>
> }
>
> so when i click on the marker it will open the infowindow
> on the first window there will be a html input button with id
> "editInfo"
> when i click the button I set the marker data to edit mode than
> trigger marker "click" event again and this time the infowindow will
> show the edit mode
> the html input button "cancelInfo" will be there instead of "editInfo"
> and when you click on it, it will set marker mode to show mode again
> and trigger the "click" event
>
> My Question:
> because i call the click event every time does that mean i create a
> duplicate of below function
> - GEvent.addListener(markerme,'infowindowopen',function()
> - GEvent.addDomListener($('editInfo'), 'click', function() {
> - GEvent.addDomListener($('cancelInfo'), 'click', function() {
> every time (redefine exactly same function)?
>
> if it's duplicate then, is there any method to prevent this
> like checking if the function exist than just pass it without define
> it again
> cause i have a lot of Dom Listerner there
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to