¡Ayúdanos a traducir esta Web y consigue licencias gratis!
Usuario anónimo  |  Ingresar  |  Regístrate
Mensaje dentro General Discussions

Centre map

Responder 
#1 - 15/01/2010 1:08:51 Reporta abuso | Link permanente
greyhound
Fecha de registro: 08/01/2010
10 posts en todos los foros
Centre map

Responder Citar
Hi,

I am going to have one permanent marker on the map.
This marker will be "draggable" by the user. After it has been dragged I need the map to centre on the resting position of the marker.

Can anyone tell me how to do this?

One final question - when adding javascript functions to events can anyone tell me what the {0} part of {0}.panTo   means Is it an array number or something.

Any help really appreciated. Its taking me a long long time to get my head around how this all works.

Thanks in advance and sorry for newbie questions.

Volver arriba

Respuestas
De en 15
#2 - 15/01/2010 12:56:44 Reporta abuso | Link permanente
greyhound
Fecha de registro: 08/01/2010
10 posts en todos los foros
RE: Centre map

Responder Citar
Just in case anyone finds this useful.

In order to centre the map on a marker that has been dragged to a certain point (rather than click which is all the example code shows how to do) please follow the instructions below. I have commented the code to make the example worthwhile:

c#

    protected void Page_Load(object sender, EventArgs e)
    {
 //my marker will be static, I only want to add the marker and listener once so check for initial page load
        if (!IsPostBack)
        {
            int zoom = 15;
            //set up a default map
            GMap1.Width = 450;
            GMap1.Height = 330;
     //Create a default longitude and latitude for the map to start with
            GLatLng latlng = new GLatLng(51.420714, -0.401875);
     //Set the map centre using my latlng co-ordinates
            GMap1.setCenter(latlng, zoom);

     //Create options for the marker to be added
            GMarkerOptions mOpts = new GMarkerOptions();
            mOpts.draggable = true;
            mOpts.bouncy = true;
            mOpts.title = "Drag me to find your spot";
     //Create a new marker and assign the co-ordinates and the options
            GMarker mkr = new GMarker(latlng, mOpts);
            GMap1.Add(mkr);

     //probably a better way to do this but hey!
     //create a string builder and create the javascript function to be fired when the marker is dragged
    
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("function(marker) {");
            sb.Append("if (marker){");
            sb.AppendFormat("{0}.panTo(marker);", GMap1.GMap_Id);
            sb.Append("}");
            sb.Append("}");
            GListener listener2 = new GListener(mkr.ID, GListener.Event.dragend, sb.ToString());
            GMap1.addListener(listener2);
        }

    }

Volver arriba
De en 15

Powered by Subgurim.NET