cmv / cmv-app

CMV - The Configurable Map Viewer - A community supported open source mapping framework built with the Esri JavaScript API and the Dojo Toolkit
https://demo.cmv.io/
MIT License
325 stars 278 forks source link

Search widget help - Feature layer #771

Closed gisnovice closed 7 years ago

gisnovice commented 7 years ago

If I am try to put a featureLayer into the search bar would I do the following for viewer.js?

define([
    'esri/units',
    'esri/geometry/Extent',
    'esri/config',
    'esri/dijit/Search',
    /*'esri/urlUtils',*/
    'esri/tasks/GeometryService',
    'esri/layers/ImageParameters',
    'gis/plugins/Google',
    'dojo/i18n!./nls/main',
    'dojo/topic',
    'dojo/sniff'
], function (units, Extent, esriConfig, Search, /*urlUtils,*/ GeometryService, ImageParameters, GoogleMapsLoader, i18n, topic, has) {

    var sources = ({
        featureLayer: new FeatureLayer("http://gis.ci.oceanside.ca.us/gis/rest/services/WebService/Planning/MapServer/2"),
        searchFields: ["APN"],
        suggestionTemplate: "${APN}",
        exactMatch: false,
        name: "APN",
        outFields: ["*"],
        placeholder: "Search for APN",
        maxResults: 4,
        maxSuggestions: 3,
        enableSuggestions: false,
        minCharacters: 2
    });
green3g commented 7 years ago

I have a file config/search.js where I put all this:

define([
    'esri/tasks/locator',
    'esri/layers/FeatureLayer',
    'esri/InfoTemplate',
    'dojo/has'
], function (Locator, FeatureLayer, InfoTemplate, has) {

    return {
        map: true,
        mapRightClickMenu: true,
        enableInfoWindow: true,
        enableButtonMode: has('mobile') ? false: true,
        expanded: true,
        allPlaceholder: 'Find an address',
        sources: [{
            placeholder: 'Find an address',
            locator: new Locator('//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer'),
            singleLineFieldName: 'SingleLine',
            outFields: ['Addr_type'],
            name: 'Property Search',
            localSearchOptions: {
                minScale: 300000,
                distance: 50000
            }
        }, {
            featureLayer: new FeatureLayer('/arcgis/rest/services/internal/assets/MapServer/12', {
                outFields: ['cid', 'Shape', 'OBJECTID']
            }),
            outFields: ['cid'],
            searchFields: ['cid'],
            suggestionTemplate: 'Structure Number: ${cid}',
            exactMatch: false,
            name: 'Storm Structure ID',
            placeholder: 'Structure ID',
            maxResults: 6,
            maxSuggestions: 6,
            enableSuggestions: true,
            minCharacters: 0,
            localSearchOptions: {distance: 5000},
            infoTemplate: new InfoTemplate('Structure Found', 'ID: ${cid}')
        },
//.........

and in viewer.js my search widget options: 'config/search'

tmcgee commented 7 years ago

@roemhildtg uses the same approach I take for my applications.

gisnovice commented 7 years ago

@roemhildtg Thanks for code, but now for the search bar I have the default suggestions, but it does not geolocate the information I enter.

viewer.js/search widget

            search: {
                include: true,
                type: has('phone') ? 'titlePane' : 'ui',
                path: 'esri/dijit/Search',
                placeAt: has('phone') ? null : 'top-center',
                title: i18n.viewer.widgets.search,
                iconClass: 'fa-search',
                position: 0,
                options: 'config/search'
            },

and I modified the seach.js, with esri/dijit/Search and it seamed to solve what I needed.

define([
    'esri/tasks/locator',
    'esri/dijit/Search',
    'esri/layers/FeatureLayer',
    'esri/InfoTemplate',
    'dojo/has'
], function (Locator, Search, FeatureLayer, InfoTemplate, has) {

    return {
        map: true,
        mapRightClickMenu: true,
        enableInfoWindow: true,
        enableButtonMode: has('mobile') ? false: true,
        expanded: true,
        allPlaceholder: 'Find an address or APN',
        sources: [{
            placeholder: 'Find an address',
            locator: new Locator('http://gis.ci.oceanside.ca.us/gis/rest/services/AddressLocator_Composite2016/GeocodeServer'),
            singleLineFieldName: 'SingleLine',
            outFields: ['Loc_name'],
            name: 'Address Search',
            localSearchOptions: {
                minScale: 300000,
                distance: 50000
            }
        }, {
            featureLayer: new FeatureLayer('http://gis.ci.oceanside.ca.us/gis/rest/services/WebService/Planning/MapServer/3'),
            searchFields: ["APN"],
            displayField: "APN",
            exactMatch: false,
            name: "Assessor's Parcel Number",
            outFields: ['*'],
            placeholder: 'APN - ex 1470950400',
            maxResults: 6,
            maxSuggestions: 6,
            enableSuggestions: true,
            minCharacters: 0,
            localSearchOptions: { distance: 5000 },
            infoTemplate: new InfoTemplate('APNs Found', 'ID: ${APN}')
        }]
    }
})