Robert Scheitlin, GISP has created the eSearch widget. It has URL parameters. With this ability I can generate a URL that allows my clients / customers to visit a webmap that is cued up to exactly what I want them to see. Except I need to offer them a 'current year' URL and that wasn't an option with eSearch "out-of-the-box" so after working with Robert I was able to introduce some modified code that gave me what I wanted.
//now check if there is a url search to do
var myObject = this.getUrlParams();
if (myObject.esearch) {
if(myObject.esearch === "curmonth"){
var today = new Date();
today.setDate(1);
var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd');
myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd');
console.info(myObject.esearch);
}
if(myObject.esearch === "curyear"){
var today = new Date();
today.setDate(1);
var thisYearStr = this._formatDate(today.getTime(), 'yyyy');
myObject.esearch = this._formatDate(Date(thisYearStr), 'yyyy');
console.info(myObject.esearch);
}
if(this.config.layers[myObject.slayer].expressions.expression.length > 0){
var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value);
var values = myObject.esearch.split("|");
array.forEach(values, lang.hitch(this, function(val, index){
if (val.indexOf('~') > -1){
var ranges = val.split("~");
valuesObj1[index].valueObj.value1 = ranges[0];
valuesObj1[index].valueObj.value2 = ranges[1];
}else{
valuesObj1[index].valueObj.value = val;
}
}));
html.empty(this.textsearchlabel);
html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel);
this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url,
this.config.layers[myObject.slayer].definitionexpression);
this.selectLayerAttribute.set('value', myObject.slayer);
on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () {
this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false);
}));
}
This adds a 'Current Month' (curmonth) option and a 'Current Year' (curyear) option to the URL Parameters.
However, it just stopped working and I wonder if anyone has any ideas?
The map can be viewed at the custom URL: City of Tulsa, Tulsa Police Department, Methlabs Web Map
This map is in our sandbox area so it won't be there once I get this figured out. But for now, I'm getting zilch returns on the custom URL.
Solved! Go to Solution.
So it appears that if the query is based off of a unique field from a large dataset that has to take a moment to query, then the URL parameters don't work. at. all.
I set up "Pre-Defined" for the Year field, and put in each year, and it works fine... but when it was a Unique field and it had to query them all? It wouldn't work.
SO... it works now.
So it appears that if the query is based off of a unique field from a large dataset that has to take a moment to query, then the URL parameters don't work. at. all.
I set up "Pre-Defined" for the Year field, and put in each year, and it works fine... but when it was a Unique field and it had to query them all? It wouldn't work.
SO... it works now.
Brian,
In the latest version I did some work for just such a use case ( I'm pretty sure). Where I wait until after the unique values are returned before executing the URL query. Also I built in the code that I worked with you on into the eSearch widget permanently. You can see the help page for details on the exact URL search parameter key word for date that were added.
I started my first widget yesterday rscheitlin, so I'm hoping to start digging in and giving you a run for your money. lol