0

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: enter image description here

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));
}

1 Answer 1

0

the error : can't read property 'toJson' of null , exactely here means that the widget tries to convert the geometry to a json object and he cant resolve this field (geometry).

In your featureLayer search refered to the url service : http://arcgis-cabhp-1819518128.us-west-1.elb.amazonaws.com/arcgis/rest/services/HCIC/160411_interactive_map_jzz_v01/MapServer/0 it seems that you have some thing wrong with the Shape field :

shape fieald invisible

So i think , you have first to make your Shape field visible in the service then the search may work after .

Link may help you : how to make shape visible in map service

2
  • Agree! Probably it's because I turned that field off when I published the service. I will try to republish it and see if it works! Thank you buddy! Commented Apr 24, 2016 at 23:41
  • Hope it resolve your problem @DevilShankou Commented Apr 25, 2016 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.