eSearch Related : Custom Query for Current Month

2409
10
Jump to solution
05-24-2016 08:30 AM
BrianO_keefe
Occasional Contributor III


Using the eSearch widget by Robert Scheitlin, GISP​ I am wondering if anyone has come up with a method, through the URL Parameters, to generate a query that would show the 'Current' Day/Month/Year.

I am developing a Crimes map, and it needs to load with the current Month's crimes (not the last 30 days, altho if that's an option I'm open to that as well). If there is any option to make this happen I would love to hear it.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Brian,

  OK there is nothing that can take just some value like this month in the url param. Currently it is like I said to do a date range search you do:

?esearch=2016-05-01~2016-05-24&slayer=2&exprnum=0

But you could modify the Widget.js to allow this:

Find this code area looking for the following three lines:

//now check if there is a url search to do

            var myObject = this.getUrlParams();

            if (myObject.esearch) {

and make it:

//now check if there is a url search to do

            var myObject = this.getUrlParams();

            if (myObject.esearch) {

              if(myObject.esearch === "thismonth"){

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

              }

and do this in the url:

esearch=thismonth&slayer=2&exprnum=0

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Brain,

  I am a little confused. Any url that is not the default website url would mean that you have to provide the custom url to your users to click on some link or send to them in some form, unless you are teaching them how to use url parameters. If this is the case then you can easily do the date math yourself for the date range to use in the url parameter. Here is an example:

?esearch=2014-11-10~2014-11-17&slayer=2&exprnum=0. If I am missing your question or goal please inform me.

0 Kudos
BrianO_keefe
Occasional Contributor III

Anyone reaching the Crime map will come from a URL provided by the City.

So if I have my URL like so: http://point.to.map.com/?esearch=parameters-that-equal-current-month then I can setup our Map Gallery or the provided links so that they all point to the URL parameter version.

This allows me to have the map load and show all data relevant to just the current month (regardless of which month) and then I can have a SINGLE rest service rather than REST Service 1 = Current Year / REST Service 2 = Current Month.

This allows me to (also) have the data onscreen disappear the instant a new search is generated. I have police officers testing this map that don't understand why the dots stay on the screen after a search. AND they will turn on the Current Year layer and wonder why some dots are overlapping. I am going to extrapolate that citizens will be equally confused.

The eSearch with it's URL parameter allows me a map that loads showing JUST the data I want. AND it's data that disappears at the first search.

If there was a way to "easily" trigger disabling a Layer on a map upon search, that would be just as good.

I hope this makes sense.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brian,

  OK there is nothing that can take just some value like this month in the url param. Currently it is like I said to do a date range search you do:

?esearch=2016-05-01~2016-05-24&slayer=2&exprnum=0

But you could modify the Widget.js to allow this:

Find this code area looking for the following three lines:

//now check if there is a url search to do

            var myObject = this.getUrlParams();

            if (myObject.esearch) {

and make it:

//now check if there is a url search to do

            var myObject = this.getUrlParams();

            if (myObject.esearch) {

              if(myObject.esearch === "thismonth"){

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

              }

and do this in the url:

esearch=thismonth&slayer=2&exprnum=0

BrianO_keefe
Occasional Contributor III

Ok... I'm getting a weird error...

Here is my code:

//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);
  } else {
  this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false);
  this.publishData({
  message : myObject.slayer
  });
  }
  else {
  //init the first available layers paramsDijit
  var aIndex = options[0].value;
  //console.info(options[0].label);
  this.AttributeLayerIndex = aIndex;
  this._initSelectedLayerExpressions();
  var valuesObj = lang.clone(this.config.layers[aIndex].expressions.expression[0].values.value);
  this.paramsDijit.build(valuesObj, this.resultLayers[aIndex], this.config.layers[aIndex].url, this.config.layers[aIndex].definitionexpression);
  if (this.config.layers[aIndex].sumfield) {
  html.addClass(this.list.domNode, 'sum');
  html.setStyle(this.divSum, 'display', '');
  } else {
  html.removeClass(this.list.domNode, 'sum');
  html.setStyle(this.divSum, 'display', 'none');
  }
  }
}

Can you see anything wrong with this? It's buggin.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brain,

  What version of the widget are you using? It appears you are on an older version.

0 Kudos
BrianO_keefe
Occasional Contributor III

Ok. I updated everything, made the adjustments, and here is what I am getting.

init.js:199 TypeError: Cannot read property 'expressions' of undefined(…) "TypeError: Cannot read property 'expressions' of undefined
    at .<anonymous> (http://maps.cityoftulsa.org/sandbox/crimes/widgets/eSearch/Widget.js:966:53)
    at http://js.arcgis.com/3.16/init.js:167:296
    at k (http://js.arcgis.com/3.16/init.js:189:431)
    at q (http://js.arcgis.com/3.16/init.js:189:357)
    at resolve (http://js.arcgis.com/3.16/init.js:191:441)
    at http://js.arcgis.com/3.16/init.js:949:56
    at k (http://js.arcgis.com/3.16/init.js:189:431)
    at q (http://js.arcgis.com/3.16/init.js:189:357)
    at resolve (http://js.arcgis.com/3.16/init.js:191:441)
    at k (http://js.arcgis.com/3.16/init.js:189:431)
    ----------------------------------------
    rejected at a (http://js.arcgis.com/3.16/init.js:190:337)
    at k (http://js.arcgis.com/3.16/init.js:190:89)
    at q (http://js.arcgis.com/3.16/init.js:189:357)
    at resolve (http://js.arcgis.com/3.16/init.js:191:441)
    at http://js.arcgis.com/3.16/init.js:949:56
    at k (http://js.arcgis.com/3.16/init.js:189:431)
    at q (http://js.arcgis.com/3.16/init.js:189:357)
    at resolve (http://js.arcgis.com/3.16/init.js:191:441)
    at k (http://js.arcgis.com/3.16/init.js:189:431)
    at q (http://js.arcgis.com/3.16/init.js:189:357)
    ----------------------------------------
Error
    at then.b.then (http://js.arcgis.com/3.16/init.js:192:253)
    at declare._initLayerSelect (http://maps.cityoftulsa.org/sandbox/crimes/widgets/eSearch/Widget.js:894:21)
    at declare.postCreate (http://maps.cityoftulsa.org/sandbox/crimes/widgets/eSearch/Widget.js:156:14)
    at h.create (http://js.arcgis.com/3.16/init.js:1281:207)
    at h.postscript (http://js.arcgis.com/3.16/init.js:1279:464)
    at new <anonymous> (http://js.arcgis.com/3.16/init.js:98:192)
    at declare.createWidget (http://maps.cityoftulsa.org/sandbox/crimes/jimu.js/WidgetManager.js:294:20)
    at .<anonymous> (http://maps.cityoftulsa.org/sandbox/crimes/jimu.js/WidgetManager.js:113:39)
    at http://js.arcgis.com/3.16/init.js:167:296
    at k (http://js.arcgis.com/3.16/init.js:189:431)"

I'm kinda lost. lol

Here is the URL to the actual map: ArcGIS Web Application

Just in case that helps.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brain,

  You only have one layer configured but you are telling the widget to use the 3rd layer based on your url parameters:

?esearch=curmonth&slayer=2&exprnum=0

You need to use:

?esearch=curmonth&slayer=0&exprnum=0

RobertScheitlin__GISP
MVP Emeritus

Looks like you need to add the "UCC_CODE" field to your search so that your symbols get rendered.

BrianO_keefe
Occasional Contributor III

Do you mean in the Widget.js somewhere or through the Widget Interface?

0 Kudos