none
Microsoft.Maps.registerModule - Javascript path issue RRS feed

  • Question

  • Hi

    I am trying to register modules in my ASP.NET MVC application view (.cshtml). The application can not recognise the .js file. I tried to place the .js file same location where my view (.cshtml). But it is not loading.

    Can anybody please help me how to refer the .js file in the Microsoft.Maps.registerModule()?

    Here is my project structure:

    http://localhost/MyApplication/Test/Dashboard

    My ShapeToolboxModule.js is in my Scripts/ShapeToolboxModule.js in the project. I also placed the ShapeToolboxModule.js in View/Test folder.

    Microsoft.Maps.registerModule("DrawShapeModule", "ShapeToolboxModule.js");

    Where exactly I have to place ShapeToolboxModule.js file and how to refer? It is only the issue with ASP.NET MVC .cshtml project.


    Bala

    Wednesday, May 30, 2012 4:27 PM

Answers

  • Hi,

    Finally I was able to fix my issue by using <script> tag to register the module instead of using Microsoft.Maps.registerModule("HeatMapModule",'Scripts/heatmap.min.js');

    Here is the working solution. It works in Safari also.

    <scripttype="text/javascript">Microsoft.Maps.registerModule('HeatMapModule');</script>

    <scripttype="text/javascript"src="~/Scripts/heatmap.min.js"></script>


    Bala

    Thursday, May 31, 2012 2:51 PM
  • This is a very old forum post that used an open source module for adding heat maps to Bing Maps V7. That module was updated in June to make it partially supported in V8. However the Bing Maps V8 control now supports heat maps out of the box, so no need for an open source module, just use the built in heat map module which is officially supported and less likely to break as changes occur to the map API.

    [Blog] [twitter] [LinkedIn]

    Tuesday, November 15, 2016 10:33 PM
  • Currently there are no xml based file readers in v8, however we plan to add one in a few months. There is some open source modules for loading georss files into bing maps v7 which work with v8 that you can use: http://bingmapsv7modules.codeplex.com/

    [Blog] [twitter] [LinkedIn]

    Wednesday, November 16, 2016 4:00 PM
  • Ah, I see the issue. You are loading the module before the Map script is even loaded. The registerModule call should be done in the map load callback like this:

    <script type="text/javascript" src="http://www.bing.com/api/maps/mapcontrol?callback=GetMap" async defer></script>
    
    <script type="text/javascript">
    function GetMap(){
    	//Load map and modules now that the Microsoft Namespace is loaded.
    }
    </script>


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, November 16, 2016 10:52 PM
    • Marked as answer by Ricky_Brundritt Wednesday, November 16, 2016 10:52 PM
    Wednesday, November 16, 2016 10:52 PM

All replies

  • Hi,

    I tested with exact in regular HTML file and works fine. In ASP.NET MVC , modules are not getting registered.

    I added small test  function ( for ex, function Test(){ alert(' hi'); } inside the ShapeToolboxModule.js  and when I called from my .cshtml view it works fine.

    But the following returns null:  

    var a = Microsoft.Maps.registerModule("DrawShapeModule", 'Scripts/ShapeToolboxModule.js');

    I tried by placing ShapeToolboxModule.js in the same folder where my .cshtml is there. But it is not working.

    I tried ShapeToolboxModule, HeatMap and CustonInfobhanksox and all are having same issue in ASP.NET MVC view.

    Please help me.


    Bala

    Thursday, May 31, 2012 12:30 AM
  • I do see the callback method in

    Microsoft.Maps.loadModule("ShapeToolboxModule", { callback: myModuleLoaded });

    is getting called. But I am getting "Microsoft JScript runtime error: Access is denied." in styleSheet.cssRules

    else if (mediaType == "object") {
                    for (i = 0; i < styleSheet.cssRules.length; i++) {
                        if (styleSheet.cssRules[i].selectorText.toLowerCase() == selector.toLowerCase()) {
                            styleSheet.cssRules[i].style.cssText = style;
                            return;
                        }
                    }

    Bala

    Thursday, May 31, 2012 1:29 AM
  • Please read my above comments before this...

    I just noticed a strange thing. If I add alert() statements before and after myToolbox = new ShapeToolboxModule(map); line then I am not getting the 'Access denied' error and it works perfectly in IE web browser. If I remove any of the below then it throws javascript error.

    function myModuleLoaded() {
         //Create new instance of module
         alert(11);
         myToolbox = new ShapeToolboxModule(map);
         alert(myToolbox);
     }

    I am targeting iPhone Safari browser and the above is not working ( not getting alert message ).


    Bala

    Thursday, May 31, 2012 2:01 AM
  • Hi,

    Finally I was able to fix my issue by using <script> tag to register the module instead of using Microsoft.Maps.registerModule("HeatMapModule",'Scripts/heatmap.min.js');

    Here is the working solution. It works in Safari also.

    <scripttype="text/javascript">Microsoft.Maps.registerModule('HeatMapModule');</script>

    <scripttype="text/javascript"src="~/Scripts/heatmap.min.js"></script>


    Bala

    Thursday, May 31, 2012 2:51 PM
  • This works on Bing Maps V7, but as soon as I switch to V8 it can no longer find the module.

    To switch to V8 I replaced the url http://ecn.dev.virtualearth.net...

    for http://www.bing.com/api/maps/mapcontrol?callback=GetMap

    Please let me know if there is anything extra that needs to be done on V8.

    Tuesday, November 15, 2016 9:11 PM
  • This is a very old forum post that used an open source module for adding heat maps to Bing Maps V7. That module was updated in June to make it partially supported in V8. However the Bing Maps V8 control now supports heat maps out of the box, so no need for an open source module, just use the built in heat map module which is officially supported and less likely to break as changes occur to the map API.

    [Blog] [twitter] [LinkedIn]

    Tuesday, November 15, 2016 10:33 PM
  • Thanks for your reply.  The Bing Maps API V8 show how to load the Heat Maps from GeoJson, but I need to read it from RSS Feeds.  Do you have something equivalent to Microsoft.Maps.GeoJson.readFromUrl for RSS, or XML?

    
    Wednesday, November 16, 2016 1:02 PM
  • Currently there are no xml based file readers in v8, however we plan to add one in a few months. There is some open source modules for loading georss files into bing maps v7 which work with v8 that you can use: http://bingmapsv7modules.codeplex.com/

    [Blog] [twitter] [LinkedIn]

    Wednesday, November 16, 2016 4:00 PM
  • That is the example I’m trying to use, but using V8, it cannot registerModule.  This is the reason I posted the message on this site.  I tried following the advice above but get this message:
    
    0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'registerModule'
    <script type='text/javascript'> Microsoft.Maps.registerModule("GeoRSSModule", "~/Scripts/GeoRSSModule.js");</script>
    

    
    Wednesday, November 16, 2016 5:46 PM
  • Ah, I see the issue. You are loading the module before the Map script is even loaded. The registerModule call should be done in the map load callback like this:

    <script type="text/javascript" src="http://www.bing.com/api/maps/mapcontrol?callback=GetMap" async defer></script>
    
    <script type="text/javascript">
    function GetMap(){
    	//Load map and modules now that the Microsoft Namespace is loaded.
    }
    </script>


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, November 16, 2016 10:52 PM
    • Marked as answer by Ricky_Brundritt Wednesday, November 16, 2016 10:52 PM
    Wednesday, November 16, 2016 10:52 PM
  • When I do this then I end up with the original issue that was posted in this forum.

    ... Never mind I decided to switch to GeoJSON.

    Thank you

    • Edited by pjra3 Monday, November 21, 2016 5:10 PM
    Thursday, November 17, 2016 6:16 PM