Created
March 11, 2016 19:02
-
-
Save kflaw/72fdf6ebe6d30b9df51c to your computer and use it in GitHub Desktop.
postmileSearch widget
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
define([ | |
'dojo/_base/declare', | |
'dijit/_WidgetBase', | |
'dijit/_TemplatedMixin', | |
'dijit/_WidgetsInTemplateMixin', | |
'gis/dijit/_FloatingWidgetMixin', | |
'dijit/form/Button', | |
'dojo/_base/lang', | |
'dojo/_base/array', | |
'dojo/dom', | |
'dojo/domReady!', | |
'dojo/on', | |
'dojo/text!./PostmileSearch/templates/PostmileSearch_test.html', | |
'xstyle/css!./PostmileSearch/css/PostmileSearch_test.css', | |
'dojo/dom-construct', | |
'dijit/form/FilteringSelect', | |
'dijit/form/Select', | |
'dijit/Dialog', | |
'esri/geometry/Point', | |
'esri/SpatialReference', | |
'esri/geometry/Extent', | |
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _FloatingWidgetMixin, Button, lang, arrayUtils, dom, ready, on, template, | |
css, domConstruct, FilteringSelect, Select, Dialog, Point, SpatialReference, Extent | |
) { | |
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _FloatingWidgetMixin], { | |
name: 'PostmileSearch', | |
map: true, | |
widgetsInTemplate: true, | |
templateString: template, | |
mapClickMode: null, | |
baseClass: 'pmSearchWidget', | |
html: '<a href="#">Search for Postmile</a>', | |
title: "Search for Postmile", | |
domTarget: 'postmileSearchWidget', | |
postCreate: function(){ | |
this.inherited(arguments); | |
map = this.map; | |
if (!this.parentWidget.toggleable) { | |
this.parentWidget.draggable = this.draggable; | |
var pmLink = domConstruct.place(this.html, this.domTarget); | |
on(pmLink, 'click', lang.hitch(this.pmDialog, 'show')); | |
} | |
// this.initTrace(); | |
}, | |
showPMdialog: function(){ | |
this.pmDialog.show(); | |
}, | |
closePMdialog: function() { | |
this.pmDialog.hide(); | |
}, | |
clearForm: function(){ | |
this.rte.reset(); | |
this.rtesffx.reset(); | |
this.cnty1.reset(); | |
this.cnty2.reset(); | |
this.pmPrefix1.reset(); | |
this.pmPrefix2.reset(); | |
this.pmile1.reset(); | |
this.pmile2.reset(); | |
this.alignmnt1.reset(); | |
this.alignmnt2.reset(); | |
}, | |
populate: function (){ | |
var c1 = this.cnty1; | |
var c2 = this.cnty2; | |
var r = this.rte; | |
r.innerHTML = ''; | |
if(c1.value == 'ALA'){ | |
var optionArray = ['13', '24', '61', '77', '80', '84', '92', '112', '123', '185','205', '238', '260', '262', '580', '680', '880', '980']; | |
} | |
else if(c1.value == 'CC'){ | |
var optionArray = ['4', '24', '80', '123', '160', '242', '580', '680']; | |
} | |
else if(c1.value == 'MRN'){ | |
var optionArray = ['1', '37', '101', '131', '580']; | |
} | |
else if (c1.value == 'NAP'){ | |
var optionArray = ['12', '29', '80', '121', '128', '221']; | |
} | |
else if (c1.value == 'SF'){ | |
var optionArray = ['1', '35', '80', '82', '101', '280']; | |
} | |
else if (c1.value == 'SM'){ | |
var optionArray = ['1', '9', '35', '82', '84', '92', '101', '109', '114', '280', '380']; | |
} | |
else if (c1.value == 'SCL'){ | |
var optionArray = ['9', '17', '25', '35', '82', '85', '87', '101', '130', '152', '156', '237', '280', '680', '880']; | |
} | |
else if (c1.value == 'SOL'){ | |
var optionArray = ['12', '29', '37', '80', '84', '113', '128', '220', '505', '680', '780']; | |
} | |
else if (c1.value == 'SON'){ | |
var optionArray = ['1', '12', '37', '101', '116', '121', '128']; | |
} | |
else if (c1.value == "" && c2.value == ''){ | |
var optionArray = [' ']; | |
} | |
r.removeOption(r.getOptions()); | |
// } | |
for(var option in optionArray){ | |
//s2.removeOption() | |
var listRoute = optionArray[option]; | |
//domConstruct.create("option",{value: listRoute, innerHTML: listRoute},s2); | |
var newOption = domConstruct.create("option"); | |
newOption.value = listRoute; | |
newOption.innerHTML = listRoute; | |
r.addOption(newOption); | |
} | |
}, | |
getLatLong: function () { | |
if (this.pmile1.value != '' && this.pmile2.value == ''){ | |
//var outputDiv = document.getElementById('latLongResult'); | |
var req = new validatorRequest(); | |
var pm = new postmile(); | |
pm.routeNumber = this.rte.value; | |
pm.routeSuffixCode = this.rtesffx.value; | |
pm.countyCode = this.cnty1.value; | |
pm.postmilePrefixCode = this.pmPrefix1.value; | |
pm.postmileValue = this.pmile1.value; | |
pm.alignmentCode = this.alignmnt1.value; | |
var opt = new validatorOptions(); | |
opt.tolerance=0.1; | |
req.postmile = pm; | |
req.options = opt; | |
var ws = new GISWebServiceSoapImp(); | |
var res = ws.validatePostmile(req); | |
var pmLL = new postmile(); | |
pmLL.routeNumber = this.rte.value; | |
pmLL.routeSuffixCode = this.rtesffx.value; | |
pmLL.countyCode = this.cnty1.value; | |
pmLL.postmilePrefixCode = this.pmPrefix1.value; | |
pmLL.postmileValue = this.pmile1.value; | |
pmLL.alignmentCode = this.alignmnt1.value; | |
var optionsLL = new pmOptions(); | |
optionsLL.alignmentType=0; //centerline | |
if (pmLL.alignmentCode == 'L') | |
optionsLL.alignmentType=2; | |
if (pmLL.alignmentCode == 'R') | |
optionsLL.alignmentType=3; | |
optionsLL.effectiveDate=null; | |
optionsLL.offsetDistance=0.0; | |
var reqLL = new pmRequest(); | |
reqLL.postmile = pmLL; | |
reqLL.options = optionsLL; | |
var wsLL = new GISWebServiceSoapImp(); | |
var resLL = wsLL.getCoordinatesForPostmile(reqLL); | |
if (resLL.pointGeometry){ | |
console.log(reqLL); | |
console.log(resLL); | |
var pt = resLL.pointGeometry; | |
console.log(pt.x); | |
console.log(pt.y); | |
map.centerAndZoom([pt.x,pt.y],17); | |
clearForm(); | |
// this.rte.reset(); | |
// this.rtesffx.reset(); | |
// this.cnty1.reset(); | |
// this.cnty2.reset(); | |
// this.pmPrefix1.reset(); | |
// this.pmPrefix2.reset(); | |
// this.pmile1.reset(); | |
// this.pmile2.reset(); | |
// this.alignmnt1.reset(); | |
// this.alignmnt2.reset(); | |
this.pmDialog.hide(); | |
} | |
else if (res !== null && resLL.pointGeometry == null && res.candidates.length > 0) { | |
var cand = res.candidates[0].postmile; | |
var candAlgnCode = cand.alignmentCode; | |
var candCnty = cand.countyCode; | |
var candPMprefix = cand.postmilePrefixCode; | |
var candPMvalue = cand.postmileValue; | |
var candRteNum = cand.routeNumber; | |
var candRteSffx = cand.routeSuffixCode; | |
if (candPMprefix == null){ | |
candPMprefix = ""; | |
} | |
if (candRteSffx == null){ | |
candRteSffx = ""; | |
} | |
if (candAlgnCode == null){ | |
candAlgnCode = ""; | |
} | |
console.log(candRteSffx); | |
if (candRteSffx == "" && candPMprefix !== ""){ | |
msg = confirm('Did you mean '+ candCnty +' '+ candRteNum +' '+ candPMprefix+' '+ candPMvalue) | |
} | |
if (candRteSffx =="" && candPMprefix =="") { | |
msg = confirm('Did you mean '+ candCnty +' '+ candRteNum +' '+ candPMvalue) | |
} | |
if (candRteSffx !== "" && candPMprefix == "") { | |
msg = confirm('Did you mean '+ candCnty +' '+ candRteNum +' '+ candPMprefix+' '+ candPMvalue + ' '+ candRteSffx) | |
} | |
if (msg){ | |
var pmCand = new postmile(); | |
pmCand.routeNumber = candRteNum; | |
pmCand.routeSuffixCode = candRteSffx; | |
pmCand.countyCode = candCnty; | |
pmCand.postmilePrefixCode = candPMprefix; | |
pmCand.postmileValue = candPMvalue; | |
pmCand.alignmentCode = candAlgnCode; | |
var optionsCand= new pmOptions(); | |
optionsCand.alignmentType=0; //centerline | |
optionsCand.effectiveDate=null; | |
optionsCand.offsetDistance=0.0; | |
var reqCand = new pmRequest(); | |
reqCand.postmile = pmCand; | |
reqCand.options = optionsCand; | |
var wsCand = new GISWebServiceSoapImp(); | |
var resCand = wsCand.getCoordinatesForPostmile(reqCand); | |
console.log(reqCand); | |
console.log(resCand); | |
var ptCand = resCand.pointGeometry; | |
// console.log(ptCand.x); | |
// console.log(ptCand.y); | |
map.centerAndZoom([ptCand.x,ptCand.y],17); | |
clearForm(); | |
// this.rte.reset(); | |
// this.rtesffx.reset(); | |
// this.cnty.reset(); | |
// this.pmPrefix1.reset(); | |
// this.pmile1.reset(); | |
// this.pmile2.reset(); | |
// this.alignmnt.reset(); | |
this.pmDialog.hide(); | |
} | |
} | |
else{ | |
alert('Postmile can\'t be found'); | |
} | |
} | |
else if (this.pmile1 == ''){ | |
alert('You must enter a postmile value'); | |
} | |
else if (this.pmile1 != '' && pmile2 != ''){ | |
var pmFrom = new postmile(); | |
pmFrom.routeNumber = this.rte.value; | |
pmFrom.routeSuffixCode = document.InputCoordinates.OutputRouteSuffix1.value; | |
pmFrom.countyCode = document.InputCoordinates.OutputCounty1.value; | |
pmFrom.postmilePrefixCode = document.InputCoordinates.OutputPostmilePrefix1.value; | |
pmFrom.postmileValue = document.InputCoordinates.OutputPostmile1.value; | |
pmFrom.alignmentCode = document.InputCoordinates.OutputAlignment1.value; | |
var pmTo = new postmile(); | |
pmTo.routeNumber = document.InputCoordinates.OutputRoute1.value; | |
pmTo.routeSuffixCode = document.InputCoordinates.OutputRouteSuffix1.value; | |
pmTo.countyCode = document.InputCoordinates.OutputCounty2.value; | |
pmTo.postmilePrefixCode = document.InputCoordinates.OutputPostmilePrefix2.value; | |
pmTo.postmileValue = document.InputCoordinates.OutputPostmile2.value; | |
pmTo.alignmentCode = document.InputCoordinates.OutputAlignment2.value; | |
var pp = new postmilePair(); | |
pp.routeNumber = document.InputCoordinates.OutputRoute1.value; | |
pp.routeSuffixCode = document.InputCoordinates.OutputRouteSuffix1.value; | |
pp.fromPostmile = pmFrom; | |
pp.toPostmile = pmTo; | |
var options = new validatorOptions(); | |
options.effectiveDate=null; | |
options.tolerance=0.1; | |
var req = new validatorRequest(); | |
req.postmilePair = pp; | |
req.options = options; | |
var ws = new GISWebServiceSoapImp(); | |
var res = ws.validatePostmilePair(req); | |
} | |
// getLL = lang.htich(this,function(){ | |
// var pt = resCand.pointGeometry; | |
// console.log(pt.x); | |
// console.log(pt.y); | |
// map.centerAndZoom([pt.x,pt.y],17); | |
// this.rte.reset(); | |
// this.rtesffx.reset(); | |
// this.cnty.reset(); | |
// this.pmPrefix.reset(); | |
// this.pmile.reset(); | |
// this.alignmnt.reset(); | |
// this.pmDialog.hide(); | |
// } | |
// ); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for all the helpful comments!