diff --git a/viewer/js/gis/dijit/Find.js b/viewer/js/gis/dijit/Find.js index 57d00559a..7ce59e45f 100644 --- a/viewer/js/gis/dijit/Find.js +++ b/viewer/js/gis/dijit/Find.js @@ -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: { @@ -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; @@ -184,7 +199,7 @@ define([ findParams.contains = !this.containsSearchText.checked; findParams.outSpatialReference = { - wkid: this.outputSpatialReference + wkid: this.spatialReference }; this.findResultsNode.innerHTML = 'Searching...'; @@ -197,7 +212,7 @@ define([ createResultsGrid: function () { if (!this.resultsStore) { this.resultsStore = new Memory({ - idProperty: 'value', + idProperty: 'id', data: [] }); } @@ -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'; } @@ -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': @@ -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); } @@ -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) {