locked
Map takes entire page, should stay in div RRS feed

  • Question

  • New to Bing Maps.

    I need to have several divs on the page and the map in only one of them. The documentation says that the map will take on the size of the div, that does not seem to be the case as the map takes up the whole page and does not respect the size of the div.

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link href="StyleSheet.css" rel="stylesheet" />
        <script src="scripts/jquery-1.9.1.js"></script>
        <script src="scripts/knockout-2.2.1.js"></script>
        <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
        <script src="scripts/JBingMaps.js"></script>
        <title></title>
    </head>
    <body>
    <div id='mapDiv'"></div>
    
    <div id='navDiv'>
        Test right nav
    </div> 
    </body>
    
    </html>
    $(function () {
        var JBingKey = "{key}";
        var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {
            credentials: JBingKey,
            center: new Microsoft.Maps.Location(33.5, -112.45),
            mapTypeId: Microsoft.Maps.MapTypeId.road,
            zoom: 10
        });
    });
    
    
    
    
    

    body {
    }
    #mapDiv {
        float: left;
        border: thin solid #000000;
        margin: 0px;
        height: 500px;
        width: 1000px;
    }
    #navDiv {
        border-style: solid solid solid none;
        border-width: thin thin thin 0px;
        border-color: #000000;
        float: left;
        margin: 0px;
        width: 187px;
        height: 500px;
    }


    Saturday, March 30, 2013 4:18 PM

Answers

  • Well, I have done a workaround by using Knockout and JQuery to resize the div AND the map at the same time and it works well.

    You see my objective was to have a navigational div on the right which the map was wiping out by blowing out of the div.

    According to the documentation this should not be needed as the map is supposed to take the size of the div.

    Oh well.  I guess I live with it.

    • Marked as answer by Jerry Lanp Thursday, April 4, 2013 2:16 AM
    Thursday, April 4, 2013 2:16 AM
  • There are several issues with the original code. The first one is that a CSS position is never defined for the map. This is a simple thing to do and is the cause of most formatting issues. The second issue is that the code sample is missing the proper doctype and metadata tag as specified here: http://msdn.microsoft.com/en-us/library/gg427624.aspx

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Tuesday, August 27, 2013 10:46 AM
    • Unproposed as answer by Jerry Lanp Tuesday, August 27, 2013 2:15 PM
    • Proposed as answer by Ricky_Brundritt Tuesday, August 27, 2013 3:33 PM
    • Marked as answer by Ricky_Brundritt Wednesday, November 6, 2013 1:40 PM
    Tuesday, August 27, 2013 10:46 AM
  • There is a property in CSS called "position" which you don't define which is one of the main issues. Simply try adding ";" to the #mapDiv CSS class. Width and height are not positions but dimensions. If you want the map to resize with the div as it changes sizes then you can use percentages for the width and height.

    http://rbrundritt.wordpress.com

    Tuesday, August 27, 2013 3:33 PM

All replies

  • Well, I have done a workaround by using Knockout and JQuery to resize the div AND the map at the same time and it works well.

    You see my objective was to have a navigational div on the right which the map was wiping out by blowing out of the div.

    According to the documentation this should not be needed as the map is supposed to take the size of the div.

    Oh well.  I guess I live with it.

    • Marked as answer by Jerry Lanp Thursday, April 4, 2013 2:16 AM
    Thursday, April 4, 2013 2:16 AM
  • Did you ever find a better solution? I am having the exact same problem and I think it has to do with the page layout.
    Monday, August 26, 2013 4:10 PM
  • Sorry, I never found a better way.  I just use JQuery to get the window size and set the map size manually when it changes.
    Tuesday, August 27, 2013 12:52 AM
  • There are several issues with the original code. The first one is that a CSS position is never defined for the map. This is a simple thing to do and is the cause of most formatting issues. The second issue is that the code sample is missing the proper doctype and metadata tag as specified here: http://msdn.microsoft.com/en-us/library/gg427624.aspx

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Tuesday, August 27, 2013 10:46 AM
    • Unproposed as answer by Jerry Lanp Tuesday, August 27, 2013 2:15 PM
    • Proposed as answer by Ricky_Brundritt Tuesday, August 27, 2013 3:33 PM
    • Marked as answer by Ricky_Brundritt Wednesday, November 6, 2013 1:40 PM
    Tuesday, August 27, 2013 10:46 AM
  • Hmm...  I wouldn't say that it (CSS Position) is never define.  The CSS position as you call it is defined in the CSS and technically is not a position, but rather a height and width. I believe it belongs in the CSS and not as an inline style.  As for the doctype, well, call me new fashioned. I need that doctype  for the rest of my application.

    If it is true, then that the map only respects the size of the div if that size is explicitly defined as an inline style, then the map control needs to be fixed, and probably with an option to maintain backward compatibility.

    I will accept the task of setting the size with code.

    Tuesday, August 27, 2013 2:15 PM
  • There is a property in CSS called "position" which you don't define which is one of the main issues. Simply try adding ";" to the #mapDiv CSS class. Width and height are not positions but dimensions. If you want the map to resize with the div as it changes sizes then you can use percentages for the width and height.

    http://rbrundritt.wordpress.com

    Tuesday, August 27, 2013 3:33 PM