function $pv() {};

var dragMap;

function initDrag() {
    dragMap = new MQA.TileMap(document.getElementById('dragMapWindow'));
    MQA.withModule('routeio', 'route', function() {
        var io = new MQA.RouteIO(HOST_URL+"/directions/v1");
        var delegate = new MQA.Route.RouteDelegate();
        
        //  Override the default dragRoute function from the routeio module.
        //  By doing so, we can intercept the dragRoute requests in realtime.
        //  We will simply show the same route request in a <div> element.
        //  The Location objects will be trimmed down to only the latLng and
        //  dragPoint attributes.
        var oldDrag = io.dragRoute;
        io.dragRoute = function(routeRequest, ioSettings, callback) {
            url = io.baseURI + '/dragroute?key=YOUR_KEY_HERE';
            var trimLocations = new Array();
            var i;
            var locations = routeRequest.locations;
            for (i = 0; i < locations.length; i++) {
                var location = locations[i];
                trimLocations.push(
                    {
                        linkId: location.linkId,
                        latLng: location.latLng,
                        dragPoint: location.dragPoint 
                    }
                );
            }
            url += '&json=' + MQA.IO.stringifyJSON({mapState: routeRequest.mapState, locations: trimLocations});
            document.getElementById('dragURL').innerHTML = url;    
            return oldDrag.call(this, routeRequest, ioSettings, callback);
        }
                
        var RouteController = dragMap.createRoute(delegate, io, {ribbonOptions: {draggable: true,draggablepoi:true},routeOptions:{shapeFormat: 'raw'}});
        io.route(
            {
                locations: ["Boalsburg, PA", "Philadelphia, PA"],
                mapState: RouteController.delegate.virtualMapState(dragMap)
            }, 
            { 
                timeout: 10000
            },
            function(results) {
                RouteController.setRouteData(results.route);
                dragMap.bestFit();
            }
        );
    });
}

