This project has moved. For the latest updates, please go here.

Some ideas...

Jan 24, 2010 at 11:04 PM

 

I'm thinking of using this code in a future project of mine and I started making some changes on the code based on my needs. I leave here what I've done so far. If the creator would like to add it to the final code, go ahead. :)

I'm only using google maps so I only made code for this kind of map.

I managed to change the constructor of GoogleMap in order to support language and also map version. Below is the code from the 2 files i've changed:

On file GoogleMapExtensions.cs:

 

    public static class GoogleMapExtensions
    {
        public static GoogleMap GoogleMap( this AjaxHelper helper ) {
            //DateTime dt = DateTime.Now;
            //return GoogleMap( helper, "G" + string.Format( "{0}{1}{2}", dt.Minute, dt.Second, dt.Millisecond ) );
            return GoogleMap( helper, null );
        }

        public static GoogleMap GoogleMap( this AjaxHelper helper, string mapID ) {
            return GoogleMap( helper, mapID, null);
        }

        public static GoogleMap GoogleMap( this AjaxHelper helper, string mapID, string map_language) {
            return GoogleMap( helper, mapID, map_language, null );
        }

        public static GoogleMap GoogleMap( this AjaxHelper helper, string mapID, string map_language, int? version ) {
            if ( string.IsNullOrEmpty( mapID ) ) {
                DateTime dt = DateTime.Now;
                mapID = "G" + string.Format( "{0}{1}{2}", dt.Minute, dt.Second, dt.Millisecond );
            }
            var map = new GoogleMap( helper, mapID, map_language, version );

            map.Zoom( 4 );

            //map.Zoom( 4 )
            //    .Center( 39.9097362345372, -97.470703125 )
            //    .MapType( MapType.Road );

            return map;
        }
    }

And them have to change on GoogleMap.cs constructor:

 

public GoogleMap(AjaxHelper helper, string mapID, string map_language, int? version)
            : base(helper, mapID, "MvcMaps.GoogleMap")
        {
            int current_version = 2;
            // I only know about version 2 and 3...
            if ( version.HasValue && version.Value == 2 || version.Value == 3 )
                current_version = version.Value;
            string googlemaps_js = string.Format( "http://maps.google.com/maps?file=api&v={0}&key=abcdefg&sensor=false", current_version );

            if ( !string.IsNullOrEmpty( map_language ) ) {
                // google changed the language parameter in version 3...
                string language_prefix = current_version == 2 ? "&hl=" : "&language=";
                googlemaps_js += language_prefix + map_language;
            }

            this.ScriptInclude("main", googlemaps_js);
            this.ScriptInclude("gmap.js", WebUtils.GetWebResourceUrl<GoogleMap>("MvcMaps.GoogleMap.js"));
        }

 

 

Then on the page:

 

    <% Ajax.GoogleMap("MapID", "pt-PT", 3)     // Create a Google Map
        .CssClass("GoogleMap") // Define the CSS Style to use. These specify the Maps Size
        .AddPushpin(new Pushpin(41.15, -8.6102) {
                        Title = "Porto",
                        Description = "This is my test pin <a href='#'>LINK?</a><br/>Weeee..."
                    })
        .AddPushpin(new Pushpin(38.713376, -9.136505) {
                        Title = "Lisboa",
                        Description = "This is my test pin"
                    })
        .Center(39, 9)
        .Render();           // Render all the HTML / JavaScript necessary to create the Map to Server.Response
        %>
        <hr />

 

 

This is not particularly well programmed, this is just a proof of concept. I was also thinking in adding the api_key as a parameter.

I had to put all this code on the constructor because the code adds the scripts in it. Is it possible to add the script include on render?? If so it will be much easier to add all this parameters via Getters and Setters.

I don't know if this helps someone out there... please give some feedback :)