locked
Map_render() Error RRS feed

  • Question

  • Hi

    I followed the 7 steps in this guide: http://msdn.microsoft.com/en-us/library/vstudio/jj733572.aspx#map

    When I run the app, I get the error shown below.

    First up, I'm not 100% sure that I put the references in the correct places in the default.htm file. This is where I have them:

        #silverlightControlHost {
            height: 100%;
        }
        </style>
    
        <script type="text/javascript" charset="utf­8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    
        <script type="text/javascript" src="Silverlight.js"></script>
    
        <script type="text/javascript">
            function checkDirty(e) {

    above is where I placed the start reference and below is the end reference (bolded):

                    errMsg += "MethodName: " + args.methodName + "     \n";
                }
    
                throw new Error(errMsg);
            }
        </script>
        <script type="text/javascript" charset="utf­8" src="Scripts/lightswitch.bing-maps.js"></script>
    </head>
    
    <body>
        <!-- Runtime errors from Silverlight will be displayed here.

    I also suspect that I have to pass a "postal" address or Lat/Long but no example is given. When I run the app and go to the tab that holds the map I get this error.

    If someone can point me to an example it will be appreciated.

    Thanks, Mark.


    Mark

    Sunday, July 7, 2013 8:34 AM

Answers

  • Hi Mark,

    A little bit of too much copy/paste. The error you're seeing is because of this line in your code above:

    myapp.ViewStoreGroup.Map_render = function (element, contentItem) {
        // Write code here.
        /// <reference path="../GeneratedArtifacts/viewModel.js" />
    
        var mapDiv;
        var current = 0;
        var step = 15;
    
        myapp.BrowseCustomers.Customer_render = function (element, contentItem) {
            mapDiv = $('<div />').appendTo($(element));
    

    My guess is there's no such thing as a BrowseCustomers screen in your application, so myapp.BrowseCustomers does not exist. What the method should at the very least look like is

    var mapDiv;
    var current = 0;
    var step = 15;
    
    myapp.ViewStoreGroup.Map_render = function (element, contentItem) {
    
            mapDiv = $('<div />').appendTo($(element));
            $(mapDiv).lightswitchBingMapsControl();
    
            var visualCollection = contentItem.value;
            if (visualCollection.isLoaded) {
                showItems(current, step, contentItem.screen);
            } else {
                visualCollection.addChangeListener("isLoaded", function () {
                    showItems(current, step, contentItem.screen);
                });
                visualCollection.load();
            }
        };

    However, this will most likely not work for your case because

    • Your content item is a tab, not a collection control like in the sample, so there will be no visualCollection to use.
    • The showItems were meant to show a collection of items, and I'm not sure if that is what you want.

    My suggestion would be to try to follow the example step-by-step using a Northwind database until you got everything working, then look at the code and see how it draws individual item and see how it can apply for your scenario.

    Best regards,
    Huy

    • Marked as answer by ITPSB Friday, July 12, 2013 2:02 AM
    Thursday, July 11, 2013 3:28 PM

All replies

  • Same problem here. Works sometimes after refresh.

    Bug?

    Regards

    Sven


    Sven Elm

    Sunday, July 7, 2013 8:58 PM
  • Hi Sven

    If you look at where I placed the start and end lines of code:

     <script type="text/javascript" charset="utf­8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

    and

        <script type="text/javascript" charset="utf­8" src="Scripts/lightswitch.bing-maps.js"></script>

    Am I placing them in the correct position? (see my original post).

    Thanks, Mark.


    Mark


    • Edited by ITPSB Monday, July 8, 2013 4:20 AM typo
    Monday, July 8, 2013 3:36 AM
  • Hi Mark,

    It looks like you adds the reference into the default.htm file used by the Silverlight client. The default.htm used by HTML Client should be under YourApp.HtmlClient folder.

    Best regards,
    Huy

    Tuesday, July 9, 2013 11:30 PM
  • Thanks Huy

    That was a silly mistake on my part :-/

    I moved the two lines to the HTML client default.htm as shown below but I still see the same error message when displaying the map. Do I have to pass a "postal address" or a long/lat coordinate maybe?

        <title>SkeMaz.Auditor</title>
        <script type="text/javascript" charset="utf­8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
        <script type="text/javascript">
            // Work around viewport sizing issue in IE 10 on Windows Phone 8
            if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
                document.writeln("<style>@-ms-viewport { width: auto!important; }</style>");
            }
        </script>

    1st Line above (bolded).

    2nd line below (also bolded).

        <script type="text/javascript">
            $(document).ready(function () {
                msls._run()
                .then(null, function failure(error) {
                    alert(error);
                });
            });
        </script>
        <script type="text/javascript" charset="utf­8" src="Scripts/lightswitch.bing-maps.js"></script>
    </body>



    Mark

    Wednesday, July 10, 2013 4:14 AM
  • Hi Mark,

    Can you post the content of your Map_render method?

    Thanks,
    Huy

    Wednesday, July 10, 2013 6:01 PM
  • Hello Huy

    Thanks for assisting this newbie to JS (to me C# & SL are a snap compared to JS & HTML5).

    Here's my code. Many thanks, Mark.

    // Replace the code below with the code above when you migrate to VS 2013 and remove the button
    
    myapp.ViewStoreGroup.addDynamicSurvey_execute = function (screen) {
        var newSurvey = new myapp.Survey();
        newSurvey.setStore(screen.GroupList.selectedItem.Store);
        newSurvey.Status = "Started";
        newSurvey.SurveyDateCreated = new Date();
        // Get the location of a device
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (pos) {
                newSurvey.Latitude = pos.coords.latitude.toString();
                newSurvey.Longitude = pos.coords.longitude.toString();
            });
        }
        else {
            alert("Geolocation not supported");
        }
    
    
        return myapp.activeDataWorkspace.ApplicationData
        then.saveChanges()
    //   /\
    //   ||
    // Remove this "then" word when you migrate to VS 2013
        // Save all changes on the screen
    // NOTE: Remove comments when migrating to VS 2013
    //    screen.showTab("StartedSurveys");
    
    //        .then(function () {
    //            screen.showTab("StartedSurveys");
    //        })
    };
    
    
    myapp.ViewStoreGroup.addDynamicSurvey2_execute = function (screen) {
        // Write code here.
        screen.showTab("StartedSurveys");
    };


    Mark

    Thursday, July 11, 2013 3:44 AM
  • myapp.ViewStoreGroup.Map_render = function (element, contentItem) {
        // Write code here.
        /// <reference path="../GeneratedArtifacts/viewModel.js" />
    
        var mapDiv;
        var current = 0;
        var step = 15;
    
        myapp.BrowseCustomers.Customer_render = function (element, contentItem) {
            mapDiv = $('<div />').appendTo($(element));
            $(mapDiv).lightswitchBingMapsControl();
    
            var visualCollection = contentItem.value;
            if (visualCollection.isLoaded) {
                showItems(current, step, contentItem.screen);
            } else {
                visualCollection.addChangeListener("isLoaded", function () {
                    showItems(current, step, contentItem.screen);
                });
                visualCollection.load();
            }
        };
    


    Mark

    Thursday, July 11, 2013 3:47 AM
  • Hi Mark,

    A little bit of too much copy/paste. The error you're seeing is because of this line in your code above:

    myapp.ViewStoreGroup.Map_render = function (element, contentItem) {
        // Write code here.
        /// <reference path="../GeneratedArtifacts/viewModel.js" />
    
        var mapDiv;
        var current = 0;
        var step = 15;
    
        myapp.BrowseCustomers.Customer_render = function (element, contentItem) {
            mapDiv = $('<div />').appendTo($(element));
    

    My guess is there's no such thing as a BrowseCustomers screen in your application, so myapp.BrowseCustomers does not exist. What the method should at the very least look like is

    var mapDiv;
    var current = 0;
    var step = 15;
    
    myapp.ViewStoreGroup.Map_render = function (element, contentItem) {
    
            mapDiv = $('<div />').appendTo($(element));
            $(mapDiv).lightswitchBingMapsControl();
    
            var visualCollection = contentItem.value;
            if (visualCollection.isLoaded) {
                showItems(current, step, contentItem.screen);
            } else {
                visualCollection.addChangeListener("isLoaded", function () {
                    showItems(current, step, contentItem.screen);
                });
                visualCollection.load();
            }
        };

    However, this will most likely not work for your case because

    • Your content item is a tab, not a collection control like in the sample, so there will be no visualCollection to use.
    • The showItems were meant to show a collection of items, and I'm not sure if that is what you want.

    My suggestion would be to try to follow the example step-by-step using a Northwind database until you got everything working, then look at the code and see how it draws individual item and see how it can apply for your scenario.

    Best regards,
    Huy

    • Marked as answer by ITPSB Friday, July 12, 2013 2:02 AM
    Thursday, July 11, 2013 3:28 PM
  • Thanks Huy

    Yep, too much copy, paste and fingers crossed ;-)

    I'll follow the Nothwind example step by step.

    Many thanks, Mark.


    Mark

    Friday, July 12, 2013 2:02 AM