I want to show tooltip for my dojo button, I have tried the following code but getting error: Uncaught SyntaxError: Unexpected token (
. Please solve this issue.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="http://js.arcgis.com/3.14/"></script>
<script>
var map,toolbar,toolTip;
require(["esri/map",
"esri/toolbars/draw",
"esri/graphic",
"esri/symbols/SimpleLineSymbol",
"esri/Color",
"dojo/on",
"dojo/dom",
"dijit/Tooltip",
"dojo/domReady!"],
function(Map,Draw,Graphic,SimpleLineSymbol,Color,on,dom,Tooltip) {
map = new Map("map", {
basemap: "streets",
center: [72, 25.75],
zoom: 5
});
//map.on("load",createToolbar);
dojo.connect(Info, "onclick", createToolbar);
function createToolbar() {
toolbar = new Draw(map, { showTooltips: true });
toolbar.activate(Draw.RECTANGLE);
toolbar.on("draw-end", addToMap);
}
function() {
toolTip = new Tooltip({
connectId: ["Info"],
label: "value <b>Draw PolyLine</b>"
});
}
function addToMap(evt) {
//alert("Index");
toolbar.deactivate();
var sls = new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255,0,0]),3);
var graphic = new Graphic(evt.geometry, sls);
map.graphics.add(graphic);
}
});
</script>
</head>
<body>
<div id="map">
<div> <button id="Info" data-dojo-type="dijit/form/Button"><b>Draw PolyLine</b></button>
<div data-dojo-type="dijit/Tooltip" data-dojo-props="connectId:'Info',position:['below']"></div>
</div>
</div>
</body>
</html>
-
1This looks not like a GIS/ArcGIS specific problem, but like a problem with malformatted javascript code.til_b– til_b2016年02月03日 14:23:47 +00:00Commented Feb 3, 2016 at 14:23
2 Answers 2
The function definition below (before addToMap)
function() {
toolTip = new Tooltip({
connectId: ["Info"],
label: "value <b>Draw PolyLine</b>"
});
throws the syntax error.
You have to add a name to that function definition, like
function createTooltip() {
toolTip = new Tooltip({
connectId: ["Info"],
label: "value <b>Draw PolyLine</b>"
});
-
Mine was the answer to msurya question. The syntax error is there, in the function() { like. Sorry for being too short.fradal83– fradal832016年02月03日 15:15:15 +00:00Commented Feb 3, 2016 at 15:15
You have to place the code executed by your addToMap(evt)
function in curly brackets.The problem is that you missed the closing bracket at the end of the function:
function addToMap(evt) {
//alert("Index");
toolbar.deactivate();
} //<- expected token
So your browser expects to see the closing bracket, but it moves along to the next line and gets
var sls = new SimpleLineSymbol( //Not "{", so it's an unexpected token.
EDIT: You have to pay attention to the closing brackets and paranthesis, otherwise your code won't work. You missed a few more:
zoom: 5
});
}); //<- you should add } to close the function(Map,Draw,Graphic,...)
//and ) to close the require
//map.on("load",createToolbar);