Skip to content

Commit

Permalink
Merge pull request #114 from DavidSpriggs/bug/find-widget-highlight-u…
Browse files Browse the repository at this point in the history
…nique-features

add unique id to each result / fine tune spatial reference
  • Loading branch information
tmcgee committed Jul 11, 2014
2 parents 5b17834 + 8a83568 commit e3a738d
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions viewer/js/gis/dijit/Find.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ define([
templateString: FindTemplate,
baseClass: 'gis_FindDijit',

// default Spatial Reference
outputSpatialReference: 4326,
// Spatial Reference. uses the map's spatial reference if none provided
spatialReference: null,

// Use 0.0001 for decimal degrees (wkid 4326)
// or 500 for meters/feet
pointExtentSize: null,

// default symbology for found features
defaultSymbols: {
Expand Down Expand Up @@ -79,6 +83,17 @@ define([
postCreate: function () {
this.inherited(arguments);

if (this.spatialReference === null) {
this.spatialReference = this.map.spatialReference.wkid;
}
if (this.pointExtentSize === null) {
if (this.spatialReference === 4326) { // special case for geographic lat/lng
this.pointExtentSize = 0.0001;
} else {
this.pointExtentSize = 500; // could be feet or meters
}
}

var pointSymbol = null, polylineSymbol = null, polygonSymbol = null;
var pointRenderer = null, polylineRenderer = null, polygonRenderer = null;

Expand Down Expand Up @@ -184,7 +199,7 @@ define([
findParams.contains = !this.containsSearchText.checked;

findParams.outSpatialReference = {
wkid: this.outputSpatialReference
wkid: this.spatialReference
};

this.findResultsNode.innerHTML = 'Searching...';
Expand All @@ -197,7 +212,7 @@ define([
createResultsGrid: function () {
if (!this.resultsStore) {
this.resultsStore = new Memory({
idProperty: 'value',
idProperty: 'id',
data: []
});
}
Expand Down Expand Up @@ -235,8 +250,8 @@ define([
if (this.results.length > 0) {
var s = (this.results.length === 1) ? '' : 's';
resultText = this.results.length + ' Result' + s + ' Found';
this.showResultsGrid();
this.highlightFeatures();
this.showResultsGrid();
} else {
resultText = 'No Results Found';
}
Expand All @@ -261,7 +276,11 @@ define([
},

highlightFeatures: function () {
var unique = 0;
array.forEach(this.results, function (result) {
// add a unique key for the store
result.id = unique;
unique++;
var graphic, feature = result.feature;
switch (feature.geometry.type) {
case 'point':
Expand Down Expand Up @@ -314,12 +333,11 @@ define([

// zoom to feature
if (result.length) {
var data = result[result.length - 1].data;
var data = result[0].data;
if (data) {
var feature = data.feature;
if (feature) {
var extent = feature.geometry.getExtent();
console.log(feature);
if (!extent && feature.geometry.type === 'point') {
extent = this.getExtentFromPoint(feature);
}
Expand Down Expand Up @@ -371,9 +389,18 @@ define([
},

getExtentFromPoint: function (point) {
var factor = 0.0001; // hack: 0.0001 of a decimal degree
var sz = this.pointExtentSize; // hack
var pt = point.geometry;
return new Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.SpatialReference);
var extent = new Extent({
'xmin': pt.x - sz,
'ymin': pt.y - sz,
'xmax': pt.x + sz,
'ymax': pt.y + sz,
'spatialReference': {
wkid: this.spatialReference
}
});
return extent;
},

_onQueryChange: function (queryIdx) {
Expand Down

0 comments on commit e3a738d

Please sign in to comment.