2016-05-30 40 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

很高興能幫到您,請將問題標記爲已回答。 –