justin m justin m - 1 month ago 16
HTML Question

javascript works in sandbox but not in browser

I put together this code to produce a map centered on a location and tested it with multiple sandbox applications and it works, but when I try to run it from a .html file on my desktop the page is blank. Does anyone have any ideas on what i'm doing wrong?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user- scalable=no">
<title>OKC MapView - Create a 2D map - 4.1</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

<link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
<script <!-- src="https://js.arcgis.com/4.1/"> //--></script>

<script>
<!--
require([
"esri/Map",
"esri/views/MapView",
"dojo/domReady!"
], function(Map, MapView) {

var map = new Map({
basemap: "togo"
});

var view = new MapView({
container: "viewDiv",
map: map,
zoom: 10,
center: [-97.508, 35.482]
});

});
//-->
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>
</html>

Answer

Are you trying to open the file directly as file:/// then it might not work, as you need to host it in a website.

There is no service by name "togo" it needs to be "topo".

Also, get rid of the un-necessary comments <!-- -->

Hope this was helpful.

Comments