findTask.js 1.42 KB
import {loadModules} from 'esri-loader'

export default {

    methods:{
      /**
       * @description: findByPro
       * @param {*} url
       * @param {*} layerIds
       * @param {*} searchFields
       * @param {*} searchText
       * @param {*} returnGeometry
       * @param {*} callBackFunction
       * @author: renchao
       */
        findByPro(url,layerIds,searchFields,searchText,returnGeometry,callBackFunction){
            loadModules([
                "esri/tasks/FindTask",
                "esri/tasks/support/FindParameters"
            ]).then(([
                         FindTask,
                         FindParameters
                     ]) => {
                var findTask = new FindTask({
                        url:url
                    }),
                    findParameters = new FindParameters();
                findParameters.returnGeometry = returnGeometry ? returnGeometry : false;
                findParameters.layerIds = layerIds;
                findParameters.searchFields = searchFields;
                findParameters.searchText = searchText;
				findParameters.outSpatialReference  = {wkid:3857};
                findTask.execute(findParameters).then(function (result) {
                    if(callBackFunction){
                        callBackFunction(result);
                    }
                });
            }).catch(err => {
                throw (err);
            })

        }

    }
}