	var map = null;
    var startGeocoded = null;
    var destinationGeocoded = null;
 
      function goMap24() {
  	
  	map = Map24.Webservices.getMap24Application({
  	  AppKey:"FJXea7d1ef2eb6886fe33bbc82896b1fX13",
  	  MapArea:document.getElementById("maparea"),
          Maptype: "JAVA",
  	  MapWidth: 400,
  	  MapHeight: 390
  	});
      }
	  
	  function addLocation(){
        var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
        mrcContainer.push(
          new Map24.Webservices.MRC.DeclareMap24Location({
            MapObjectID: "myLocation",
            Coordinate: new Map24.Coordinate( 21.1917	,	2836.0073	),
			LogoURL: "http://www.rando-valdeloire.fr/pointe.png",
            SymbolID: 20100
          })
        );
        mrcContainer.push(
          new Map24.Webservices.MRC.ControlMapObject({
            Control: "ENABLE",
            MapObjectIDs: "myLocation"
          })
        );
        mrcContainer.push(
          new Map24.Webservices.MRC.SetMapView({
            Coordinates: new Map24.Coordinate( 21.1917	,	2836.0073	),
			ClippingWidth: new Map24.Webservices.ClippingWidth(
              { MinimumWidth: 4000 }            
            )
          })
        );
        map.Webservices.sendRequest( mrcContainer );
      }
	  
	  
	  
	  function calculateRouteAddr( start, destination ){
        if( typeof start == 'undefined' || start == '' ){
          Map24.dump( "No start address defined!" );
          return;
        }
        if( typeof destination == 'undefined' || destination == '' ){
          Map24.dump( "No destination address defined!" );
          return;
        }
        geocodeStartAndDestination( start, destination );
        return;
      }
      
      function geocodeStartAndDestination( start, destination ){
        //1. Geocode the start address
        geocode( start, onGeocodeStart )

        //2. When start address has been geocoded, then geocode destination address
        function onGeocodeStart( geoRes ){
          startGeocoded = geoRes.firstResult;
          geocode( destination, onGeocodeDest )
        }
        //3. When both start and dest address have been geocoded, then start route calculation
        function onGeocodeDest( geoRes ){
          destinationGeocoded = geoRes.firstResult;
          calculateRouteCoord( startGeocoded, destinationGeocoded );
        }
      }
      
      //Calculate a route between two addresses
      function calculateRouteCoord( startGeocoded, destinationGeocoded ){
        if( startGeocoded == 'NULL' || typeof startGeocoded == 'undefined' ) return;
        if( destinationGeocoded == 'NULL' || typeof destinationGeocoded == 'undefined' ) return;
      
        var routeRequest = new Map24.Webservices.Request.CalculateRoute( map );
        routeRequest.Start = new Map24.Webservices.Request.CalculateRoute.CoordinateAndAddress();
        routeRequest.Start.Coordinate = new Map24.Coordinate( startGeocoded.Coordinate.Longitude,
                                                              startGeocoded.Coordinate.Latitude );
        routeRequest.Destination = new Map24.Webservices.Request.CalculateRoute.CoordinateAndAddress();
        routeRequest.Destination.Coordinate = new Map24.Coordinate( destinationGeocoded.Coordinate.Longitude,
                                                                    destinationGeocoded.Coordinate.Latitude );
        map.Webservices.sendRequest( routeRequest );
      
       //This listener is called when the route calculation has finished
        map.onCalculateRoute = function( event ){
          var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
          mrcContainer.push( 
            new Map24.Webservices.MRC.DeclareMap24RouteObject({
              MapObjectID: "actualRoute",
              Map24RouteID: event.Info.RouteID,
              Color: new Map24.Color( 255, 0, 0, 180 )
            }) 
          );
          //Center the map view on the route visualization
          mrcContainer.push( genSetMapView( 15000, 70, 0, 0, 'actualRoute' ) );
          
          //Enable the visibility of the route 
          mrcContainer.push( genControlMapObject( 'ENABLE', 'actualRoute' ) );
          
          map.Webservices.sendRequest( mrcContainer );
        }
      }
      
      //Geocoding
      function geocode( address, onGeoFunc ){
        map.Webservices.sendRequest(
          new Map24.Webservices.Request.MapSearchFree(map, {
            SearchText: address,
            MaxNoOfAlternatives: 3
          })
        );
      
        map.onMapSearchFree = function( event ){
          //Use dump console to output event object; the event object is the result
          Map24.dump( event );

          var geoRes = new Object();
          geoRes.Alternatives = event.Alternatives;
          geoRes.firstResult = geoRes.Alternatives[0];

          onGeoFunc( geoRes );
        }
      }    
      
      //Factory functions
      function genSetMapView( ClippingWidth, ClippingPercent, Long, Lat, id ){
        var Clip = new Array();
        if( ClippingWidth != '' ) Clip['MinimumWidth'] = ClippingWidth;
        if( ClippingPercent != '' ) Clip['ViewPercentage'] = ClippingPercent;
        if( Long != '' && Lat != '' )
        {
          var SetMapView = new Map24.Webservices.MRC.SetMapView({
            ClippingWidth: new Map24.Webservices.ClippingWidth( Clip ),
            Coordinates: new Map24.Coordinate( Long, Lat )
          });
        } 
        else if( id != '' )
        {
          var SetMapView = new Map24.Webservices.MRC.SetMapView({
            ClippingWidth: new Map24.Webservices.ClippingWidth( Clip ),
            MapObjectIDs: id 
          });
        }	
        return SetMapView;	
      }		
      
      function genControlMapObject( Control, id ){
        var ControlObject = new Map24.Webservices.MRC.ControlMapObject({
          Control: Control,
          MapObjectIDs: id
        });
        return ControlObject;
      }  
	  //fonction voir la route
	  function control3DRoute( cmd ){
        var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
        mrcContainer.push( 
          new Map24.Webservices.MRC.ControlComponent({
            Component: "M3DROUTE",
            Control: cmd
          }) 
        );
        mrcContainer.push( 
          new Map24.Webservices.MRC.ControlComponent({
            Component: "SHOWM3DROUTE",
            Control: cmd
          }) 
        );
        map.Webservices.sendRequest( mrcContainer );
      }
	  //fonction 3D
	  function control3DView( cmd ){
        var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
        mrcContainer.push( 
          new Map24.Webservices.MRC.ControlComponent({
            Component: "M3D",
            Control: cmd
          }) 
        );
        mrcContainer.push( 
          new Map24.Webservices.MRC.ControlComponent({
            Component: "SHOWM3D",
            Control: cmd
          }) 
        );
        map.Webservices.sendRequest( mrcContainer );
      }
