2016-05-30 128 views
-1

我正在编写使用ArcGIS API和Dojo类开发交互式地图的代码。Arcgis api模块无法加载

它工作正常,直到我定义了一些模块,如“esri/toolbars/draw”或一些其他模块。这些给一个错误:HTTP://localhost/esri/toolbars/draw.js 404(未找到)

我的问题是,如果我使用许多其它模块,例如“道场/ _base/DECLARE”, 'dojo/_base/lang','dojo/on','dojo/Deferred','esri/map'等等,为什么程序不能加载'esri/toolbars/draw'?有趣的是,它在localhost中搜索它,因为我没有在本地使用ArcGIS API,所以它不适合查看。

我想知道是否有人可以帮助我这个。以下是我的代码示例:

require({ 
async: true, 
parseOnLoad: true, 
baseUrl: "/myApp/", 
aliases: [ 
['text', 'dojo/text'] 
], 
packages: [{ 
name: 'controllers', 
location: 'js/controllers' 
}, { 
name: 'services', 
location: 'js/services' 
}, { 
name: 'utils', 
location: 'js/utils' 
}, { 
name: 'widgets', 
location: 'js/widgets' 
}, { 
name: 'app', 
location: 'js', 
main:'main' 
}] 
}, ['app']); 
___________________________________________ widgets/edit/drawTools.js 
define([ 
'dojo/_base/declare', 
'dojo/_base/lang', 
'dojo/on', 
'dijit/_WidgetBase', 
'dijit/_TemplatedMixin', 
'dojo/dom-class', 
'text!widgets/edit/drawTools.html', 
'esri/graphic', 
"esri/toolbars/draw", 
"esri/symbols/SimpleMarkerSymbol", 
"esri/symbols/SimpleLineSymbol", 
"esri/symbols/PictureFillSymbol",  
"esri/symbols/CartographicLineSymbol", 
"esri/Color" 
    ], function(
    declare, lang, on, _WidgetBase, _TemplatedMixin, domClass, template,  graphic, Draw, SimpleMarkerSymbol, SimpleLineSymbol, 
    PictureFillSymbol, CartographicLineSymbol, Color 
    ) { 


     return declare([_WidgetBase, _TemplatedMixin], { 

      templateString: template, 
      map:null, 
      options:{}, 

      constructor: function(options) { 
       this.options = options; 
       this.map = this.options.map; 
      }, 

      postCreate: function() { 
       tb = new Draw(this.map); 
       tb.on("draw-end", '_addGraphic'); 
      } 

      function _addGraphic(evt) { 
     } 
     }) 
    }) 

回答

0

您的dojo运行时配置不正确。请参阅文档。 here

Note that not all configuration options can be set at runtime. In particular, async, tlmSiblingOfDojo, and pre-existing has tests cannot be changed once the loader is loaded. Additionally, most configuration data is shallow copied, which means that you couldn’t use this mechanism to, for example, add more keys to a custom configuration object—the object would be overwritten

尝试使用添加dojoConfig的默认方式。另外,在添加esri api url之前,必须添加dojoConfig。

<script> 
    dojoConfig= { 
     parseOnLoad: true, 
     async: true 
     package: [{ 
      "name": "agsjs", 
      "location": location.pathname.replace(/\/[^/]+$/, "")+'/agsjs' 
      }] 
    }; 
</script> 

Dojo api是esri api的一部分,因此不需要为dojo添加显式url。

+0

非常感谢,它解决了这个问题。 – samira

+0

很高兴能帮到您,请将问题标记为已回答。 –