2016-11-08 2 views
0

ASP.Net MVC 플랫폼에서 Dojo를 활용하고 사용하려고합니다. 색인()보기에 나는 config.js에서ASP.Net MVC에서 Dojo 사용 문제

@{ 
    ViewBag.Title = "Home Page"; 
} 
<link rel="stylesheet" href="http://js.arcgis.com/3.18/dijit/themes/nihilo/nihilo.css"> 
<link rel='stylesheet' href='http://js.arcgis.com/3.18/esri/css/esri.css' /> 
<script src="http://js.arcgis.com/3.18"></script> 
<script src="~/Map/config.js"></script> 
<div class="container"> 
    <a role="button" id="lib" class="btn btn-default">Add Libraries</a> 
    <a role="button" id="sch" class="btn btn-default">Add Schools</a> 
    <div class="col-md-12" id="map-div"></div> 
</div> 

이 나는 ​​

(function() { 
'use strict'; 
var pathRX = new RegExp(/\/[^\/]+$/), locationPath = location.pathname.replace(pathRX, ''); 
require({ 
    async: true, 
    aliases: [ ['text', 'dojo/text']], 
    packages: [{ 
     name: 'MapCoctent', 
     location: locationPath + '../Map/MapCoctent' 
    }, { 
     name: 'MapServices', 
     location: locationPath + '../Map/MapServices' 
    }, { 
     name: 'Map', 
     location: locationPath + '../Map', 
     main: 'map' 
    }] 
}, ['Map']); 
})(); 

map.js에 나는 내가

mapservices.js에 마지막으로

require([ 
'MapCoctent/appcontroller', 
'MapServices/mapservices', 
'dojo/domReady!' 
], function (AppCtrl, mapServices) { 
    'use strict'; 
    var appCtrl = new AppCtrl({ 
    elem: 'map-div', 
    mapOptions: { 
    basemap: 'streets', 
    center: [-123.141608, 49.245291], 
    zoom: 12, 
    autoResize: false 
} 
}); 
    appCtrl.load(); 
}); 

하고있다가

define(["esri/geometry/Geometry", 
    "esri/geometry/Point", 
    "esri/graphic", 
    "esri/symbols/SimpleMarkerSymbol", 
    "esri/symbols/SimpleFillSymbol", 
    "esri/Color", 
    "dojo/on", 
    "dojo/dom" 
], function (Geometry, Point, Graphic, SimpleMarkerSymbol, SimpleFillSymbol, Color, on, dom) { 
     on(dom.byId("sch"), "click", function() { 
     var point = new Point(-123.141608, 49.245291); 
     var markerSymbol = new SimpleMarkerSymbol(); 
     markerSymbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE); 
     markerSymbol.setSize(12); 
     markerSymbol.setColor(new Color([255, 0, 0])); 
     var pointGraphic = new Graphic(point, markerSymbol); 
     map.graphics.add(pointGraphic); 
    }); 
}); 

appcontroller.js 나는

define([ 
'dojo/_base/declare', 
'esri/map' 
], function (declare, Map) { 
return declare(null, { 
    map: null, 
    options: {}, 
    constructor: function (options) { 
     this.options = options; 
    }, 
    load: function() { 
     this.map = new Map(this.options.elem, this.options.mapOptions); 
    } 
}); 
}); 

을 가지고 있지만 내가 클릭했을 때이 오류가 무엇입니까 학교 추가 버튼을

TypeError: map.graphics is undefined

당신이 날 내가 뭘 잘못 알려 주시기 바랍니다 수 있습니다 오류 및 왜지도 아직 정의되지 않은 상태에서 페이지에 이미 인스턴스가 만들어져 있습니까?

답변

0

가 액세스 할 수없는 형태로에게 (만 appcontroller.js에서 액세스) 다른 모듈

시도가 그것에게 golbal 변수를 만들 수를 그래서지도 객체는 글로벌 변수, 그것은 다른에 액세스 할 것이다되지 않는다 모듈 (js 파일)

var map ; // declare global var here 
define([ 
'dojo/_base/declare', 
'esri/map' 
], function (declare, Map) { 
return declare(null, { 
    //map: null, useless ! 
    options: {}, 
    constructor: function (options) { 
     this.options = options; 
    }, 
    load: function() { 
     map = new Map(this.options.elem, this.options.mapOptions); 
    } 
}); 
});