我试图让概述地图示例在这里工作:
https://developers.arcgis.com/javascript/jssamples/widget_overviewmap.html
在我的网站上。我有两个错误。 Chrome在标题中给出了上面的一个,IE给出了" dojo / parser :: parse()errorTypeError:无法获取属性' toString'未定义或空引用"。
Chrome也给了我错误:Uncaught TypeError:当我在我的函数中有OverviewMap变量时,undefined不是函数,IE说SCRIPT438:对象不支持属性或方法' byId' 。如果我这样评论出来:
/*OverviewMap,*/ dom) {
以及下面的引用,我没有得到后两个错误。
看了这个:https://gis.stackexchange.com/questions/86674/arcgis-api-for-javascript-error-in-dojo-parser-parse
我注意到在我下面的.cshtml文件中,我没有Lang = en,但是在我查看控制台时它被添加到HTML中。所以我补充说:
<script>
dojoConfig = {
locale: 'en-us'
};
</script>
但没有变化。
@model Site.Models.LoginModel
@{
ViewBag.Title = "My Map";
}
@functions{
public string GetAntiForgeryToken()
{
string cookieToken, formToken;
AntiForgery.GetTokens(null, out cookieToken, out formToken);
return cookieToken + ":" + formToken;
}
}
@if (1==1)
{
@section toolbar {
<li>
<div id="navToolbar" data-dojo-type="dijit/Toolbar" style="display:none">
<div data-dojo-type="dijit/form/Button" id="printSimple" data-dojo-props="iconClass:'esriPrintIcon', label:'Print'"></div>
<div data-dojo-type="dijit.form.Button" id="measure" data-dojo-props="label:'Measure', iconClass:'esriMeasureIcon'"></div>
<div data-dojo-type="dijit/form/Button" id="zoomin" data-dojo-props="iconClass:'zoominIcon'">Zoom In</div>
<div data-dojo-type="dijit/form/Button" id="zoomout" data-dojo-props="iconClass:'zoomoutIcon'">Zoom Out</div>
<div data-dojo-type="dijit/form/Button" id="zoomfullext" data-dojo-props="iconClass:'zoomfullextIcon'">Full Extent</div>
<div data-dojo-type="dijit/form/Button" id="zoomprev" data-dojo-props="iconClass:'zoomprevIcon'">Prev Extent</div>
<div data-dojo-type="dijit/form/Button" id="zoomnext" data-dojo-props="iconClass:'zoomnextIcon'">Next Extent</div>
<div data-dojo-type="dijit/form/Button" id="pan" data-dojo-props="iconClass:'panIcon'">Pan</div>
<div data-dojo-type="dijit/form/Button" id="deactivate" data-dojo-props="iconClass:'deactivateIcon'">Deactivate</div>
</div>
</li>
<!--
<li>
<img src='@Href("~/Images/map/identify_b.png")' />
</li>
<li>
<img src='@Href("~/Images/map/zoom_in_b.png")' />
</li>
<li>
<img src='@Href("~/Images/map/zoom_out_b.png")' />
</li>
<li>
<img src='@Href("~/Images/map/pan_b.png")' />
</li>
<li>
<img src='@Href("~/Images/map/global_b.png")' />
</li>
<li>
<img src='@Href("~/Images/map/print_b.png")' />
</li> -->
}
<div class="row-fluid" style="height:100%">
<input id="antiForgeryToken" type="hidden" value="@GetAntiForgeryToken()" />
<div class="col col-lg-2 visible-desktop" >Sidebar</div>
<!-- Bootstrap-map-js -->
<div class="col col-lg-10">
<div style="position:absolute; right:20px; top:10px; z-Index:999;">
<div id="titlePane" data-dojo-type="dijit.TitlePane" data-dojo-props="title:'Measurement', closable:'true', open:'false'">
<div id="measurementDiv"></div>
</div>
</div>
<div id="mapDiv" data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"
style="padding:0">
</div>
</div>
</div>
}
else
{
<div class="todoList" id="loginPanel">
<section id="localLoginPanel">
<h2>Log in</h2>
@Html.Partial("_Login")
</section>
<section id="socialLoginPanel">
<h2>Log in using another service</h2>
@Html.Action("ExternalLoginsList", "Account", new { ReturnUrl = ViewBag.ReturnUrl })
</section>
<p>First time here? <a id="showRegister">Sign up</a></p>
</div>
<div class="todoList" id="registerPanel">
<h2>Sign up</h2>
@Html.Partial("_Register")
<p>Already signed up? <a id="showLogin">Log in</a></p>
</div>
}
</div>
@if (1==1)
{
@section styles {
@Styles.Render("~/bundles/bootstrap/map/css")
<link rel= "stylesheet" type="text/css" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css" />
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.9/js/esri/css/esri.css"/>
}
@section scripts {
<!--
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/todo") -->
<script src="http://js.arcgis.com/3.9/"></script>
<script>
dojoConfig = {
locale: 'en-us'
};
</script>
<script>
require(["esri/map", "application/bootstrapmap", "esri/toolbars/navigation",
"dojo/on",
"dojo/parser",
"dijit/registry",
"dijit/Toolbar",
"dijit/form/Button",
"esri/SnappingManager",
"esri/dijit/Measurement",
"dojo/dom",
"esri/dijit/Scalebar",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/TitlePane",
"esri/dijit/OverviewMap",
"dojo/domReady!",
],
function (Map, BootstrapMap, Navigation, on, parser, registry, Toolbar, Button, SnappingManager, Measurement, OverviewMap, dom) {
var map = BootstrapMap.create("mapDiv",{
basemap:"national-geographic",
center:[-122.45,37.77],
zoom:12,
autoResize: true
});
parser.parse();
navToolbar = new Navigation(map);
on(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);
registry.byId("zoomin").on("click", function () {
navToolbar.activate(Navigation.ZOOM_IN);
});
registry.byId("zoomout").on("click", function () {
navToolbar.activate(Navigation.ZOOM_OUT);
});
registry.byId("zoomfullext").on("click", function () {
navToolbar.zoomToFullExtent();
});
registry.byId("zoomprev").on("click", function () {
navToolbar.zoomToPrevExtent();
});
registry.byId("zoomnext").on("click", function () {
navToolbar.zoomToNextExtent();
});
registry.byId("pan").on("click", function () {
navToolbar.activate(Navigation.PAN);
});
registry.byId("deactivate").on("click", function () {
navToolbar.deactivate();
});
$('#navToolbar').show();
esri.config.defaults.geometryService = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer");
measurement = new Measurement({
map: map
}, dom.byId("measurementDiv"));
measurement.startup();
registry.byId("measure").on("click", function () {
measurement.show();
});
function extentHistoryChangeHandler() {
$("#zoomprev").disabled = navToolbar.isFirstExtent();
$("#zoomnext").disabled = navToolbar.isLastExtent();
}
var overviewMapDijit = new OverviewMap({
map: map,
visible: true
});
overviewMapDijit.startup();
});
</script>
}
}
根据回答编辑:
.
.
.
"esri/dijit/OverviewMap",
"dojo/domReady!",
],
function (Map, BootstrapMap, Navigation, on, parser, registry, Toolbar, Button, SnappingManager, Measurement, OverviewMap, dom) {
.
.
.
但没有解决它
答案 0 :(得分:3)
从页面的HTML标记中删除lang =“en”属性
答案 1 :(得分:1)
看起来问题是您没有在需求列表和相关变量列表中的同一位置获得概述图。需要的每个模块都传递给函数,并在同一索引处分配给变量名。因此,require语句中的第一项是“esri / map”。这将传递给函数定义中的第一个变量,即:Map。因此,Map是对esri / Map模块的引用。好到目前为止。
因为某些模块不(总是)需要传递给函数定义中的变量,所以它们只是在最后,例如,你没有“dijit / TitlePane”等参考资料。因此,您需要将esri / dijit / OverviewMap的require更高。它需要与您传递给它的变量名称位于同一位置。把它放在esri / dijit / Measurement和dojo / dom之间。
希望这能解决问题,但如果没有,请告诉我。