I am a beginner of ArcGIS JavaScript API. I am creating a simple web map now. For some reason, the search widget of the map doesn't work. When I go to the console, it shows this error:
Here is my source code:
var navigation;
var mainMap;
require([
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/Color",
"esri/map",
"dojo/dom-construct",
"esri/dijit/Popup",
"esri/InfoTemplate",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/dijit/Search",
"esri/layers/FeatureLayer",
"esri/toolbars/navigation",
"esri/dijit/Legend",
"dojo/domReady!"
], function(SimpleFillSymbol, SimpleLineSymbol, Color, Map, domConstruct, Popup, InfoTemplate,
ArcGISDynamicMapServiceLayer, Search, FeatureLayer, Navigation, Legend ){
var fill = new SimpleFillSymbol("solid", null, new Color("#A4CE67"));
var popup = new Popup({
fillSymbol: fill
},domConstruct.create("div"));
mainMap = new Map("mainMap",{
center: [-112,34.3],
zoom: 7,
basemap: "streets",
infoWindow: popup
});
popup.startup();
var providerInfoTemplate = new InfoTemplate();
providerInfoTemplate.setTitle("<b>Provider Information</b>");
providerInfoTemplate.setContent("<b>Provider Name:</b><br> ${Provider} <br> <b>Address:</b><br> ${FullAddress} <br> <b>Type:</b><br> ${Type_Behavior_Health_Hospital_Health_Center_} <br> <b>Intergration Model:</b><br> ${IntergrationModel} <br>");
var communityInfoTemplate = new InfoTemplate();
communityInfoTemplate.setTitle("<b>community Information</b>")
communityInfoTemplate.setContent("Community Name: ${COUMMUNITY} <br>")
var mainLayer = new ArcGISDynamicMapServiceLayer("http://arcgis-cabhp-1819518128.us-west-1.elb.amazonaws.com/arcgis/rest/services/HCIC/160411_interactive_map_jzz_v01/MapServer",{});
mainLayer.setInfoTemplates({
0:{infoTemplate: providerInfoTemplate},
7:{infoTemplate: communityInfoTemplate}
});
var mainSearch = new Search({
enableButtonMode: false,
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: false,
map: mainMap
}, "searchBar");
var prividerLayer = new FeatureLayer("http://arcgis-cabhp-1819518128.us-west-1.elb.amazonaws.com/arcgis/rest/services/HCIC/160411_interactive_map_jzz_v01/MapServer/0");
var sources = mainSearch.get("sources");
sources.push({
featureLayer: prividerLayer,
searchFields:["Provider"],
displayField: "Provider",
exactMatch: false,
outFields:["Provider"],
name: "HCIC Provider Information",
maxResults: 6,
maxSuggestions: 6,
infoTemplate: new InfoTemplate("Provider Information", "Provider Nmae: ${Provider}</br>Provider Address: ${FullAddress}</br>Provider Type: ${Type_Behavior_Health_Hospital_Health_Center_}"),
enableSuggestions: true,
minCharacters: 0
});
mainSearch.set("sources", sources);
mainSearch.startup();
navigation = new Navigation(mainMap);
myLegend = new Legend({
map:mainMap,
layerInfos:[{
title:"Legend",
layer:mainLayer,
hideLayers:[1,2,3,4,5,6,8,9]
}]
}, "legendDiv");
myLegend.startup();
mainMap.addLayer(mainLayer);
});
function zoomToPrev(){
navigation.zoomToPrevExtent();
}
function zoomToNext(){
navigation.zoomToNextExtent();
}
function zoomToFull(){
mainMap.setExtent(new esri.geometry.Extent(-116.5,30.8,-107.2,37.9));
}