= 0 ? 1 : 0)
}
function addBaseLayer(name) {
var exists = false;
for (var i = 0; i < map.layers.length; i++) {
if (map.layers[i].name == name) {
exists = true;
}
}
if (!exists) {
map.addLayer(lyrBase[name]);
}
}
function getElementsByTagNameNS(xmlDoc,nsUrl,nsTag,tag) {
// we have namespaces, and browsers treat them differently
if (document.getElementsByTagNameNS !== undefined) {
return xmlDoc.getElementsByTagNameNS(nsUrl,tag);
}
else {
return xmlDoc.getElementsByTagName(nsTag + ':' + tag);
}
}
function printSave() {
var l = {};
var leg = {};
var hits = 0;
pokeMap()
// go through all visible layers and pick out the base layer -- don't want it to be
// added to the end of the stack since it shows up as an activeLyr
for (var j = 0; j < map.layers.length; j++) {
if (map.layers[j].isBaseLayer && map.layers[j].grid && map.layers[j].visibility) {
var a = [];
for (tilerow in map.layers[j].grid) {
for (tilei in map.layers[j].grid[tilerow]) {
var tile = map.layers[j].grid[tilerow][tilei];
if (tile && tile.bounds) {
var url = map.layers[j].getURL(tile.bounds);
var position = tile.position;
a.push({
url : url
,x : position.x
,y : position.y
,opacity : map.layers[j].opacity
,grid : true
});
}
}
}
l[map.layers[j].name] = a;
hits++;
}
else if (map.layers[j].isBaseLayer && map.layers[j].DEFAULT_PARAMS && map.layers[j].visibility) {
l[map.layers[j].name] = [{
url : activeLyr[map.layers[j].name].getFullRequestString({})
,x : 0
,y : 0
,opacity : activeLyr[map.layers[j].name].opacity
}];
hits++;
}
}
// grab everything else
for (var j = 0; j < map.layers.length; j++) {
if (l[map.layers[j].name]) {
continue;
}
for (var i in activeLyr) {
if (map.layers[j].name == i && String(lyr2wms[i]).indexOf(featurePrefix + ':') == 0 && map.layers[j].visibility && scaleOK(i).isOK) {
l[i] = [{
url : activeLyr[i].getFullRequestString({})
,x : 0
,y : 0
,opacity : activeLyr[i].opacity
}];
hits++;
leg[i] = activeLyr[i].getFullRequestString({}).replace('GetMap','GetLegendGraphic').replace('LAYERS=','LAYER=');
}
else if (map.layers[j].name == i && map.layers[j].visibility && scaleOK(i).isOK && map.layers[j].grid) {
var a = [];
for (tilerow in map.layers[j].grid) {
for (tilei in map.layers[j].grid[tilerow]) {
var tile = map.layers[j].grid[tilerow][tilei];
if (tile && tile.bounds) {
var url = map.layers[j].getURL(tile.bounds);
var position = tile.position;
a.push({
url : url
,x : position.x
,y : position.y
,opacity : map.layers[j].opacity
,grid : true
});
}
}
}
l[i] = a;
leg[i] = '';
hits++;
}
}
}
if (hits > 0) {
YUI().use("io","json-parse","json-stringify",function(Y) {
var handleSuccess = function(ioId,o,args) {
Ext.MessageBox.hide();
var json = Y.JSON.parse(o.responseText);
Ext.Msg.buttonText.ok = 'Close';
Ext.Msg.alert('Map ready','Please click here to open a new window containing your map and legend as separate images. You can then either right-click each image and save them locally or use the browser print option to print the entire map.');
Ext.Msg.buttonText.ok = 'OK';
};
Y.on('io:success',handleSuccess,this,[]);
var scaleLineTop = getElementsByClassName('olControlScaleLineTop')[0];
var scaleLineBottom = getElementsByClassName('olControlScaleLineBottom')[0];
var cfg = {
method : 'POST'
,headers : {'Content-Type':'application/json'}
,data : Y.JSON.stringify({
w : map.div.style.width
,h : map.div.style.height
,extent : map.getExtent().toArray()
,layers : l
,legends : leg
,scaleLineTop : {w : scaleLineTop.style.width,val : scaleLineTop.innerHTML}
,scaleLineBottom : {w : scaleLineBottom.style.width,val : scaleLineBottom.innerHTML}
})
};
promptForTitle(cfg,Y);
});
}
else {
Ext.Msg.alert('Print/Save error','There are no active data layers to print.');
}
}
function promptForTitle(cfg,Y) {
Ext.MessageBox.prompt('Print/Save','Enter a title and click OK to print or save images of your map and legend.
Please note: Basemaps and external data layers will not be shown on the map image. If you would like to print or save a map with the basemap or external data layers, use the print option in your browser or capture a screenshot of the map.
Title:',function(btn,txt) {
if (btn == 'ok' && txt != '') {
Ext.MessageBox.show({
title : 'Assembling map'
,msg : 'Please wait...'
,progressText : 'Working...'
,width : 300
,wait : true
,waitConfig : {interval:200}
});
var request = Y.io('print.php?title=' + txt,cfg);
}
else if (btn == 'ok') {
promptForTitle(cfg,Y);
}
});
}
function launchExportWizard(aoi) {
var tstLyrStore = new Ext.data.ArrayStore({
fields : [
{name : 'ico' }
,{name : 'title'}
]
});
for (var j = map.layers.length - 1; j >= 0; j--) {
for (var i in activeLyr) {
if (map.layers[j].name == i && String(lyr2wms[i]).indexOf(featurePrefix + ':') == 0 && map.layers[j].visibility) {
// a normal find wasn't working properly, so loop through the list to keep dups out
var exists = false;
tstLyrStore.each(function(rec) {
exists = exists || rec.get('title') == activeLyr[i].name;
});
if (!exists) {
tstLyrStore.add(new tstLyrStore.recordType(
{ico : wms2ico[lyr2wms[activeLyr[i].name]],title : activeLyr[i].name}
,++tstLyrCount
));
}
}
}
}
var bboxLyrStore = new Ext.data.ArrayStore({
fields : [
{name : 'ico' }
,{name : 'title'}
,{name : 'bbox' }
,{name : 'wfs' }
,{name : 'busy' }
,{name : 'export'}
]
});
var bboxLyrCount = 0;
var downloadLyrStore = new Ext.data.ArrayStore({
fields : [
{name : 'ico' }
,{name : 'title'}
,{name : 'url' }
]
});
var wizGetData = new Ext.ux.Wiz({
title : 'Data export wizard'
,constrainHeader : true
,id : 'getDataWiz'
,headerConfig : {
title : ''
}
,width : 700
,height : 550 // 670
,resizable : true
,maximizable : true
,cardPanelConfig : {
defaults : {
border : false
,bodyStyle : 'padding:6px'
,labelWidth : 75
,autoScroll : true
}
}
,listeners : {finish : function() {
if (!mkzipCGI) {
Ext.Msg.alert('ZIP unavailable','Sorry, this functionality is currently unavailable.');
return;
}
downloadLyrStore.removeAll();
var downloadLyrCount = 0;
tstLyrStore.each(function(rec) {
var title = rec.get('title');
var ico = wms2ico[lyr2wms[title]];
if (bboxLyrStore.getAt(bboxLyrStore.find('title',rec.get('title'))).get('wfs').indexOf('> max') < 0 && bboxLyrStore.getAt(bboxLyrStore.find('title',rec.get('title'))).get('bbox') == 'Y' && bboxLyrStore.getAt(bboxLyrStore.find('title',rec.get('title'))).get('wfs') !== '0 feature(s)') {
downloadLyrStore.add(new downloadLyrStore.recordType(
{ico : ico,title : title,url : mkDataWizardURL(title,ico)}
,++downloadLyrCount
));
// add metadataUrl & everything for this layer for extractDoc
if (lyrMetadata[title].metadataUrl) {
downloadLyrStore.add(new downloadLyrStore.recordType(
{ico : 'NONE',title : ' ' + lyrMetadata[title].metadataUrl,url : lyrMetadata[title].metadataUrl}
,++downloadLyrCount
));
}
if (lyrMetadata[title].extractDoc) {
for (var i = 0; i < lyrMetadata[title].extractDoc.length; i++) {
downloadLyrStore.add(new downloadLyrStore.recordType(
{ico : 'NONE',title : ' ' + lyrMetadata[title].extractDoc[i],url : lyrMetadata[title].extractDoc[i]}
,++downloadLyrCount
));
}
}
}
});
if (downloadLyrCount == 0) {
Ext.Msg.alert('Data export','Sorry, no layers were eligible for export.');
return;
}
var dataURL = [];
var lastTitle;
downloadLyrStore.each(function(rec) {
var title = rec.get('title').replace(' ','');
if (!dataURL[title] & title.indexOf('http://') < 0) {
var layer = '';
if (rec.get('url').indexOf('application/vnd.google-earth.kml+xml') >= 0 || lyrMetadata[title].imgBytesPerPixel || lyrMetadata[title].imgUnitsPerPixel) {
layer = String(OpenLayers.Util.getParameters(rec.get('url'))['layers']).replace(featurePrefix + ':','');
}
else if (new RegExp(/outputformat=(excel2007|excel|csv)/).test(rec.get('url'))) {
layer = String(OpenLayers.Util.getParameters(rec.get('url'))['typename']).replace(featurePrefix + ':','');
}
dataURL[title] = {
base : safeXML(rec.get('url'))
,metadata : []
,layer : layer
,style : ''
};
// pass along style for kml
if (rec.get('url').indexOf('application/vnd.google-earth.kml+xml') >= 0) {
dataURL[title].style = wmsStyl[title];
}
lastTitle = title;
}
else {
dataURL[lastTitle].metadata.push(safeXML(rec.get('url')));
}
});
var dataXML = '';
for (var i in dataURL) {
if (dataURL[i].base) {
dataXML += '' + dataURL[i].metadata.join('') + '' + '';
}
}
YUI().use("io",function(Y) {
var handleSuccess = function(ioId,o,args) {
Ext.MessageBox.hide();
Ext.MessageBox.show({
title : 'Download exported data'
,msg : 'Click here to download the ZIP file.'
,width : 300
});
};
Y.on('io:success',handleSuccess,this,[]);
var cfg = {
method : 'POST'
,headers : {'Content-Type':'application/xml; charset=UTF-8'}
,data : '' + dataXML + ''
};
Ext.MessageBox.show({
title : 'Exporting data'
,msg : 'Exporting data, please wait...'
,progressText : 'Saving...'
,width : 300
,wait : true
,waitConfig : {interval:200}
});
var request = Y.io(mkzipCGI,cfg);
});
}}
,cards : [
new Ext.ux.Wiz.Card({
title : 'How to export data'
,items : [{
bodyStyle : 'padding:30px'
,border : false
,html : 'Welcome to the data export wizard.
This wizard may be used to download geospatial data as shapefiles, Google Earth files (KMLs), or GeoTIFFs. Users may choose their area of interest and subsets of data layers may be downloaded. Metadata and other supporting documents are also packaged with the exported data.
A 15 MB size limit has been imposed on each raster data layer, and a 25,000 feature limit has been imposed on each vector data layer. For information on accessing full datasets, please check the Help document.
'
}]
})
,new Ext.ux.Wiz.Card({
title : 'Select data layers and area of interest'
,monitorValid : true
,id : 'wizardStep2'
,items : [
{
html : 'By default, the checked data layers in the Active Data Layers window are selected for export. Use the Select additional data layers box to add other data layers to your selection. If the current map displays the appropriate extent, then click Next.'
,bodyStyle : 'padding:10px'
,border : false
}
,{
xtype : 'fieldset'
,title : 'Data layers'
,items : [
{
layout : 'column'
,border : false
,items : [
{
columnWidth : .5
,bodyStyle : 'padding-left:2px'
,border : false
,items : [
new MorisOliverApp.thGridPanel({
height : 200
,width : 272
,title : 'Selected data layers'
,store : tstLyrStore
,hideHeaders : true
,columns : [
{id : 'ico' ,header :'Icon' ,width : 25 ,renderer : ico2img}
,{id : 'title',header : 'Layer name',width : 800 }
]
// ,autoExpandColumn : 'title'
,tbar : [
{
iconCls : 'buttonIcon'
,tooltip : "Import active map's active data layers"
,text : 'Import active data layers'
,icon : 'img/import.png'
,handler : function() {
tstLyrStore.removeAll();
for (var j = map.layers.length - 1; j >= 0; j--) {
for (var i in activeLyr) {
if (map.layers[j].name == i && String(lyr2wms[i]).indexOf(featurePrefix + ':') == 0) {
// a normal find wasn't working properly, so loop through the list to keep dups out
var exists = false;
tstLyrStore.each(function(rec) {
exists = exists || rec.get('title') == activeLyr[i].name;
});
if (!exists) {
tstLyrStore.add(new tstLyrStore.recordType(
{ico : wms2ico[lyr2wms[activeLyr[i].name]],title : activeLyr[i].name}
,++tstLyrCount
));
}
}
}
}
}
}
,'->'
,{
iconCls : 'buttonIcon'
,tooltip : 'Remove all data layers'
,text : 'Remove all'
,icon : 'img/remove.png'
,handler : function() {
tstLyrStore.removeAll();
}
}
]
,listeners : {
contextmenu : function(e) {
e.stopEvent();
}
,rowcontextmenu : function(g,row,e) {
var sel = g.getSelectionModel();
if (!sel.isSelected(row)) {
sel.selectRow(row);
}
var contextMenu = new Ext.menu.Menu({
items: [{
text : 'Remove layer(s)'
,iconCls : 'buttonIcon'
,icon : 'img/remove.png'
,handler : function() {
var s = g.getSelectionModel().getSelections();
for (var i = 0; i < s.length; i++) {
g.getStore().remove(s[i]);
}
}
}]
});
contextMenu.showAt(e.getXY())
}
}
})
]
}
,{
columnWidth : .5
,bodyStyle : 'padding-right:2px'
,border : false
,items : [
new Ext.tree.TreePanel({
height : 200
,width : 272
,title : 'Select additional data layers'
,id : 'availableDataLyrWiz'
,collapsible : true
,collapsed : true
,autoScroll : true
,rootVisible : false
,root : new Ext.tree.AsyncTreeNode()
,loader : new Ext.app.LayerLoader({
dataUrl : foldersetLoc + '?a'
,requestMethod : 'GET'
})
,tbar : {height : 27,items : [
new Ext.form.ComboBox({
store : lyrStoreSearchWizard
,id : 'lyrSearchWizardCombo'
,forceSelection : true
,triggerAction : 'all'
,emptyText : 'Search data layers'
,selectOnFocus : true
,mode : 'local'
,valueField : 'id'
,displayField : 'title'
,width : 265
,listeners : {
select : function(comboBox,rec,i) {
var olLayerTree = Ext.getCmp('availableDataLyrWiz');
olLayerTree.getRootNode().cascade(function(n) {
if (n.attributes.text == rec.get('title')) {
olLayerTree.selectPath(n.getPath());
n.fireEvent('click',n);
n.ui.focus();
}
});
}
}
})
]}
,listeners : {
click : function(node,e){
if (!node.isLeaf()) {
return;
}
// a normal find wasn't working properly, so loop through the list to keep dups out
var exists = false;
tstLyrStore.each(function(rec) {
exists = exists || rec.get('title') == node.attributes.text;
});
if (!exists) {
// grab the metadata if necessary and add when done
if (!lyrMetadata[node.attributes.text]) {
loadLayerMetadata(lyr2wms[node.attributes.text],node.attributes.text,node.attributes.style,false,false,{store : tstLyrStore,title : node.attributes.text});
}
else {
tstLyrStore.add(new tstLyrStore.recordType(
{ico : wms2ico[lyr2wms[node.attributes.text]],title : node.attributes.text}
,++tstLyrCount
));
}
}
}
,contextmenu : function(n,e) {
if (n.isLeaf()) {
}
else {
var isGrandparent = false;
for (var i = 0; i < n.childNodes.length; i++) {
isGrandparent = isGrandparent || n.childNodes[i].hasChildNodes();
}
if (!isGrandparent) {
new Ext.menu.Menu({
items: [{
text : 'Add folder'
,id : 'addFolder'
,iconCls : 'buttonIcon'
,icon : 'img/addPlus.png'
,handler : function() {
var a = [];
n.eachChild(function(child) {
a.push({
text : child.attributes.text
,style : child.attributes.style
});
// a.push([child.attributes.wmsName,child.attributes.only_project,child.attributes.text,true,1]);
});
for (var i = 0; i < a.length; i++) {
// a normal find wasn't working properly, so loop through the list to keep dups out
var exists = false;
tstLyrStore.each(function(rec) {
exists = exists || rec.get('title') == a[i].text;
});
if (!exists) {
// grab the metadata if necessary and add when done
if (!lyrMetadata[a[i].text]) {
loadLayerMetadata(lyr2wms[a[i].text],a[i].text,a[i].style,false,false,{store : tstLyrStore,title : a[i].text});
}
else {
tstLyrStore.add(new tstLyrStore.recordType(
{ico : wms2ico[lyr2wms[a[i].text]],title : a[i].text}
,++tstLyrCount
));
}
}
}
}
}]
}).showAt(e.getXY());
}
}
}
}
})
]
}
]
}
]
}
,mkAreaOfInterestFieldset(aoi)
]
})
,new Ext.ux.Wiz.Card({
title : 'Query results'
,listeners : {
show : function() {
bboxLyrStore.removeAll();
var tstBbox = new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(exportBbox.minX,exportBbox.minY)
,new OpenLayers.Geometry.Point(exportBbox.maxX,exportBbox.minY)
,new OpenLayers.Geometry.Point(exportBbox.maxX,exportBbox.maxY)
,new OpenLayers.Geometry.Point(exportBbox.minX,exportBbox.maxY)
]).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:4326"));
// assume no hits
Ext.getCmp('wizVectorFmt').disable();
Ext.getCmp('wizRasterFmt').disable();
tstLyrStore.each(function(rec) {
var title = rec.get('title');
var bboxOK = 'N';
var exportOK = '';
var ico = wms2ico[lyr2wms[title]];
var rstrOK = rasterOK(title);
if (!rstrOK) {
ico += 'Gray';
}
if (new OpenLayers.Geometry.Polygon(tstBbox).intersects(getCapsBbox[lyr2wms[title]].toGeometry())) {
bboxOK = 'Y';
}
var wfsMsg = 'testing...';
// turn on options based on the ico (layer type)
if (ico.indexOf('poly') >= 0 || ico.indexOf('pt') >= 0 || ico.indexOf('line') >= 0) {
Ext.getCmp('wizVectorFmt').enable();
}
else if (ico.indexOf('raster') >= 0 || ico.indexOf('grid') >= 0) {
Ext.getCmp('wizRasterFmt').enable();
if (!rstrOK) {
wfsMsg = '> max file size';
exportOK = 'N';
}
else {
wfsMsg = 'n/a';
}
}
bboxLyrStore.add(new bboxLyrStore.recordType(
{'ico' : ico,'title' : title,'bbox' : bboxOK,'wfs' : wfsMsg,'export' : exportOK}
,++bboxLyrCount
));
});
if (Ext.getCmp('wizVectorFmt').disabled && !Ext.getCmp('wizRasterFmt').disabled) {
Ext.getCmp('radioEpsg').disable();
}
else {
Ext.getCmp('radioEpsg').enable();
}
// go back thru the layers and fire off a resultType=hits request for each one
tstLyrStore.each(function(rec) {
var ico = wms2ico[lyr2wms[rec.get('title')]];
YUI().use("io",function(Y) {
var handleSuccess = function(ioId,o,args) {
if (window.DOMParser) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(o.responseText,"text/xml");
}
else {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(o.responseText);
}
// update the right row w/ the # of feature hits
var el = getElementsByTagNameNS(xmlDoc,'http://www.opengis.net/wfs','wfs','FeatureCollection')[0];
if (el) {
var hits = el.getAttribute('numberOfFeatures');
if (hits > maxAllowedFeatures) {
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('wfs','> max # features');
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('export','N');
}
else {
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('wfs',hits + ' feature(s)');
if (hits == 0) {
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('export','N');
}
}
}
else {
if (!(args[1] == 'raster' || args[1] == 'grid')) {
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('wfs','none');
}
}
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('busy','done');
if (bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).get('export') !== 'N') {
bboxLyrStore.getAt(bboxLyrStore.find('title',args[0])).set('export','Y');
}
bboxLyrStore.commitChanges();
};
var title = rec.get('title');
Y.on('io:success',handleSuccess,this,[title,ico]);
geomName = 'SHAPE';
if (lyr2shp[title] && lyr2shp[title].indexOf('true') !== -1) {
geomName = 'the_geom';
}
var customFilter = ['','',''];
var xmlFilter = OpenLayers.Util.getParameters(activeLyr[title].getFullRequestString({}))['FILTER'];
if (xmlFilter) {
var xml = new OpenLayers.Format.XML();
var f = xml.read(xmlFilter);
customFilter = [
''
,xml2str(f.getElementsByTagName("*")[1])
,''
];
}
if (exportBbox.verts.length == 5) {
var poly = [];
for (var j = 0; j < exportBbox.verts.length; j++) {
poly.push(exportBbox.verts[j].x + ' ' + exportBbox.verts[j].y);
}
data = ''
+ ''
+ customFilter[0]
+ '' + geomName + '' + poly.join(' ') + ''
+ customFilter[1]
+ customFilter[2]
+ ''
+ ''
}
else {
data = ''
+ ''
+ customFilter[0]
+ '' + geomName + '' + exportBbox.verts[0] + ''
+ customFilter[1]
+ customFilter[2]
+ ''
+ ''
}
var cfg = {
method : "POST"
,headers : {'Content-Type':'application/xml; charset=UTF-8'}
,data : data
};
var rstrOK = rasterOK(rec.get('title'));
var request;
if (!rstrOK) {
bboxLyrStore.getAt(bboxLyrStore.find('title',rec.get('title'))).set('busy','done');
bboxLyrStore.commitChanges();
}
request = Y.io(proxyLoc + wfsUrl,cfg);
});
});
}
}
,items : [
{
html : 'This step identifies features within the area of interest. If you are satisfied with the results, click Next to continue. Otherwise, click Previous to refine the search criteria.'
,bodyStyle : 'padding:10px'
,border : false
}
,new MorisOliverApp.thGridPanel({
height : 331
,title : 'Query results'
,store : bboxLyrStore
,disableSelection : true
,enableHdMenu : false
,columns : [
{id : 'ico' ,dataIndex : 'ico' ,header : '' ,width : 25,renderer : ico2img }
,{id : 'title' ,dataIndex : 'title' ,header : 'Data layer name' }
,{id : 'wfs' ,dataIndex : 'wfs' ,header : 'Feature(s) found?' }
,{id : 'export',dataIndex : 'export',header : 'OK to export?' ,align : 'center',renderer: okIco }
,{id : 'busy' ,dataIndex : 'busy' ,header : '' ,width : 30,renderer : busyIco }
]
,autoExpandColumn : 'title'
,loadMask : true
})
]
})
,new Ext.ux.Wiz.Card({
title : 'Select output and download options'
,monitorValid : true
,items : [
{
xtype : 'fieldset'
,title : 'Vector data output options'
,items : [
{
xtype : 'radiogroup'
,id : 'wizVectorFmt'
,fieldLabel : 'Format'
,columns : 2
,items : [
{boxLabel : 'Shapefile (.shp)' ,name : 'vectorFormat',inputValue : 'shp',checked : true}
,{boxLabel : 'Google Earth file (.kml)',name : 'vectorFormat',inputValue : 'kml' }
,{boxLabel : 'Excel 2007 (.xlsx)' ,name : 'vectorFormat',inputValue : 'excel2007' }
,{boxLabel : 'Excel 97-2003 (.xls)' ,name : 'vectorFormat',inputValue : 'excel' }
,{boxLabel : 'CSV (.csv)' ,name : 'vectorFormat',inputValue : 'csv' }
]
,listeners : {change : function(group,ckedRadio) {
if (new RegExp(/kml|excel2007|excel|csv/).test(ckedRadio.getGroupValue())) {
Ext.getCmp('radioEpsg').disable();
}
else {
Ext.getCmp('radioEpsg').enable();
}
}}
}
]
}
,{
xtype : 'fieldset'
,title : 'Raster data output options'
,items : [
{
layout : 'column'
,border : false
,items : [
{
layout : 'form'
,border : false
,items : [
{
xtype : 'radiogroup'
,id : 'wizRasterFmt'
,fieldLabel : 'Format'
,items : [
{boxLabel : 'GeoTIFF (available in NAD83/Massachusetts State Plane Coordinate System, Mainland Zone, meters - EPSG:26986 coordinate system only)',name : 'rasterFormat',inputValue : 'geoTiff',checked : true}
// ,{boxLabel : 'Grid' ,name : 'rasterFormat',inputValue : 'grid' }
]
}
]
}
]
}
]
}
,{
xtype : 'fieldset'
,title : 'Output coordinate system'
,items : [
{
xtype : 'radiogroup'
,id : 'radioEpsg'
,columns : 1
,items : [
{boxLabel : 'NAD83/Massachusetts State Plane Coordinate System, Mainland Zone, meters - EPSG:26986',name : 'epsg',inputValue : 'EPSG:26986',checked : true }
,{boxLabel : 'NAD83/UTM zone 18N, meters (Western Massachusetts) - EPSG:26918' ,name : 'epsg',inputValue : 'EPSG:26918' }
,{boxLabel : 'NAD83/UTM zone 19N, meters (Eastern Massachusetts) - EPSG:26919' ,name : 'epsg',inputValue : 'EPSG:26919' }
,{boxLabel : 'WGS84 (Latitude-Longitude) - EPSG:4326' ,name : 'epsg',inputValue : 'EPSG:4326' }
]
}
]
}
,{
xtype : 'fieldset'
,title : 'Name of the ZIP file to download (do not use spaces)'
,items : new Ext.form.TextField({
name : 'zipName'
,id : 'zipName'
,allowBlank : false
,fieldLabel : 'File name'
})
}
]
})
]
});
wizGetData.show();
}
function syncExportBboxVerts() {
exportBbox.verts = [
new OpenLayers.Geometry.Point(exportBbox.minX,exportBbox.minY).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:26986"))
,new OpenLayers.Geometry.Point(exportBbox.maxX,exportBbox.minY).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:26986"))
,new OpenLayers.Geometry.Point(exportBbox.maxX,exportBbox.maxY).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:26986"))
,new OpenLayers.Geometry.Point(exportBbox.minX,exportBbox.maxY).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:26986"))
,new OpenLayers.Geometry.Point(exportBbox.minX,exportBbox.minY).transform(new OpenLayers.Projection(exportBbox.units.replace('dms','')),new OpenLayers.Projection("EPSG:26986"))
];
}
function mkAreaOfInterestFieldset(aoi) {
if (aoi.typ == 'bbox') {
return {
xtype : 'fieldset'
,title : 'Area of interest'
,id : 'wizardStep2AOI'
,items : [
{
html : 'To change the geographic extent of the data to export, use the Advanced - Change area of interest option. Once the appropriate extent has been entered, click Next.'
,bodyStyle : 'padding:0 5px 10px 5px'
,border : false
}
,{xtype : 'fieldset',title : 'Advanced - Change area of interest',collapsible : true,collapsed : true,listeners : {expand : function() {Ext.getCmp('wizardStep2').doLayout();Ext.getCmp('getDataWiz').setWidth(Ext.getCmp('getDataWiz').getWidth() - 1);},collapse : function() {Ext.getCmp('wizardStep2').doLayout();Ext.getCmp('getDataWiz').setWidth(Ext.getCmp('getDataWiz').getWidth() + 1);}},items : [{
layout : 'column'
,border : false
,items : [
{
columnWidth : .5
,layout : 'form'
,border : false
,items : [
{
xtype : 'textfield'
,fieldLabel : 'Min X'
,id : 'minX'
,allowBlank : false
,listeners : {valid : function(field) {
exportBbox.minX = exportBbox.units.indexOf('dms') >= 0 ? dms2dd(field.getValue()) : field.getValue();
syncExportBboxVerts();
}}
}
,{
xtype : 'textfield'
,fieldLabel : 'Min Y'
,id : 'minY'
,allowBlank : false
,listeners : {valid : function(field) {
exportBbox.minY = exportBbox.units.indexOf('dms') >= 0 ? dms2dd(field.getValue()) : field.getValue();
syncExportBboxVerts();
}}
}
]
}
,{
columnWidth : .5
,layout : 'form'
,border : false
,items : [
{
xtype : 'textfield'
,fieldLabel : 'Max X'
,id : 'maxX'
,allowBlank : false
,listeners : {valid : function(field) {
exportBbox.maxX = exportBbox.units.indexOf('dms') >= 0 ? dms2dd(field.getValue()) : field.getValue();
syncExportBboxVerts();
}}
}
,{
xtype : 'textfield'
,fieldLabel : 'Max Y'
,id : 'maxY'
,allowBlank : false
,listeners : {valid : function(field) {
exportBbox.maxY = exportBbox.units.indexOf('dms') >= 0 ? dms2dd(field.getValue()) : field.getValue();
syncExportBboxVerts();
}}
}
]
}
]
}
,{
xtype : 'radiogroup'
,fieldLabel : 'Units'
,id : 'radioUnits'
,items : [
{boxLabel : 'MA State Plane meters' ,name : 'units',inputValue : 'EPSG:26986' ,checked : defaultCoordUnit == 'm' }
,{boxLabel : 'Decimal degrees' ,name : 'units',inputValue : 'EPSG:4326' ,checked : defaultCoordUnit == 'dd' }
,{boxLabel : 'Degrees, minutes, seconds',name : 'units',inputValue : 'EPSG:4326dms',checked : defaultCoordUnit == 'dms'}
]
,listeners : {
render : function(field) {
var proj = 'EPSG:26986';
if (defaultCoordUnit == 'dd' || defaultCoordUnit == 'dms') {
proj = 'EPSG:4326';
}
exportBbox.units = field.items.get(0).getGroupValue();
var bbox = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection(proj)).toArray();
if (defaultCoordUnit == 'dms') {
Ext.getCmp('minX').setValue(convertDMS(bbox[0],'',true));
Ext.getCmp('minY').setValue(convertDMS(bbox[1],'',true));
Ext.getCmp('maxX').setValue(convertDMS(bbox[2],'',true));
Ext.getCmp('maxY').setValue(convertDMS(bbox[3],'',true));
}
else {
Ext.getCmp('minX').setValue(Math.round(bbox[0]*1000000)/1000000);
Ext.getCmp('minY').setValue(Math.round(bbox[1]*1000000)/1000000);
Ext.getCmp('maxX').setValue(Math.round(bbox[2]*1000000)/1000000);
Ext.getCmp('maxY').setValue(Math.round(bbox[3]*1000000)/1000000);
}
}
,valid : function(field) {exportBbox.units = field.items.get(0).getGroupValue()}
}
}
,{
layout : 'fit'
,height : 30
,border : false
,bodyStyle : 'padding-right:100px;padding-left:100px'
,items : [{
xtype : 'button'
,text : "Import active map's bounding box"
,handler : function() {
var bbox = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection(exportBbox.units.replace('dms',''))).toArray();
if (exportBbox.units.indexOf('dms') >= 0) {
Ext.getCmp('minX').setValue(convertDMS(bbox[0],'',true));
Ext.getCmp('minY').setValue(convertDMS(bbox[1],'',true));
Ext.getCmp('maxX').setValue(convertDMS(bbox[2],'',true));
Ext.getCmp('maxY').setValue(convertDMS(bbox[3],'',true));
}
else {
Ext.getCmp('minX').setValue(Math.round(bbox[0]*1000000)/1000000);
Ext.getCmp('minY').setValue(Math.round(bbox[1]*1000000)/1000000);
Ext.getCmp('maxX').setValue(Math.round(bbox[2]*1000000)/1000000);
Ext.getCmp('maxY').setValue(Math.round(bbox[3]*1000000)/1000000);
}
}
}]
}]}
]
}
}
else if (aoi.typ == 'poly') {
return {
xtype : 'fieldset'
,title : 'Area of interest'
,items : [
{
html : 'The area you defined with the identify tool will be used as your area of interest.'
,bodyStyle : 'padding:0 5px 10px 5px'
,border : false
}
]
};
}
}
function showBaseLayerMetadata(l) {
var l2m = {
'OpenStreetMap' : 'http://www.openstreetmap.org/'
,'Google Terrain' : 'http://en.wikipedia.org/wiki/Google_Maps'
,'Google Satellite' : 'http://en.wikipedia.org/wiki/Google_Maps#Satellite_view'
,'Custom' : 'https://wiki.state.ma.us/confluence/display/massgis'
,'Bing Hybrid' : 'http://en.wikipedia.org/wiki/Bing_Maps'
,'Bing Roads' : 'http://en.wikipedia.org/wiki/Bing_Maps#Road_view'
,'Bing Aerial' : 'http://en.wikipedia.org/wiki/Bing_Maps#Aerial_view'
,'Google Hybrid' : 'http://en.wikipedia.org/wiki/Google_Maps'
,'Google Roadmap' : 'http://en.wikipedia.org/wiki/Google_Maps'
,'CloudMade' : 'http://wiki.openstreetmap.org/wiki/CloudMade'
,'Massachusetts Topographic Map' : 'http://wiki.openstreetmap.org/wiki/TopOSM'
,'AGOL_Orthos_2013' : 'http://massgis.maps.arcgis.com/home/item.html?id=3dbb839b26ec40f991379cda90912399'
,'Basemaps_Orthos_DigitalGlobe2011_2012' : 'http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/online-mapping/dg2011-12-basemap.html'
,'MassGIS_Basemap' : 'http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/online-mapping/massgis-basemap.html'
};
if (Ext.getCmp('baseLayerMetadataWin')) {
Ext.getCmp('baseLayerMetadataWin').close();
}
window.open(l2m[l]);
return;
var MIF = new Ext.ux.ManagedIFramePanel({
defaultSrc : l2m[l]
,bodyBorder : false
,bodyStyle : 'background:white'
,listeners : {domready : function(frame){
var fbody = frame.getBody();
var w = Ext.getCmp('myFrameWin');
if (w && fbody){
// calc current offsets for Window body border and padding
var bHeightAdj = w.body.getHeight() - w.body.getHeight(true);
var bWidthAdj = w.body.getWidth() - w.body.getWidth(true);
// Window is rendered (has size) but invisible
w.setSize(Math.max(w.minWidth || 0, fbody.scrollWidth + w.getFrameWidth() + bWidthAdj) ,
Math.max(w.minHeight || 0, fbody.scrollHeight + w.getFrameHeight() + bHeightAdj) );
// then show it sized to frame document
w.show();
}
}}
});
new Ext.Window({
title : l + ' metadata'
,width : mapPanel.getWidth() * 0.65
,height : mapPanel.getHeight() * 0.65
,hideMode : 'visibility'
,id : 'baseLayerMetadataWin'
,hidden : true //wait till you know the size
,plain : true
,constrainHeader : true
,minimizable : false
,ddScroll : false
,border : false
,bodyBorder : false
,layout : 'fit'
,plain : true
,maximizable : true
,buttonAlign : 'center'
,items : MIF
}).show();
}
function addRemoteWmsLayer(rec) {
var lyr = rec.getLayer();
var bbox = rec.get('llbbox');
lyrMetadata[lyr.name] = {
title : lyr.name
,maxExtent : {
left : bbox[0]
,bottom : bbox[1]
,right : bbox[2]
,top : bbox[3]
}
};
lyr2type[lyr.name] = ['externalWms'];
lyr2wms[lyr.name] = rec.get('name');
wmsStyl[lyr.name] = '';
wms2ico[rec.get('name')] = 'layergroup';
addLayer(
rec.get('name')
,map.getProjectionObject()
,lyr.name
,true
,1
,lyr.url.indexOf('?') >= 0 ? lyr.url.substr(0,lyr.url.indexOf('?')) : lyr.url
);
}
function getCaps(n,u) {
if (Ext.getCmp('externalWmsLayers')) {
Ext.getCmp('externalWmsLayers').destroy();
}
externalWmsWin.add({
xtype : 'fieldset'
,id : 'externalWmsLayers'
,title : 'Data layers'
,items : [
new Ext.grid.GridPanel({
id : 'externalWmsDataLayers'
,width : externalWmsWin.getWidth() - 50
,height : externalWmsWin.getHeight() - Ext.getCmp('externalWmsGridPanel').getHeight() - Ext.getCmp('externalWmsDirections').getHeight() - 130
,tbar : [
{text : 'Add selected',handler : function() {
var sel = Ext.getCmp('externalWmsDataLayers').getSelectionModel().getSelections();
for (var i = 0; i < sel.length; i++) {
addRemoteWmsLayer(sel[i]);
}
}}
,'-'
,{text : 'Add all',handler : function() {
Ext.getCmp('externalWmsDataLayers').getSelectionModel().selectAll();
var sel = Ext.getCmp('externalWmsDataLayers').getSelectionModel().getSelections();
for (var i = 0; i < sel.length; i++) {
addRemoteWmsLayer(sel[i]);
}
}}
]
,store : new GeoExt.data.WMSCapabilitiesStore({
url : u
,autoLoad : true
,sortInfo : {
field : 'title'
,direction : 'ASC'
}
})
,columns : [
{header : 'Title' ,dataIndex : 'title' ,sortable : true,id : 'title'}
,{header : 'Name' ,dataIndex : 'name' ,sortable : true}
,{header : 'Description',dataIndex : 'abstract',sortable : true}
]
,autoExpandColumn : 'title'
,loadMask : true
,listeners : {
rowdblclick : function(grid,idx) {addRemoteWmsLayer(grid.getStore().getAt(idx))}
,contextmenu : function(e) {
e.stopEvent();
}
,rowcontextmenu : function(g,row,e) {
var sel = g.getSelectionModel();
if (!sel.isSelected(row)) {
sel.selectRow(row);
}
new Ext.menu.Menu({
items: [{
text : 'Add layer(s)'
,id : 'addLayer'
,iconCls : 'buttonIcon'
,icon : 'img/addPlus.png'
,handler : function() {
var sel = Ext.getCmp('externalWmsDataLayers').getSelectionModel().getSelections();
for (var i = 0; i < sel.length; i++) {
addRemoteWmsLayer(sel[i]);
}
}
}]
}).showAt(e.getXY());
}
}
})
]
});
externalWmsWin.doLayout();
}
function goHelpHTML() {
if (Ext.getCmp('myFrameWin')) {
Ext.getCmp('myFrameWin').close();
}
var MIF = new Ext.ux.ManagedIFramePanel({
defaultSrc : helpUrl1
,bodyBorder : false
,bodyStyle : 'background:white'
,listeners : {domready : function(frame){
var fbody = frame.getBody();
var w = Ext.getCmp('myFrameWin');
if (w && fbody){
// calc current offsets for Window body border and padding
var bHeightAdj = w.body.getHeight() - w.body.getHeight(true);
var bWidthAdj = w.body.getWidth() - w.body.getWidth(true);
// Window is rendered (has size) but invisible
w.setSize(Math.max(w.minWidth || 0, fbody.scrollWidth + w.getFrameWidth() + bWidthAdj) ,
Math.max(w.minHeight || 0, fbody.scrollHeight + w.getFrameHeight() + bHeightAdj) );
// then show it sized to frame document
w.show();
}
}}
});
new Ext.Window({
title : siteTitle + ' help'
,width : mapPanel.getWidth() * 0.65
,height : mapPanel.getHeight() * 0.65
,hideMode : 'visibility'
,id : 'myFrameWin'
,hidden : true //wait till you know the size
,plain : true
,constrainHeader : true
,minimizable : false
,ddScroll : false
,border : false
,bodyBorder : false
,layout : 'fit'
,plain : true
,maximizable : true
,buttonAlign : 'center'
,items : MIF
}).show();
}
function countTopLayers() {
// keep this function current w/ the # of layers that must always appear on top!
var active = 0;
layerRuler ? active++ : null;
lyrGeoLocate ? active++ : null;
lyrRasterQry ? active++ : null;
featureBoxControl.polygon.layer ? active++ : null;
featurePolyControl.polygon.layer ? active++ : null;
bufferControl.point.layer ? active++ : null;
return active;
}
function saveResultsAs(request,format,extension,mode,gridPanel) {
// enumerate cols since some may be hidden
var cols = [];
for (var i = 0; i < gridPanel.getColumnModel().columns.length; i++) {
if (!gridPanel.getColumnModel().columns[i].hidden) {
cols.push('' + gridPanel.getColumnModel().columns[i].dataIndex + '');
}
}
var f;
// this will always be true
if (gridPanel) {
var fids = [];
if (mode == 'selection') {
var sel = gridPanel.getSelectionModel().getSelections();
if (sel.length == 0) {
Ext.Msg.alert('Save results error',"You haven't selected any rows for export. Please select at least one row and try again.");
}
else {
for (var i = 0; i < sel.length; i++) {
fids.push(sel[i].get('fid'));
}
f = new OpenLayers.Filter.FeatureId({fids : fids});
}
}
// a user may have removed a record from the list, so iterate through them to pull out fid's
else if (mode == 'all') {
gridPanel.getStore().each(function(rec) {
fids.push(rec.get('fid'));
});
f = new OpenLayers.Filter.FeatureId({fids : fids});
}
}
else {
f = request.filter;
}
if (f) {
var parser = new OpenLayers.Format.Filter.v1_1_0();
var xml = new OpenLayers.Format.XML();
var filter = request.header.replace('___FORMAT___',format) + cols.join("\n") + xml.write(parser.write(f)) + request.footer;
YUI().use("io",function(Y) {
var handleSuccess = function(ioId,o,args) {
Ext.MessageBox.hide();
Ext.MessageBox.show({
title : 'Download exported data'
,msg : 'Click here to download your file.'
,width : 300
});
};
Y.on('io:success',handleSuccess,this,[]);
var cfg = {
method : 'POST'
,headers : {'Content-Type':'application/xml; charset=UTF-8'}
,data : filter
};
Ext.MessageBox.show({
title : 'Exporting data'
,msg : 'Exporting data, please wait...'
,progressText : 'Saving...'
,width : 300
,wait : true
,waitConfig : {interval:200}
});
var r = Y.io('getstore.php?name=' + request.title + '.' + extension + '&url=' + wfsUrl,cfg);
});
}
}
function makeBasemapMenu() {
var bm = [];
for (i = 0; i < availableBase.length; i++) {
if (availableBase[i] == 'custom') {
bm.push(
{
text : 'Create custom basemap'
,group : 'basemap'
,checked : defaultBase == 'custom'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Custom');
}
}]}
,handler : function () {
addBaseLayer('custom');
map.setOptions({fractionalZoom : true});
if (map.getProjection() == 'EPSG:26986') {
map.setBaseLayer(lyrBase['custom']);
Ext.getCmp('customScale') && Ext.getCmp('customScale').setDisabled(false);
Ext.getCmp('customScaleHeader').setText('Type a custom scale below and press Enter. A leading "1:" is optional.');
Ext.getCmp('zoomToAScale').setDisabled(false);
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:26986'));
map.setBaseLayer(lyrBase['custom']);
Ext.getCmp('customScale') && Ext.getCmp('customScale').setDisabled(false);
Ext.getCmp('zoomToAScale').setDisabled(false);
Ext.getCmp('customScaleHeader').setText('Type a custom scale below and press Enter. A leading "1:" is optional.');
map.setOptions({maxExtent : maxExtent26986});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
,'-'
);
}
else if (availableBase[i] == 'bingHybrid') {
bm.push(
{
text : 'Bing Hybrid'
,group : 'basemap'
,checked : defaultBase == 'bingHybrid'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Bing Hybrid');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('bingHybrid');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['bingHybrid']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['bingHybrid']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'bingRoads') {
bm.push(
{
text : 'Bing Roads'
,group : 'basemap'
,checked : defaultBase == 'bingRoads'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Bing Roads');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('bingRoads');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['bingRoads']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['bingRoads']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'bingAerial') {
bm.push(
{
text : 'Bing Aerial'
,group : 'basemap'
,checked : defaultBase == 'bingAerial'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Bing Aerial');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('bingAerial');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['bingAerial']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['bingAerial']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'CloudMade') {
bm.push(
{
text : 'CloudMade'
,group : 'basemap'
,checked : defaultBase == 'CloudMade'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('CloudMade');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
// cloudmade is having problems w/ non-standard maxExtents, so force it here
map.setOptions({maxExtent : new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508.34)});
addBaseLayer('CloudMade');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['CloudMade']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['CloudMade']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'googleHybrid') {
bm.push(
{
text : 'Google Hybrid'
,group : 'basemap'
,checked : defaultBase == 'googleHybrid'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Google Hybrid');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('googleHybrid');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['googleHybrid']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['googleHybrid']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'googleRoadmap') {
bm.push(
{
text : 'Google Roadmap'
,group : 'basemap'
,checked : defaultBase == 'googleRoadmap'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Google Roadmap');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('googleRoadmap');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['googleRoadmap']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['googleRoadmap']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'googleSatellite') {
bm.push(
{
text : 'Google Satellite'
,group : 'basemap'
,checked : defaultBase == 'googleSatellite'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Google Satellite');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('googleSatellite');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['googleSatellite']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['googleSatellite']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'googleTerrain') {
bm.push(
{
text : 'Google Terrain'
,group : 'basemap'
,checked : defaultBase == 'googleTerrain'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Google Terrain');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('googleTerrain');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['googleTerrain']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['googleTerrain']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'openStreetMap') {
bm.push(
{
text : 'OpenStreetMap'
,group : 'basemap'
,checked : defaultBase == 'openStreetMap'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('OpenStreetMap');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('openStreetMap');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['openStreetMap']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['openStreetMap']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'TopOSM-MA') {
bm.push(
{
text : 'Massachusetts Topographic Map'
,group : 'basemap'
,checked : defaultBase == 'TopOSM-MA'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Massachusetts Topographic Map');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('TopOSM-MA');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['TopOSM-MA']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['TopOSM-MA']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'AGOL_Orthos_2013') {
bm.push(
{
text : 'Orthos 2013 (USGS)'
,group : 'basemap'
,checked : defaultBase == 'AGOL_Orthos_2013'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('AGOL_Orthos_2013');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('AGOL_Orthos_2013');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['AGOL_Orthos_2013']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['AGOL_Orthos_2013']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'Basemaps_Orthos_DigitalGlobe2011_2012') {
bm.push(
{
text : 'Digital Globe Orthophotos 2011-2012'
,group : 'basemap'
,checked : defaultBase == 'Basemaps_Orthos_DigitalGlobe2011_2012'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('Basemaps_Orthos_DigitalGlobe2011_2012');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('Basemaps_Orthos_DigitalGlobe2011_2012');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['Basemaps_Orthos_DigitalGlobe2011_2012']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['Basemaps_Orthos_DigitalGlobe2011_2012']);
Ext.getCmp('customScale').setDisabled(true);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
else if (availableBase[i] == 'MassGIS_Basemap') {
bm.push(
{
text : 'MassGIS Statewide Basemap'
,group : 'basemap'
,checked : defaultBase == 'MassGIS_Basemap'
,menu : {items : [{
text : 'View metadata'
,iconCls : 'buttonIcon'
,icon : 'img/info1.png'
,handler : function() {
showBaseLayerMetadata('MassGIS_Basemap');
}
}]}
,handler : function () {
map.setOptions({fractionalZoom : false});
addBaseLayer('MassGIS_Basemap');
Ext.getCmp('opacitySliderBaseLayer').setValue(100);
if (map.getProjection() == 'EPSG:900913') {
map.setBaseLayer(lyrBase['MassGIS_Basemap']);
Ext.getCmp('customScale') && Ext.getCmp('customScale').setDisabled(false);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
return;
}
else {
var ext = map.getExtent().transform(map.getProjectionObject(),new OpenLayers.Projection('EPSG:900913'));
map.setBaseLayer(lyrBase['MassGIS_Basemap']);
Ext.getCmp('customScale') && Ext.getCmp('customScale').setDisabled(false);
Ext.getCmp('customScaleHeader').setText('Custom scale disabled for current map projection.');
Ext.getCmp('zoomToAScale').setDisabled(true);
map.setOptions({maxExtent : maxExtent900913});
map.zoomToExtent(ext);
refreshLayers();
}
}
}
);
}
}
// get rid of a dangling divider if any
if (bm.length == 2 && bm[1] == '-') {
bm.pop();
}
return bm;
}
/*
* APIMethod: createGeodesicPolygon
* Create a regular polygon around a radius. Useful for creating circles
* and the like.
*
* Parameters:
* origin - {} center of polygon.
* radius - {Float} distance to vertex, in map units.
* sides - {Integer} Number of sides. 20 approximates a circle.
* rotation - {Float} original angle of rotation, in degrees.
* projection - {} the map's projection
*/
OpenLayers.Geometry.Polygon.createGeodesicPolygon = function(origin, radius, sides, rotation, projection){
if (projection.getCode() !== "EPSG:4326") {
origin.transform(projection, new OpenLayers.Projection("EPSG:4326"));
}
var latlon = new OpenLayers.LonLat(origin.x, origin.y);
var angle;
var new_lonlat, geom_point;
var points = [];
for (var i = 0; i < sides; i++) {
angle = (i * 360 / sides) + rotation;
new_lonlat = OpenLayers.Util.destinationVincenty(latlon, angle, radius);
new_lonlat.transform(new OpenLayers.Projection("EPSG:4326"), projection);
geom_point = new OpenLayers.Geometry.Point(new_lonlat.lon, new_lonlat.lat);
points.push(geom_point);
}
var ring = new OpenLayers.Geometry.LinearRing(points);
return new OpenLayers.Geometry.Polygon([ring]);
};
function unionFeatureGeometriesAndBuffer(features,dist,seg) {
var u;
var reader = new jsts.io.WKTReader();
for (var i = 0; i < features.length; i++) {
var g = features[i].geometry;
if (i == 0) {
u = reader.read(g.toString());
}
else {
u = u.union(reader.read(g.toString()));
}
}
u = u.buffer(dist,seg);
var parser = new jsts.io.OpenLayersParser();
return parser.write(u);
}
function launchRowQuery(rowIndex,filterFeatures) {
if (qryLyrStore.getAt(rowIndex).get('wfs') == '0 feature(s)') {
Ext.Msg.alert('Identify details','This data layer has zero features within or overlapping the identify area. Feature details will not be provided.');
if (!launchBufferQuery && Ext.getCmp('queryBuffer') && Ext.getCmp('queryBuffer').pressed) {
launchBufferQuery = true;
singleIdentifyLayerName = Ext.getCmp('queryBuffer').selectDataLayer
}
return;
}
else if (qryLyrStore.getAt(rowIndex).get('wfs') == 'no value') {
var centerPx = map.getPixelFromLonLat(qryBounds.getBounds().getCenterLonLat());
var lonLat = map.getLonLatFromPixel(centerPx);
lyrRasterQry.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonLat.lon,lonLat.lat)));
Ext.Msg.show({
title : 'Identify details'
,msg : 'This raster data layer has no value in the cell you identified.'
,fn : function() {lyrRasterQry.removeFeatures(lyrRasterQry.features)}
,buttons : Ext.Msg.OK
});
return;
}
else if (qryLyrStore.getAt(rowIndex).get('wfs') == 'not visible at scale') {
Ext.Msg.alert('Identify details','This data layer is not visible at this scale. Feature details will not be provided. Please check the Help document for more information.');
if (!launchBufferQuery && Ext.getCmp('queryBuffer') && Ext.getCmp('queryBuffer').pressed) {
launchBufferQuery = true;
singleIdentifyLayerName = Ext.getCmp('queryBuffer').selectDataLayer
}
return;
}
else if (qryLyrStore.getAt(rowIndex).get('wfs').indexOf('value') >= 0) {
featureBbox.unselectAll();
title = qryLyrStore.getAt(rowIndex).get('title');
var centerPx = map.getPixelFromLonLat(qryBounds.getBounds().getCenterLonLat());
var gfiUrl = activeLyr[title].getFullRequestString({INFO_FORMAT : 'text/html',BBOX : map.getExtent().toBBOX(),X : centerPx.x,Y : centerPx.y,REQUEST : 'GetFeatureInfo',QUERY_LAYERS : lyr2wms[title],WIDTH : map.div.style.width.replace('px',''),HEIGHT : map.div.style.height.replace('px',''),FOO : '',STYLE : ''}).replace('&FOO=','').replace('&STYLE=','');
var MIF = new Ext.ux.ManagedIFramePanel({
defaultSrc : gfiUrl
,bodyBorder : false
,bodyStyle : 'background:white'
,listeners : {domready : function(frame){
var fbody = frame.getBody();
var w = Ext.getCmp('myFrameWin');
if (w && fbody){
// calc current offsets for Window body border and padding
var bHeightAdj = w.body.getHeight() - w.body.getHeight(true);
var bWidthAdj = w.body.getWidth() - w.body.getWidth(true);
// Window is rendered (has size) but invisible
w.setSize(Math.max(w.minWidth || 0, fbody.scrollWidth + w.getFrameWidth() + bWidthAdj) ,
Math.max(w.minHeight || 0, fbody.scrollHeight + w.getFrameHeight() + bHeightAdj) );
// then show it sized to frame document
w.show();
}
}}
});
if (rasterQryWin[title] && rasterQryWin[title].isVisible()) {
rasterQryWin[title].hide();
}
rasterQryWin[title] = new Ext.Window({
title : title
,width : 640 / 1.5
,height : 480 / 1.5
,hideMode : 'visibility'
,hidden : true //wait till you know the size
,plain : true
,constrainHeader : true
,minimizable : false
,ddScroll : false
,border : false
,bodyBorder : false
,layout : 'fit'
,plain : true
,maximizable : true
,buttonAlign : 'center'
,closeAction : 'hide'
,items : MIF
,listeners : {
show : function() {
var lonLat = map.getLonLatFromPixel(centerPx);
lyrRasterQry.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonLat.lon,lonLat.lat)));
}
,hide : function() {
lyrRasterQry.removeFeatures(lyrRasterQry.features);
}
}
});
rasterQryWin[title].show();
return;
}
var p = qryLyrStore.getAt(rowIndex).get('wfs').split(' feature(s)');
if (p.length == 2 && p[0] > 500) {
Ext.Msg.alert('Identify details','This data layer has over 500 features within or overlapping the identify area. Feature details will not be provided.');
if (!launchBufferQuery && Ext.getCmp('queryBuffer') && Ext.getCmp('queryBuffer').pressed) {
launchBufferQuery = true;
singleIdentifyLayerName = Ext.getCmp('queryBuffer').selectDataLayer
}
return;
}
Ext.getCmp('qryFeatureDetails').getEl().mask('Retrieving features... | ![](img/loading16.gif) |
','mask');
featureBbox.unselectAll();
title = qryLyrStore.getAt(rowIndex).get('title');
if (!launchBufferQuery && Ext.getCmp('queryBuffer') && Ext.getCmp('queryBuffer').pressed) {
loadLayerDescribeFeatureType(lyr2wms[title],toolSettings.identifyBuffer.fieldsToShow);
}
else {
loadLayerDescribeFeatureType(lyr2wms[title]);
}
geomName = 'SHAPE';
if (lyr2shp[title] && lyr2shp[title].indexOf('true') !== -1) {
geomName = 'the_geom';
}
var xmlFilter = OpenLayers.Util.getParameters(activeLyr[title].getFullRequestString({}))['FILTER'];
var filter;
if (xmlFilter) {
var xml = new OpenLayers.Format.XML();
var f = xml.read(xmlFilter);
var parser = new OpenLayers.Format.Filter.v1_1_0();
filter = parser.read(f.documentElement);
}
featureBbox.protocol = OpenLayers.Protocol.WFS.fromWMSLayer(
activeLyr[title]
,{
// geometryName : 'line_geom'
geometryName : geomName
,featurePrefix : featurePrefix
,version : '1.1.0'
,srs : map.getProjection()
,defaultFilter : filter
}
);
featureBbox.setModifiers();
map.addControl(featureBbox);
featureBbox.activate();
// create filters for the export options
var exportFilter = new OpenLayers.Filter.Spatial({
type : featureBbox.filterType
,value : qryBounds
});
if (filter) {
exportFilter = new OpenLayers.Filter.Logical({
type : OpenLayers.Filter.Logical.AND
,filters : [
new OpenLayers.Filter.Spatial({
type : featureBbox.filterType
,value : qryBounds
})
,filter
]
});
}
// FORMAT is currently suported to be one of csv (.csv), excel (.xlsx), excel2007 (.xls)
featureBbox.getFeatureOutputFormatRequest = {
header : ''
,filter : exportFilter
,footer : ''
,title : lyr2wms[activeLyr[title].name].replace(featurePrefix + ':','')
};
featureBbox.request(qryBounds,{filterFeatures : filterFeatures});
featureBbox.deactivate();
}
function massgisAddressSearch(query,launchWin) {
if (launchWin) {
launchWin.disable();
}
function zoomToCenter(ctr) {
map.setCenter(ctr);
map.zoomToScale(1000);
var f = lyrGeoLocate.features;
for (var i = 0; i < f.length; i++) {
lyrGeoLocate.removeFeatures(f[i]);
}
lyrGeoLocate.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(ctr.lon,ctr.lat)));
geoLocateLonLat = new OpenLayers.LonLat(ctr.lon,ctr.lat);
}
YUI().use("io",function(Y) {
var handleSuccess = function(ioId,o,args) {
if (window.DOMParser) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(o.responseText,"text/xml");
}
else {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(o.responseText);
}
var x = xmlDoc.getElementsByTagName('X')[0].childNodes[0].nodeValue;
var y = xmlDoc.getElementsByTagName('Y')[0].childNodes[0].nodeValue;
if (x == 'NaN' && y == 'NaN') {
if (launchWin) {
Ext.Msg.alert('Location search results','The address service could not find any matching results.');
launchWin.enable();
}
return;
}
var ctr = new OpenLayers.LonLat(x,y).transform(new OpenLayers.Projection('EPSG:26986'),map.getProjectionObject());
if (launchWin) {
var locationWin = new Ext.Window({
title : 'Location search results'
,width : 325
,height : 200
,plain : true
,modal : true
,layout : 'fit'
,items : [new Ext.FormPanel({
bodyStyle:'padding:5px 5px 0'
,border : false
,items : [{
html : 'The MassGIS service found the following location with ' + xmlDoc.getElementsByTagName('Score')[0].childNodes[0].nodeValue + '% confidence:
' + xmlDoc.getElementsByTagName('MatchedAddress')[0].childNodes[0].nodeValue
,border : false
}]
,buttons : [
{
text : 'Zoom to center point'
,handler : function() {
zoomToCenter(ctr);
locationWin.close();
}
}
,{
text : 'Cancel'
,handler : function() {
locationWin.close();
}
}
]
})]
});
locationWin.show();
launchWin.close();
}
else {
zoomToCenter(ctr);
}
};
Y.on('io:success',handleSuccess,this,[]);
var cfg = {
method : "POST"
,headers : {'Content-Type':'text/xml; charset=UTF-8'}
,data : ' ___ADDR___ ___CITY___ ___ZIP___ ___STATE___ '.replace('___ADDR___',query.street).replace('___CITY___',query.municipality).replace('___ZIP___',query.zipcode).replace('___STATE___',query.state)
,sync : true
};
var request = Y.io(proxyLoc + query.url,cfg);
});
}
function bingAddressSearch(query,launchCmp) {
if (launchCmp) {
launchCmp.disable();
}
function zoomToCenter(loc,bnds,ctr) {
map.setCenter(ctr);
map.zoomToScale(1000);
var f = lyrGeoLocate.features;
for (var i = 0; i < f.length; i++) {
lyrGeoLocate.removeFeatures(f[i]);
}
lyrGeoLocate.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(ctr.lon,ctr.lat)));
geoLocateLonLat = new OpenLayers.LonLat(loc.resourceSets[0].resources[0].point.coordinates[1],loc.resourceSets[0].resources[0].point.coordinates[0]);
}
function zoomToRegion(loc,bnds,ctr) {
map.zoomToExtent(bnds);
var f = lyrGeoLocate.features;
for (var i = 0; i < f.length; i++) {
lyrGeoLocate.removeFeatures(f[i]);
}
lyrGeoLocate.addFeatures(new OpenLayers.Feature.Vector(bnds.toGeometry()));
geoLocateBnds = new OpenLayers.Bounds(loc.resourceSets[0].resources[0].bbox[1],loc.resourceSets[0].resources[0].bbox[0],loc.resourceSets[0].resources[0].bbox[3],loc.resourceSets[0].resources[0].bbox[2]);
}
YUI().use('jsonp', 'jsonp-url', function (Y) {
var handleSuccess = function(o) {
if (!o) {
if (launchCmp) {
Ext.getCmp('searchLocation').enable();
}
return;
}
var loc = o;
if (loc.resourceSets[0].estimatedTotal == 0) {
Ext.Msg.alert('Location search results','The Bing service could not find any matching results.');
if (launchCmp) {
Ext.getCmp('searchLocation').enable();
}
return;
}
var bnds = new OpenLayers.Bounds(loc.resourceSets[0].resources[0].bbox[1],loc.resourceSets[0].resources[0].bbox[0],loc.resourceSets[0].resources[0].bbox[3],loc.resourceSets[0].resources[0].bbox[2]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
var ctr = new OpenLayers.LonLat(loc.resourceSets[0].resources[0].point.coordinates[1],loc.resourceSets[0].resources[0].point.coordinates[0]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
geoLocateLonLat = undefined;
geoLocateBnds = undefined;
var msg = [];
for (var i in loc.resourceSets[0].resources[0].address) {
if (loc.resourceSets[0].resources[0].address[i] !== '') {
msg.push(loc.resourceSets[0].resources[0].address[i]);
}
}
if (query.zoomToCenter) {
zoomToCenter(loc,bnds,ctr);
return;
}
else if (query.zoomToRegion) {
zoomToRegion(loc,bnds,ctr);
return;
}
var locationWin = new Ext.Window({
title : 'Location search results'
,width : 325
,height : 200
,plain : true
,modal : true
,layout : 'fit'
,items : [new Ext.FormPanel({
bodyStyle:'padding:5px 5px 0'
,border : false
,items : [{
html : 'The Bing service found the following location with ' + loc.resourceSets[0].resources[0].confidence + ' confidence:
' + msg.join('
')
,border : false
}]
,buttons : [
{
text : 'Zoom to center point'
,handler : function() {
zoomToCenter(loc,bnds,ctr);
locationWin.close();
}
}
,{
text : 'Zoom to region'
,handler : function() {
zoomToRegion(loc,bnds,ctr);
locationWin.close();
}
}
,{
text : 'Cancel'
,handler : function() {
locationWin.close();
}
}
]
})]
});
locationWin.show();
if (launchCmp) {
launchCmp.enable();
}
}
if (query.text !== '') {
var service = new Y.jsonp('http://dev.virtualearth.net/REST/v1/Locations?jsonp={callback}&key=' + bingKey + '&q=' + encodeURIComponent(query.text),handleSuccess);
}
});
}
function pokeMap() {
// the basemaps may get out of step before a print, so poke it
if (map.getZoom() > 1) {
map.zoomIn();
map.zoomOut();
}
else {
map.zoomOut();
map.zoomIn();
}
}