Select to view content in your preferred language

Passing an address to the search

686
2
11-29-2011 05:39 AM
deleted-user-FYWnb7WVNuhY
Deactivated User
I am looking for a way to pass an address automatically to the search box of my arcgis.com webapp.  Something like a Get Request or a Post...  I built the webapp with the Basic Viewer seen in the attached picture.  I host it on my own server because I want to use our locators not the ESRI world locators.

The goal is to have a user in another program click a search button on an address, that click would launch the users internet browser and the arcgis.com website.  It would pass the address to the webapp and zoom into it.

Any Ideas?
Tags (2)
0 Kudos
2 Replies
KellyHutchins
Esri Notable Contributor
You could modify the basic viewer template to accept an address as a url parameter. There are a few ways to accomplish this but here's one.

Open layout.js and replace the createSearchTool function with this one.
function createSearchTool(){
     //add the toolbar section that holds the search tool
    var wrapperDiv = dojo.create('div',{
      id:'searchWrapper'
    },dojo.byId('webmap-toolbar-right'));
    dojo.addClass('searchWrapper','searchwrapper');
    var searchInput = dojo.create('input',{
      id:'searchField',
      type:'text',
      placeholder: i18n.tools.search.title,
      onkeydown: function(e) {
        if(e.keyCode === 13){
          findLocation();
        }
      }
    },wrapperDiv);
    dojo.addClass(dojo.byId('searchField'),'searchbox');
    
    dojo.create('input',{
      type:'image',
      id:'blankImage',
      src:'images/blank.gif'
    },wrapperDiv);
    dojo.connect(dojo.byId('blankImage'),'onclick',function(){
      findLocation();
    });
    dojo.addClass(dojo.byId('blankImage'),'searchbutton');
    
  //add placeholder for browsers that don't support (IE)
  if (!supportsPlaceholder()) {
    var search = dojo.byId("searchField");
    var text_content = i18n.tools.search.title;

    search.style.color = "gray";
    search.value = text_content;

    search.onfocus = function () {
      if (this.style.color === "gray") {
        this.value = "";
        this.style.color = "black";
      }
    };

    search.onblur = function () {
      if (this.value === "") {
        this.style.color = "gray";
        this.value = text_content;
      }
    };
  }

//if there were url params zoom to them
   if(urlObject.query && urlObject.query.address){
    dojo.byId('searchField').value = urlObject.query.address;
    findLocation();
   }  
 }



Then you can add an address to the url and the app should zoom to that location. You may have to modify the code if your locator doesn't accept single address input:

http://localhost/Template/test/basicviewer/index.html?address=380 new York st Redlands CA
0 Kudos
deleted-user-FYWnb7WVNuhY
Deactivated User
Thank you Kelly, that worked like a charm.  Just had to switch the place holders and insert

//if there were url params zoom to them
   if(urlObject.query && urlObject.query.address){
    dojo.byId('searchField').value = urlObject.query.address;
    findLocation();

into what the templet already had and it worked like a champ!  Thank you!
0 Kudos