1

我已经加载了 MapQuest JavaScript api 模块,并且能够在http://developer.mapquest.com/web/documentation/sdk/javascript/v7.0/basic-map引入基本示例地图,但是当我尝试使用他们的下一个示例添加地图控件我收到 JavaScript 错误:

                            map.addControl is not a function

我试过 window.map.addControl 但这会产生同样的错误。

有谁知道可能出了什么问题?

谢谢

4

2 回答 2

0

您需要在MQA.EventUtil.observe 调用后在您的权限 内添加地图控制代码window.map = new MQA.TileMap(options);

代码:

<html>
  <head>
    <script src="http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=Kmjtd%7Cluua2qu7n9%2C7a%3Do5-lzbgq"></script>

    <script type="text/javascript">

      MQA.EventUtil.observe(window, 'load', function() {

        /*Create an object for options*/
        var options={
          elt:document.getElementById('map'),        /*ID of element on the page where you want the map added*/
          zoom:10,                                   /*initial zoom level of map*/
          latLng:{lat:39.743943, lng:-105.020089},   /*center of map in latitude/longitude*/
          mtype:'map'                                /*map type (map)*/
        };

        /*Construct an instance of MQA.TileMap with the options object*/
        window.map = new MQA.TileMap(options);
                                MQA.withModule('largezoom','traffictoggle','viewoptions','mousewheel', function() {

          map.addControl(
            new MQA.LargeZoom(),
            new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT, new MQA.Size(5,5))
          );

          map.addControl(new MQA.TrafficToggle());

          map.addControl(new MQA.ViewOptions());

          map.enableMouseWheelZoom();
        });
      });

    </script>
  </head>

  <body>
    <div id='map' style='width:750px; height:280px;'></div>
  </body>
</html>
于 2014-04-08T04:16:56.060 回答
-1

确保在将控件添加到地图之前添加控件的模块。

于 2013-11-19T17:54:36.043 回答