Created
January 17, 2017 15:06
-
-
Save green3g/dfc8e46ae253268644520935f33d8a02 to your computer and use it in GitHub Desktop.
simple cmv widget to query parcels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the top of viewer.js add these in your define block... | |
// ORDER is important and function variables need to match the list | |
define([ | |
'esri/tasks/query', | |
'esri/tasks/QueryTask', | |
'esri/SpatialReference', | |
], function(Query, QueryTask, SpatialReference){ | |
.... | |
parcel_query: { | |
type: 'invisible', | |
id: 'parcel_query', | |
include: true, | |
path: 'dijit/_WidgetBase', | |
options: { | |
// tell cmv to include the map | |
map: true, | |
// when it starts up, look for a parcel id | |
startup: function() { | |
// change MAP_PARCEL to whatever you want your link to be www.mysite.com?MAP_PARCEL=13234234 | |
var parcelid = this.getParameterByName('MAP_PARCEL'); | |
if(parcelid){ | |
this.getFeature({ | |
url: '/arcgis/rest/services/ParcelService/MapServer', | |
id: parcelid | |
}).then(this.centerMap.bind(this)); | |
} | |
}, | |
getFeature: function (info) { | |
var task = new QueryTask(info.url); | |
var q = new Query(); | |
q.objectIds = [info.id]; | |
q.returnGeometry = true; | |
q.outSpatialReference = new SpatialReference(102100); | |
return task.execute(q); | |
}, | |
centerMap: function (result) { | |
var geom = result.features[0].geometry; | |
this.map.centerAt(geom); | |
}, | |
getParameterByName: function (name, url) { | |
if (!url) { | |
url = window.location.href; | |
} | |
name = name.replace(/[\[\]]/g, '\\$&'); | |
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | |
results = regex.exec(url); | |
if (!results) { | |
return null; | |
} | |
if (!results[2]) { | |
return ''; | |
} | |
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment