I'm publishing data from the Search widget and was wondering if the eSearch can grab those results and populate the Results tab based on one of the config searches I have. I wouldn't need it to create another graphic in this case becasue the Search is already doing that.
Solved! Go to Solution.
Martin,
What I do on my site is in the Search widget.js I publish the search widgets results like this:
_onSelectResult: function(e) {
....
// publish select result to other widgets
this.publishData({
'selectResult': e
});
//Dispatch event to have eSearch search for this geometry.
this.publishData({
'target': 'eSearch',
'feature': result.feature
});
},
Then in the eSearch:
onReceiveData: function(widgetName, WidgetId, data){
if(data.message && data.message === "Deactivate_DrawTool"){
this.drawBox.deactivate();
}
if(data && data.target && data.target === 'eSearch'){
if(data.feature.geometry.type === "polygon"){
this.search(data.feature.geometry.getCentroid(), 0);
}else{
this.search(data.feature.geometry, 0);
}
}
},
Martin,
What I do on my site is in the Search widget.js I publish the search widgets results like this:
_onSelectResult: function(e) {
....
// publish select result to other widgets
this.publishData({
'selectResult': e
});
//Dispatch event to have eSearch search for this geometry.
this.publishData({
'target': 'eSearch',
'feature': result.feature
});
},
Then in the eSearch:
onReceiveData: function(widgetName, WidgetId, data){
if(data.message && data.message === "Deactivate_DrawTool"){
this.drawBox.deactivate();
}
if(data && data.target && data.target === 'eSearch'){
if(data.feature.geometry.type === "polygon"){
this.search(data.feature.geometry.getCentroid(), 0);
}else{
this.search(data.feature.geometry, 0);
}
}
},
That worked perfect! Thank you!
I have noticed an issue with the .getCentoid approach if the centoid falls outside of the polygon due to an irregular shape it return reults from the other shape. Is there a way to force it to always be inside the original polygon shape that is seached on?
Martin,
That is going to be a bit more difficult.
onReceiveData: function(widgetName, WidgetId, data){
if(data.message && data.message === "Deactivate_DrawTool"){
this.drawBox.deactivate();
}
if(data && data.target && data.target === 'eSearch'){
if(data.feature.geometry.type === "polygon"){
esriConfig.defaults.geometryService.labelPoints([data.feature.geometry], lang.hitch(this, function(labelPoint) {
this.search(labelPoint, 0);
});
}else{
this.search(data.feature.geometry, 0);
}
}
},
That seems like it's really close it zooms to the correct extent to select the polygon geometry but the results in the eSeach just say searching with the progress bar and receive this in the console:
TypeError: d.spatialReference is undefine.
OK try:
onReceiveData: function(widgetName, WidgetId, data){
if(data.message && data.message === "Deactivate_DrawTool"){
this.drawBox.deactivate();
}
if(data && data.target && data.target === 'eSearch'){
if(data.feature.geometry.type === "polygon"){
esriConfig.defaults.geometryService.labelPoints([data.feature.geometry], lang.hitch(this, function(labelPoint) {
this.search(labelPoint[0], 0);
}));
}else{
this.search(data.feature.geometry, 0);
}
}
},
Worked like a charm. Thanks Robert!