Sorry, no link yet.
But a (quite tricky) solution:

function initialize()
{
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(66.00,33.00), 15);
        map.addControl(new GSmallMapControl());

        getDirections ('Address 1', 'Address 2');
}

function getDirections (fromAddr, toAddr)
{
        var panel= document.getElementById("panel");
        directions = new GDirections(null, panel);
        directions.load("from: " +fromAddr+ " to: "+toAddr, { getPolyline:
true, preserveViewport: false } );
        GEvent.addListener(directions,'load', showDirections);
}

function setMarkers()
{
        var startMarker = new GMarker(directions.getMarker(0).la);
        var endMarker = new GMarker(directions.getMarker(1).la)
        map.addOverlay(startMarker);
        map.setCenter(startMarker.la, 12);
        map.addOverlay(endMarker);

        GEvent.addListener(startMarker, "click", function() {
                startMarker.openInfoWindowHtml('<p>This is the start 
point.</p>');
        });

        GEvent.addListener(endMarker, "click", function() {
                endMarker.openInfoWindowHtml('<p>This is the end point.</p>');
        });

}

function showDirections()
{
        setMarkers();
        var points = [];
        var poly = directions.getPolyline();
        for (var i = 0; i < poly.getVertexCount(); i++) {
                points[i] = poly.getVertex(i);
        }
        var mypoly = new GPolyline(points, "#ff0000", 3, 1);
        map.addOverlay(mypoly);

}

$(window).ready(function()
{
        initialize();
});


It's not too nice an by no means finished but works.
Thanks for all your help!

—trice


On Dec 11, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Dec 11, 6:58 am, trice22 <[EMAIL PROTECTED]> wrote:
>
> > The timeOut works but not very nicely:
>
> > var t = setTimeout(function()
> > {
> >         GEvent.addListener(directions.getMarker(0), "click", function() {
> >                 directions.getMarker(0).openInfoWindowHtml('<p>Text here 
> > and here</
> > p>');
> >         });
>
> > }, 500);  // e.g. 100 seems to be to short
>
> > The blowUp shows up for a split second and is then replaced by the
> > info window.
> > There has to be a better way to handle this, no?
>
> Link?
>
>
>
> > —trice
>
> > On Dec 11, 4:53 pm, trice22 <[EMAIL PROTECTED]> wrote:
>
> > > Hello,
>
> > > GEvent.addListener(directions,"load", function() {
> > >         // Kill the existing API GDirections listener
> > >         GEvent.clearListeners(directions.getMarker(0),"click");
> > >         // Add your listener
> > >         GEvent.addListener(directions.getMarker(0), "click", function() {
> > >                 alert("Click on Marker");
> > >                 directions.getMarker(0).openInfoWindowHtml('<p>Text here 
> > > and here</
> > > p>');
> > >         });
>
> > > });
>
> > > The alert "Click on Marker" shows up fine, the info window doesn't
> > > open but the blowup instead.
> > > Overriding the API's some seems to happen "too early". Starting to
> > > think that a timeout will be my only chance here…
>
> > > Thanks,
> > > —trice
>
> > > On Dec 11, 4:01 pm, Mike Williams <[EMAIL PROTECTED]> wrote:
>
> > > > Wasn't it trice22 who wrote:
>
> > > > >       directions.load("from: Address 1 to: Address 2");
> > > > >       GEvent.addListener(directions.getMarker(0), "click", function()
>
> > > > GDirections is asynchronous.
>
> > > > directions.getMarker(0) doesn't work until after a successful reply has
> > > > been received.
>
> > > > Try:
> > > >   GEvent.addListener(directions,"load", function() {
> > > >     // Kill the existing API GDirections listener
> > > >     GEvent.clearListeners(directions.getMarker(0),"click");
> > > >     // Add your listener
> > > >     GEvent.addListener(directions.getMarker(0), "click", function() {
> > > >       directions.getMarker(0).openInfoWindowHtml('<p>Text here and
> > > > here</p>');
> > > >     });
> > > >   });
>
> > > > [You probably don't really need to kill the existing listener, if you
> > > > don't your info window will probably overwrite the one created by the
> > > > API fast enough that the user won't notice it.]
>
> > > > --http://econym.org.uk/gmap
> > > > The Blackpool Community Church Javascript Team
--~--~---------~--~----~------------~-------~--~----~
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