// WISE Catalog JS script
// 11/2013 LDA
// --------------------------------------------------------------------------------
// Verge handles the viewport stuff
jQuery.extend(verge);
// Set IDs and API key
//var tableId = '1jgyLn5WNUfowx7PUBaVBbsUCjc1_25WOHFYUJNE';// VAlpha
//var tableId = '1ENccb10q_aSfAk9ajBd6Vi-fS3P2ybjpTDlWKtw';//V1.0
//var tableId = '19kxWFSHuEajOO4T-fSMt5hSx6BIJK8mBjVPhjgNy';//V1.1
//var tableId = '11aUj2B6AHcqTOaoVT9g8B5mGu1ZwScfjjonX7fgE';//V1.3
//var tableId = '1WZsLTTTGtncprmVai0klkRRyz2xLq58AflhaibdG';//V1.4
//var tableId = '18eNVm1cIYTPrGDiOXplkNs6b4bdlWv7pvDTHPsg5';//V1.5
//var tableId = '1nh9btE_MGSbMtr425OAXHX3kgPfB8yjgUoA19uKj';//V2.0
//var tableId = '1oHoMb7AhnZ7vrjFTLVTOwV2HdRnLGxggXKkJ4hxl';//V2.1
var tableId = '1FlIpNg4-abl2RSNCM9lpzFI03pnDIbyhA1dwvaIE';//V2.2
//var key = 'AIzaSyAXNHUgX4Sx80hvOllVx8XKQFfxJfTAdMQ';
var key = 'AIzaSyArpKDf-8_9QV5_g1jHn-6LUA-wDLDoVis';
var green_snr_key = '1W2BDpabvownRbKANfHbXYJmqVgPY042_fOoI19ae';
var thor_snr_key = '15iAlN2Uu3-ptqjF7S33H5WKdz2STqoaveO3d0mZz';
var shrds_key = '1jeHw50-0irHxd9SP9H87yJ_XDVgf-E52HFt6_vVj'; // Year 1
var shrds2_key = '1gsukrxXuS6li6NvHifKchQxcntjH25Sn0gTl8qF1'; // Year 2
var cluster_key = '1sFpoSkcJ9NOUv3bqMn1PlTuMV9FH3AYj6EIkonfG';
var pulsar_key = '1VJrGJXoSOxClFGc52DhoeZB2urWPAVHIO-MMkD-Y';
var gotcplus_key = '1TX27Ze6pxhBXubff_uWNd7Imq0CobZbmHgyCP35J';
var radioQuiet_key = '1CmGo7lYL9aV1uSMHthK_HspbrbWZmzsSMe-cHfCB';
// Define global vars
var map, circleobj, rectangleobj, data, chartData, table, tableOptions, view, chart, chartOptions, where, drawingManager, currCenter, overlay, aladin, HII_Data;
var markersArray = [];
var rmsArray = [];
var bronfmanArray = [];
var mwp_smallArray = [];
var mwp_largeArray = [];
// other layers
/*var other_layers = [];
other_layers[0] = new google.maps.FusionTablesLayer({
});
other_layers[1] = new google.maps.FusionTablesLayer({
});
other_layers[2] = new google.maps.FusionTablesLayer({
});
other_layers[3] = new google.maps.FusionTablesLayer({
});
other_layers[4] = new google.maps.FusionTablesLayer({
});*/
// Define table options
var tableOptions = {
'showRowNumber': true,
'width': '100%',
'frozenColumns': 2,
'allowHtml': true,
'page': 'enable',
'pageSize': 100,
'pagingSymbols': {prev: 'Previous', next: 'Next'}
};
// Define chart options
var chartOptions = {
'width': '100%',
histogram: {bucketSize:5},
title: 'LV Test',
pointSize: 1,
explorer: { actions: ['dragToZoom', 'rightClickToReset'] },
tooltip: {trigger: 'none'},
vAxis: {
// title: 'Number'
title: 'VLSR',
viewWindow: {
min: -250,
max: +250
}
},
hAxis: {
title: 'GLong',
direction: -1,
viewWindow: {
min: -180,
max: +180
}
}
};
// PHP Get
$_GET=function(key,def){
try{
// Try the coordinates and zoom
if (key=='l' || key=='b' || key=='zoom') {
var input = parseFloat(RegExp('[?&;]'+key+'=([^?]*)').exec(location.href)[1])
if (isNaN(input)) {
alert("Input " + RegExp('[?&;]'+key+'=([^?]*)').exec(location.href)[1] + " not recognized.");
return def;
} else {
return input;
};
} else {
var input = RegExp('[?&;]'+key+'=([^?]*)').exec(location.href)[1];
input = decodeURIComponent(input);
return input;
}
}catch(e){
return def||0
};
}
// Define Google map options
var mapOptions = {
panControl: true,
isPng: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.DEFAULT,
},
mapTypeControl: true,
overviewMapControl: true,
overviewMapControlOptions: {
opened: false
},
scaleControl: false,
streetViewControl: false,
center: new google.maps.LatLng(parseFloat($_GET('b', 0)), transformLng(parseFloat($_GET('l', 0)))),
zoom: parseFloat($_GET('zoom', 5)),
// fontsize: 10pt,
mapTypeControlOptions: {
mapTypeIds: ['Spitzer', 'GLIMPSE360', 'WISE', 'IGPS 21cm', 'Dame+ 12CO', 'GRS 13CO', 'ATLASGAL'],
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
}; // mapOptions
// Load table visualization
google.load('visualization', '1', { packages: ['table', 'corechart'] });
//google.load('visualization', '1', { packages: ['table', 'scatter'] });
// Add initialize function
google.maps.event.addDomListener(window, 'load', initialize);
google.setOnLoadCallback(drawTable);
google.setOnLoadCallback(drawChart);
/* ************************************************************************************** */
// Called on load
function initialize() {
// Set the sizes of the various divs
setSizes();
// Normalizes the coords that tiles repeat across the x axis (horizontally)
// like the standard Google map tiles.
function getNormalizedCoord(coord, zoom) {
var y = coord.y;
var x = coord.x;
console.log(coord);// tile range in one direction range is dependent on zoom level
// 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
var tileRange = 1 << zoom;
// don't repeat across y-axis (vertically)
if (y < 0 || y >= tileRange) {
return null;
}
// repeat across x-axis
if (x < 0 || x >= tileRange) {
x = (x % tileRange + tileRange) % tileRange;
}
return {
x: x,
y: y
}
};
// Define custom tile options
var typeOptionsSpitzer = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'glimpse_mosaic' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 11,
minZoom: 0,
name: 'Spitzer'
};
var typeOptionsGLIMPSE360 = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'glimpse360' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 11,
minZoom: 0,
name: 'GLIMPSE360'
};
var typeOptionsWISE = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'wise_rgb_small' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 8,
minZoom: 0,
name: 'WISE'
};
var typeOptionsDame = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'Wco_DHT2001' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 10,
minZoom: 0,
name: 'Dame+ 12CO'
};
var typeOptionsGRS = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'grs_mosaic' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 11,
minZoom: 0,
name: 'GRS 13CO'
};
var typeOptionsIGPS = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'igps_mosaic' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 10,
minZoom: 0,
name: 'IGPS 21cm'
};
var typeOptionsATLASGAL = {
getTileUrl: function (coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return filename = 'eso1606a' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 10,
minZoom: 0,
name: 'ATLASGAL'
};
var typeOptionsHiGal = {
getTileUrl: function(coord, zoom) {
zoom = zoom-1;
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
console.log(bound);
var url = TILE_URL
.replace('{x}', coord.x)
.replace('{y}', coord.y)
.replace('{z}', zoom);
return url;
return filename = 'higal' + '/' + zoom + '/' + normalizedCoord.x + '/' + (bound - normalizedCoord.y - 1) + '.png';
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
maxZoom: 11,
minZoom: 0,
name: 'Hi-Gal'
};
// Get Data
HII_Data = getData();
addData(map);
// Create map
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
$('
').addClass('centerMarker').appendTo(map.getDiv());
var mapTypeHiGal = new google.maps.ImageMapType(typeOptionsHiGal);
map.mapTypes.set('Hi-Gal', mapTypeHiGal);
map.setMapTypeId('Hi-Gal');
var mapTypeATLASGAL = new google.maps.ImageMapType(typeOptionsATLASGAL);
map.mapTypes.set('ATLASGAL', mapTypeATLASGAL);
map.setMapTypeId('ATLASGAL');
var mapTypeGRS = new google.maps.ImageMapType(typeOptionsGRS);
map.mapTypes.set('GRS 13CO', mapTypeGRS);
map.setMapTypeId('GRS 13CO');
var mapTypeDame = new google.maps.ImageMapType(typeOptionsDame);
map.mapTypes.set('Dame+ 12CO', mapTypeDame);
map.setMapTypeId('Dame+ 12CO');
var mapTypeIGPS = new google.maps.ImageMapType(typeOptionsIGPS);
map.mapTypes.set('IGPS 21cm', mapTypeIGPS);
map.setMapTypeId('IGPS 21cm');
var mapTypeWISE = new google.maps.ImageMapType(typeOptionsWISE);
map.mapTypes.set('WISE', mapTypeWISE);
map.setMapTypeId('WISE');
var mapTypeGLIMPSE360 = new google.maps.ImageMapType(typeOptionsGLIMPSE360);
map.mapTypes.set('GLIMPSE360', mapTypeGLIMPSE360);
map.setMapTypeId('GLIMPSE360');
var mapTypeSpitzer = new google.maps.ImageMapType(typeOptionsSpitzer);
map.mapTypes.set('Spitzer', mapTypeSpitzer);
map.setMapTypeId('Spitzer');
// Set map based on user input through PhP
var survey = $_GET('survey', 0);
switch(survey) {
case 0:
map.setMapTypeId('Spitzer');
break;
case 1:
map.setMapTypeId('GLIMPSE360');
break;
case 2:
map.setMapTypeId('WISE');
break;
case 3:
map.setMapTypeId('IGPS 21cm');
break;
case 4:
map.setMapTypeId('Dame+ 12CO');
break;
case 5:
map.setMapTypeId('GRS 13CO');
break;
case 6:
map.setMapTypeId('ATLASGAL');
break;
case 7:
map.setMapTypeId('Hi-Gal');
break;
}
// Add HII markers
// Create Fusion Table Layer
/*layer = new google.maps.FusionTablesLayer({
map: map,
suppressInfoWindows: false,
clickable: true,
query: {
select: 'geometry',
from: tableId
},
styles: [{
polygonOptions: {
fillOpacity: 0.03,
strokeWeight: 2,
}
}, {
where: "'Catalog' = 'K'",
polygonOptions: {
strokeColor: "FF0000",
fillColor: "FF0000"
}
}, {
where: "'Catalog' = 'G'",
polygonOptions: {
strokeColor: "12E603",
fillColor: "12E603"
}
}, {
where: "'Catalog' = 'C'",
polygonOptions: {
strokeColor: "00CCFF",
fillColor: "00CCFF"
}
}, {
where: "'Catalog' = 'Q'",
polygonOptions: {
strokeColor: "CCFF00",
fillColor: "CCFF00"
}
}, {
where: "'Catalog' = '?'",
polygonOptions: {
strokeColor: "333333",
fillColor: "333333"
}
}]
}); // Fusion Table Layer
// Fusion tips
layer.enableMapTips({
key:key, // replace with a key valid for your domain.
select: "'WISE Name', 'HII Region'", // list of columns to query, typially need only one column.
from: tableId, // fusion table name
geometryColumn: 'geometry', // geometry column name
// style: style,
suppressMapTips: false, // optional, whether to show map tips. default false
delay: 0, // milliseconds mouse pause before send a server query. default 300.
tolerance: 4 // tolerance in pixel around mouse. default is 6.
});
*/
var contextMenu = google.maps.event.addListener(
map,
"rightclick",
function( event ) {
showCoordinates( event );
}
);
// var aladin = A.aladin("#aladin", {survey: "P/allWISE/color", fov:0.25, cooFrame: "galactic"});
// This is the overlay, which allows us to compute coordinates over the fusion table layer
var overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map);
// Create drawing manager to handle user drawn cone and area searches
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.NULL,
drawingControl: false,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
},
circleOptions: {
fillOpacity: 0.1,
strokeOpacity: 0.5,
strokeWeight: 1,
draggable: false,
clickable: false,
editable: true,
visible: true,
},
rectangleOptions: {
fillOpacity: 0.1,
strokeOpacity: 0.5,
strokeWeight: 1,
draggable: false,
clickable: false,
editable: true,
visible: true,
}
});
drawingManager.setMap(map);
// Create legend
var legend = document.getElementById('legend');
map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(legend);
var lb = document.getElementById('lb');
map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(lb)
// Listeners
// New Circle
google.maps.event.addListener(drawingManager, 'circlecomplete', function(circle) {
if (circleobj !== undefined) {
circleobj.setMap(null)
};
circleobj = circle;
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.NULL);
// Update boxes
$( "#removecirclebutton").prop('disabled', false);
var center = circleobj.getCenter();
lng = transformLng(center.lng());
lat = center.lat();
document.getElementById('circle_lng').value = lng.toFixed(3);
document.getElementById('circle_lat').value = lat.toFixed(3);
var radius = circleobj.getRadius() / 111321. * 60; //converts to arcmin
document.getElementById('circle_radius').value = radius.toFixed(1);
// Filter the map based on the circle
where = generateWhere();
drawTable();
drawChart();
google.maps.event.addListener(circleobj, 'center_changed', function() {
var center = circleobj.getCenter();
lng = transformLng(center.lng());
lat = center.lat();
document.getElementById('circle_lng').value = lng.toFixed(3);
document.getElementById('circle_lat').value = lat.toFixed(3);
where = generateWhere();
drawTable();
drawChart();
});
google.maps.event.addListener(circleobj, 'radius_changed', function() {
var radius = circleobj.getRadius() / 111321. * 60; //converts to arcmin
document.getElementById('circle_radius').value = radius.toFixed(1);
where = generateWhere();
drawTable();
drawChart();
});
});
// New Rectangle
google.maps.event.addListener(drawingManager, 'rectanglecomplete', function(rectangle) {
if (rectangleobj !== undefined) {
rectangleobj.setMap(null)
};
rectangleobj = rectangle;
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.NULL);
// Update boxes
$( "#areasearchbutton").prop('disabled', false);
$( "#removerectanglebutton").prop('disabled', false);
var bounds = rectangleobj.getBounds();
ne = bounds.getNorthEast();
sw = bounds.getSouthWest();
ne_lng = transformLng(ne.lng());
ne_lat = ne.lat();
sw_lng = transformLng(sw.lng());
sw_lat = sw.lat();
document.getElementById('ne_glong').value = ne_lng.toFixed(3);
document.getElementById('ne_glat').value = ne_lat.toFixed(3);
document.getElementById('sw_glong').value = sw_lng.toFixed(3);
document.getElementById('sw_glat').value = sw_lat.toFixed(3);
where = generateWhere();
drawTable();
drawChart();
// Add event listener to new rectangle
google.maps.event.addListener(rectangleobj, 'bounds_changed', function() {
var bounds = rectangleobj.getBounds();
ne = bounds.getNorthEast();
sw = bounds.getSouthWest();
ne_lng = transformLng(ne.lng());
ne_lat = ne.lat();
sw_lng = transformLng(sw.lng());
sw_lat = sw.lat();
document.getElementById('ne_glong').value = ne_lng.toFixed(3);
document.getElementById('ne_glat').value = ne_lat.toFixed(3);
document.getElementById('sw_glong').value = sw_lng.toFixed(3);
document.getElementById('sw_glat').value = sw_lat.toFixed(3);
where = generateWhere();
drawTable();
drawChart();
});
});
// Custom InfoWindow
google.maps.event.addListener(layer, 'click', function(e) {
e.infoWindowHtml = 'WISE Name: ' + e.row['WISE Name'].value + "
"
+ 'Catalog: ' + e.row['Catalog'].value + "
"
// + 'GLong: ' + e.row['GLong'].value + "
"
// + 'GLat: ' + e.row['GLat'].value + "
"
+ 'Radius (arcsec): ' + e.row['Radius
(arcsec.)'].value + "
"
+ 'HII Region: ' + e.row['HII Region'].value + "
"
+ 'Membership: ' + e.row['Membership'].value + "
"
+ 'VLSR (km/s): ' + e.row['VLSR
(km/s)'].value + "
"
+ 'KDAR: ' + e.row['KDAR'].value + "
"
+ 'Distance (kpc): ' + e.row['Dist.
(kpc)'].value + "
"
+ 'RGal (kpc): ' + e.row['RGal
(kpc)'].value + "
";
});
// Longitude and Latitude cursor position
google.maps.event.addDomListener(document.getElementById('map-canvas'), 'mousemove', function(event) {
// Get position offsets
var target = document.getElementById('map-canvas');
posx = event.pageX - target.offsetLeft; // should be zero offset left
posy = event.pageY - target.offsetTop;
// Compute new longitude and latitude
var newLatLng = overlay.getProjection().fromContainerPixelToLatLng(new google.maps.Point(posx, posy));
updateLatLng(newLatLng)
});
google.maps.event.addDomListener(document.getElementById('map-canvas'), 'rightclick', function(event) {
alert('hu');
});
// Removed because above works for all positions
// Mouse longitude and latitude
// google.maps.event.addListener(map, 'mousemove', function (event) {
// var newLatLng = event.latLng;
// updateLatLng(newLatLng)
// });
// kept this because may be nice to have exact coords when infoWindow event fired
google.maps.event.addListener(layer, 'click', function (event) {
var newLatLng = event.latLng;
updateLatLng(newLatLng)
});
// Catalogs checkmarks
google.maps.event.addDomListener(document.getElementById('Catalogs'), 'click', function () {
where = generateWhere();
drawTable();
drawChart();
});
// Authors checkmarks
google.maps.event.addDomListener(document.getElementById('Authors'), 'click', function () {
where = generateWhere();
drawTable();
drawChart();
});
// Column checkmarks
google.maps.event.addDomListener(document.getElementById('Columns'), 'click', function () {
toggleColumns();
});
// Correlations checkmarks
// google.maps.event.addDomListener(document.getElementById('Correlations'),
// 'click', function () {
// where = generateWhere();
// drawTable();
// });
//********************************************
// File upload
$("#filename").change(function(e) {
var ext = $("input#filename").val().split(".").pop().toLowerCase();
if($.inArray(ext, ["csv"]) == -1) {
alert('Upload must have extension .csv');
return false;
}
if (e.target.files != undefined) {
var allTextLines = e.split(/\r\n|\n/);
var headers = allTextLines[0].split(',');
var lines = [];
for (var i=1; i -8) && (latlong[1] < 8)
&& (latlong[0] < 360) && (latlong[0] > -360)) {
// Go to location
latlong = new google.maps.LatLng(latlong[1], transformLng(latlong[0]));
map.panTo(latlong)
};
};
/* ************************************************************************************** */
// Remove circle
function removeCircle() {
circleobj.setVisible(false);
$( "#consearchbutton").prop('disabled', true);
$( "#removecirclebutton").prop('disabled', true);
// Update boxes
// document.getElementById('circle_lng').value = '';
// document.getElementById('circle_lat').value = '';
// document.getElementById('circle_radius').value = ''
where = generateWhere();
drawTable();
drawChart();
}
// Remove rectangle
function removeRectangle() {
rectangleobj.setVisible(false);
$( "#areasearchbutton").prop('disabled', true);
$( "#removerectanglebutton").prop('disabled', true);
// document.getElementById('ne_glong').value = '';
// document.getElementById('ne_glat').value = '';
// document.getElementById('sw_glong').value = '';
// document.getElementById('sw_glat').value = '';
where = generateWhere();
drawTable();
drawChart();
}
/* ************************************************************************************** */
// Draw circle
function drawNewCircle() {
// Attach drawing manager
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.CIRCLE);
};
// Draw rectangle
function drawNewRectangle() {
// Attach drawing manager
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.RECTANGLE);
};
/* ************************************************************************************** */
// Update the heatmap property of the FusionTablesLayer when the checkbox value changes.
function updateHeatmap() {
var heatmap = document.getElementById('heatmap');
layer.setOptions({
heatmap: {
enabled: heatmap.checked
}
});
};
/* ************************************************************************************** */
// Highlight selected markers - not begun
function highlight() {
};
/* ************************************************************************************** */
// Go to location as defined by selected regions
function gotoSelection() {
var selection = table.getSelection();
if (selection.length > 0) {
var bounds = new google.maps.LatLngBounds();
// Find GLong and GLat columns
for (var i = 0; i < data.getNumberOfColumns(); i++) {
var colName = data.getColumnLabel(i);
if (colName == "GLong
(deg.)") {
var nGLong = i
};
if (colName == "GLat
(deg.)") {
var nGLat = i
};
if (colName == "Radius
(arcsec.)") {
var nRadius = i
};
};
// Loop through all selected rows
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
var glong = transformLng(data.getFormattedValue(item.row, nGLong));
var glat = data.getFormattedValue(item.row, nGLat);
var latlong = new google.maps.LatLng(glat, glong);
bounds.extend(latlong);
};
// Go to location
if (selection.length == 1) {
map.panTo(latlong);
// map.setZoom(9)
} else {
map.fitBounds(bounds);
// map.setZoom(map.getZoom()+1);
};
};
};
/* ************************************************************************************** */
// Generate a where clause user inputs
function generateWhere() {
var where = '';
// Catalogs
var catalogs = document.getElementsByName('Catalog');
var filter = [];
for (var i = 0, catalog; catalog = catalogs[i]; i++) {
if (catalog.checked) {
var catalogName = catalog.value.replace(/'/g, '\\\'');// ' Needed for better emacs formatting
filter.push("'" + catalogName + "'");
}
}
if (filter.length) {
where = "'Catalog' IN (" + filter.join(',') + ')';
}
// Authors
var authors = document.getElementsByName('Author');
var filter = [];
for (var i = 0, author; author = authors[i]; i++) {
if (!author.checked) {
var authorName = author.id;
filter.push("'" + authorName + "'");
}
}
if (filter.length) {
if (where.length) {
where += ' AND '
}
where += "'Author' NOT IN (" + filter.join(',') + ')';
}
// Cone
if (circleobj !== undefined) {
if (circleobj.getVisible()) {
if (where.length) {
where += ' AND '
}
where += 'ST_INTERSECTS(geometry, ' +
'CIRCLE(LATLNG' + circleobj.getCenter() + ',' +
circleobj.getRadius() + '))'
}
};
// Rectangle
if (rectangleobj !== undefined) {
if (rectangleobj.getVisible()) {
if (where.length) {
where += ' AND '
}
where += 'ST_INTERSECTS(geometry, RECTANGLE(' +
'LATLNG' + rectangleobj.getBounds().getSouthWest() + ',' +
'LATLNG' + rectangleobj.getBounds().getNorthEast() + '))'
}
};
// Conditional statements
var value1Val = document.getElementById('value1').value;
// Should also test for non-printing chars
if ( value1Val ) {
var e = document.getElementById('field1');
var field1Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition1');
var conditions1Val = e.options[e.selectedIndex].value;
var value1Val = document.getElementById('value1').value;
if (where.length) {
where += ' AND '
}
where += field1Val + ' ' + conditions1Val + ' ' + value1Val;
};
var value2Val = document.getElementById('value2').value;
// Should also test for non-printing chars
if ( value2Val ) {
var e = document.getElementById('field2');
var field2Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition2');
var conditions2Val = e.options[e.selectedIndex].value;
var value2Val = document.getElementById('value2').value;
if (where.length) {
where += ' AND '
}
where += field2Val + ' ' + conditions2Val + ' ' + value2Val;
}
var value3Val = document.getElementById('value3').value;
// Should also test for non-printing chars
if ( value3Val ) {
var e = document.getElementById('field3');
var field3Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition3');
var conditions3Val = e.options[e.selectedIndex].value;
var value3Val = document.getElementById('value3').value;
if (where.length) {
where += ' AND '
}
where += field3Val + ' ' + conditions3Val + ' ' + value3Val;
};
var value4Val = document.getElementById('value4').value;
// Should also test for non-printing chars
if ( value4Val ) {
var e = document.getElementById('field4');
var field4Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition4');
var conditions4Val = e.options[e.selectedIndex].value;
var value4Val = document.getElementById('value4').value;
if (where.length) {
where += ' AND '
}
where += field4Val + ' ' + conditions4Val + ' ' + value4Val;
};
var value5Val = document.getElementById('value5').value;
// Should also test for non-printing chars
if ( value5Val ) {
var e = document.getElementById('field5');
var field5Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition5');
var conditions5Val = e.options[e.selectedIndex].value;
var value5Val = document.getElementById('value5').value;
if (where.length) {
where += ' AND '
}
where += field5Val + ' ' + conditions5Val + ' ' + value5Val;
};
var value6Val = document.getElementById('value6').value;
// Should also test for non-printing chars
if ( value6Val ) {
var e = document.getElementById('field6');
var field6Val = e.options[e.selectedIndex].text;
var e = document.getElementById('condition6');
var conditions6Val = e.options[e.selectedIndex].value;
var value6Val = document.getElementById('value6').value;
if (where.length) {
where += ' AND '
}
where += field6Val + ' ' + conditions6Val + ' ' + value6Val;
};
document.getElementById('sql').value = where;
where = fix_where( where, true ); // add second header
return where;
}
/* ************************************************************************************** */
function generateQuery( columns, thisWhere ) {
var query = 'SELECT ' + columns + ' FROM ' + tableId;
// Add where statement
if ((typeof where) == "string") {
query += ' WHERE ' + where
};
// Check if where statement passed
/* if ((typeof thisWhere) == "string") {
if ((typeof where) == "string") {
query += thisWhere;
} else {
query += ' WHERE ' + thisWhere
};
};*/
var encodedQuery = encodeURIComponent(query);
return encodedQuery;
}
/* ************************************************************************************** */
// Change visibility of area search panels
function circleVisible() {
if (circleobj) {
// circleobj.setVisible(true);
// rectangleobj.setVisible(false);
$( "#coneSearch" ).slideDown('slow');
$( "#areaSearch" ).slideUp('slow');
where = generateWhere();
drawTable();
drawChart();
} else {
$( "#coneSearch" ).slideDown('slow');
$( "#areaSearch" ).slideUp('slow');
drawNewCircle()
}
};
function rectangleVisible() {
if (rectangleobj) {
// circleobj.setVisible(false);
// rectangleobj.setVisible(true);
$( "#coneSearch" ).slideUp('slow');
$( "#areaSearch" ).slideDown('slow');
where = generateWhere();
drawTable();
drawChart();
} else {
$( "#coneSearch" ).slideUp('slow');
$( "#areaSearch" ).slideDown('slow');
drawNewRectangle()
}
};
function noneVisible() {
if (circleobj !== undefined) {
circleobj.setVisible(false)
};
if (rectangleobj !== undefined) {
rectangleobj.setVisible(false)
};
$( "#consearchbutton").prop('disabled', true);
$( "#removecirclebutton").prop('disabled', true);
$( "#removerectanglebutton").prop('disabled', true);
$( "#coneSearch" ).slideUp('slow');
$( "#areaSearch" ).slideUp('slow');
where = generateWhere();
drawTable();
drawChart();
};
/* ************************************************************************************** */
// For the tabs
$(function() {
$( "#tabs" ).tabs();
});
/* ************************************************************************************** */
function createURL( encodedQuery, prettyPrint ) {
var url = ['https://www.googleapis.com/fusiontables/v2/query'];
url.push('?sql=' + encodedQuery);
if (prettyPrint == 'true') {
url.push('&alt=csv');
}
url.push('&key=' + key);
console.log(url);
return url;
};
/* ************************************************************************************** */
function exportCsv() {
var columns ="'WISE Name', 'Catalog', 'GLong
(deg.)', 'GLat
(deg.)', 'Radius
(arcsec.)', 'HII Region', 'Membership', 'VLSR
(km/s)', 'Author', 'VLSR (Mol.)
(km/s)', 'Molecule', 'KDAR', 'Dist.
(kpc)', 'Err Dist.
(kpc)', 'Dist. Method', 'RGal
(kpc)', 'z
(pc)', 'GLIMPSE 8um
(Jy)', 'WISE 12um
(Jy)', 'WISE 22um
(Jy)', 'MIPSGAL 24um
(Jy)', 'Hi-Gal 70um
(Jy)', 'Hi-Gal 160um
(Jy)', 'HRDS 3cm
(Jy)', 'MAGPIS 20cm
(Jy)', 'VGPS 21cm
(Jy)'";
var encodedQuery = generateQuery( columns, where );
// Construct the URL to grab the data
url = createURL( encodedQuery, 'true' );
// Download the file
window.open(url.join(''), ' ');
};
/* ************************************************************************************** */
// Search based on cone parameters
function coneSearch(e) {
var evt = e || window.event
// "e" is the standard behavior (FF, Chrome, Safari, Opera),
// while "window.event" (or "event") is IE's behavior
if ( evt.keyCode === 13 ) {
if (circleobj !== undefined) {
if (circleobj.getVisible()) {
circleobj.setRadius(document.getElementById('circle_radius').value / 60 * 111321);
circleobj.setCenter(new google.maps.LatLng(
document.getElementById('circle_lat').value,
transformLng(document.getElementById('circle_lng').value)))
}
where = generateWhere();
drawTable();
drawChart();
} else {
var rad = document.getElementById('circle_radius').value / 60 * 111321 ;
circleobj = new google.maps.Circle({
center: new google.maps.LatLng(
document.getElementById('circle_lat').value,
transformLng(document.getElementById('circle_lng').value)),
radius: rad,
map: map,
fillOpacity: 0.1,
strokeOpacity: 0.5,
strokeWeight: 1,
draggable: true,
editable: true,
visible: false
});
where = generateWhere();
drawTable();
drawChart();
}
}
};
/* ************************************************************************************** */
// Search based on area parameters
function areaSearch() {
var evt = e || window.event
// "e" is the standard behavior (FF, Chrome, Safari, Opera),
// while "window.event" (or "event") is IE's behavior
if ( evt.keyCode === 13 ) {
if (circleobj !== undefined) {
if (rectangleobj.getVisible()) {
rectangleobj.setBounds(new google.maps.LatLngBounds(
new google.maps.LatLng(
document.getElementById('sw_glat').value,
transformLng(document.getElementById('sw_glong').value)),
new google.maps.LatLng(
document.getElementById('ne_glat').value,
transformLng(document.getElementById('ne_glong').value))))
}
where = generateWhere();
drawTable();
drawChart();
}
}
};
/* ************************************************************************************** */
// Changes from map to astronomical longitudes
function transformLng(lng) {
lng = -lng;
if (lng < 0) {
lng = lng + 360;
};
return lng
};
/* ************************************************************************************** */
// Updates the latlong input box
function updateLatLng(latLng) {
var lat = latLng.lat();
var lng = transformLng(latLng.lng());
document.getElementById('latlong').value = lng.toFixed(3) + ', ' + lat.toFixed(3)
}
function toggleLegend() {
$( "#legend_symbols" ).slideToggle();
}
function toggleLB() {
$( "#latlong" ).slideToggle();
}
/* ************************************************************************************** */
// Longitude, latitude entered
function lb_enter( e ) {
var evt = e || window.event
// "e" is the standard behavior (FF, Chrome, Safari, Opera),
// while "window.event" (or "event") is IE's behavior
if ( evt.keyCode === 13 ) {
var latlong_str = document.getElementById('latlong').value.split(',');
if (latlong_str.length == 1) {
latlong_str = document.getElementById('latlong').value.split(' ');
};
// Turn into float
var latlong = [parseFloat(latlong_str[0]), parseFloat(latlong_str[1])];
if ((latlong.length == 2) && (latlong[1] > -8) && (latlong[1] < 8)
&& (latlong[0] < 360) && (latlong[0] > -360)) {
// Go to location
latlong = new google.maps.LatLng(latlong[1], transformLng(latlong[0]));
map.panTo(latlong)
};
// You can disable the form submission this way:
return false
}
};
/* ************************************************************************************** */
// Fixes columns to add/remove second headers and quotes
function fix_where( where, add ) {
if ( add ) {
where = where.replace("WISE Name", "WISE Name");
where = where.replace("Catalog", "Catalog");
where = where.replace("GLat", "'GLat
(deg.)'");
where = where.replace(/GLong/g, "'GLong
(deg.)'");
where = where.replace("Radius", "Radius
(arcsec.)");
where = where.replace("HII Region", "HII Region");
where = where.replace("Membership", "Membership");
where = where.replace("VLSR", "'VLSR
(km/s)'");
where = where.replace("Author", "Author");
where = where.replace("VLSR (Mol.)", "'VLSR (Mol.)
(km/s)'");
where = where.replace("Molecule", "Molecule");
where = where.replace("KDAR", "KDAR");
where = where.replace("Dist.", "'Dist.
(kpc)'");
where = where.replace("Err Dist.", "Err Dist.
(kpc)");
where = where.replace("Dist. Method", "Dist. Method");
where = where.replace("RGal", "RGal
(kpc)");
where = where.replace("z", "z
(pc)");
where = where.replace("GLIMPSE 8um", "GLIMPSE 8um
(Jy)");
where = where.replace("WISE 12um", "WISE 12um
(Jy)");
where = where.replace("WISE 22um", "WISE 22um
(Jy)");
where = where.replace("MIPSGAL 24um", "MIPSGAL 24um
(Jy)");
where = where.replace("Hi-Gal 70um", "Hi-Gal 70um
(Jy)");
where = where.replace("Hi-Gal 160um", "Hi-Gal 160um
(Jy)");
where = where.replace("HRDS 3cm", "HRDS 3cm
(Jy)");
where = where.replace("MAGPIS 20cm", "MAGPIS 20um
(Jy)");
where = where.replace("VGPS 21cm", "VGPS 21cm
(Jy)");
} else {
where = where.replace("GLat
(deg.)", "GLat");
}
return where
}
/* ************************************************************************************** */
// Direct SQL query
function sql_enter( e ) {
var evt = e || window.event;
// "e" is the standard behavior (FF, Chrome, Safari, Opera),
// while "window.event" (or "event") is IE's behavior
if ( evt.keyCode === 13 ) {
var sqlVal = document.getElementById('sql').value;
where = sqlVal;
where = fix_where( where, true );
console.log(where);
drawTable();
drawChart();
// You can disable the form submission this way:
return false
}
};
/* ************************************************************************************** */
// Conditions
function conditions_enter( e ) {
var evt = e || window.event;
if ( evt.keyCode === 13 ) {
// Filter based on preferences
where = generateWhere();
drawTable();
drawChart();
// You can disable the form submission this way:
return false
}
};
/* ************************************************************************************** */
// Table line selected
function selectHandler() {
var item = "";
var query;
var vals;
var selection = table.getSelection();
if (selection.length > 0) {
$( "#goToSelection" ).prop('disabled', false);
for (var i = 0; i < selection.length; i++) {
var row = selection[i].row;
item = data.getValue(row,0);
if (vals) {
vals += ", '" + item + "'"
} else {
vals = "'" + item + "'"
}
}
query = "'WISE Name' IN (" + vals + ")"
layer.setOptions({
query: {
select: 'geometry',
from: tableId,
where: query
}
})
} else {
$( "#goToSelection" ).prop('disabled', true);
layer.setOptions({
query: {
select: 'geometry',
from: tableId
}
})
}
}
/* ************************************************************************************** */
// Search
function search_enter( e ) {
var evt = e || window.event;
if ( evt.keyCode === 13 ) {
// Filter based on preferences
var searchVal = document.getElementById('searchInput').value;
var e = document.getElementById('searchOptions');
// Do search
// Construct query
where = "'Other Names' CONTAINS IGNORING CASE '" + searchVal + "'"
drawTable();
drawChart();
// You can disable the form submission this way:
return false
}
};
/* ************************************************************************************** */
// Upload File
function uploadFile() {
var data;
$.ajax({
type: "post",
url: "upload.php",
data: data,
success: function (response) {
alert(JSON.stringify(data));
},
error: function () {
alert("failure");
},
});
}
/* ************************************************************************************** */
function showMarkers(filename, in_glat, in_glong, in_title) {
var button = document.getElementById(filename);
var infowindow = new google.maps.InfoWindow({
minWidth: 300
});
switch(filename)
{
case "bronfman":
markersArray = bronfmanArray;
break;
case "rms":
markersArray = rmsArray;
break;
case "mwp_small":
markersArray = mwp_smallArray;
break;
case "mwp_large":
markersArray = mwp_largeArray;
break;
}
if (button.checked) {
if (markersArray.length>0) {
for (i in markersArray) {
markersArray[i].setVisible(true);
}
switch(filename)
{
case "bronfman":
bronfmanArray = markersArray;
break;
case "rms":
rmsArray = markersArray;
break;
case "mwp_small":
mwp_smallArray = markersArray;
break;
case "mwp_large":
mwp_largeArray = markersArray;
break;
}
markersArray = [];
} else {
$.getJSON(filename + '.txt', function(data) {
$.each(data.data, function(index) {
// var posString = data.data[index][in_glong]
// var posString = posString.replace(/"/g, '')
// var posString = posString.replace(/{/g, '')
// var posString = posString.replace(/}/g, '')
// var posString_Arr = posString.split(',')
//var posString_Arr = "d";
// var latLng = new google.maps.LatLng(parseFloat(posString_Arr[1]), transformLng(parseFloat(posString_Arr[0])));
var latLng = new google.maps.LatLng(0,0);
// var content = data.data[index][in_title] + ' ' + data.data[index][in_title-3].toString();
// var content = 'Type:' + data.data[index][in_title] + '
' + 'Distance:' + parseFloat(data.data[index][10]).toString();
var pinImage = new google.maps.MarkerImage(filename + ".png",
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
// Create marker
marker = new google.maps.Marker({
position: latLng,
// title: content,
map: map,
clickable: true,
icon: pinImage
});
// Add marker to array
markersArray.push(marker);
// Add listener. Must be done this way because of cloture
// google.maps.event.addListener(marker, 'click', (function(marker) {
// return function() {
// infowindow.setContent(marker.getTitle());
// infowindow.open(map, marker);
// }
// })(marker));
});
});
switch(filename)
{
case "bronfman":
bronfmanArray = markersArray;
break;
case "rms":
rmsArray = markersArray;
break;
case "mwp_small":
mwp_smallArray = markersArray;
break;
case "mwp_large":
mwp_largeArray = markersArray;
break;
markersArray = [];
}
};
} else {
switch(filename)
{
case "bronfman":
markersArray = bronfmanArray;
bronfmanArray = [];
break;
case "rms":
markersArray = rmsArray;
rmsArray = [];
break;
case "mwp_small":
markersArray = mwp_smallArray;
mwp_smallArray = [];
break;
case "mwp_large":
markersArray = mwp_largeArray;
mwp_largeArray = [];
break;
markersArray = [];
}
for (i in markersArray) {
markersArray[i].setVisible(false);
}
};
};
/* ************************************************************************************** */
// Note: Cannot do dynamic styles due to fusion tables limitation! Do not try! Must use styleid
function toggleLayer(index, layer_key) {
if(other_layers[index].getMap(layer_key)==null){
other_layers[index] = new google.maps.FusionTablesLayer({
map: map,
clickable: true,
query: {
select: 'geometry',
from: layer_key
},
styleId: 2,
templateId: 2
});
} else {
other_layers[index].setMap(null);
};
}
/* ************************************************************************************** */
// Get data from database, in google data structure format
function getData(columns, thisWhere, table, callback) {
// Select Columns
var encodedQuery = generateQuery( columns, thisWhere );
// Construct the URL to grab the data
url = createURL( encodedQuery, 'false' );
// Get the variables from the table
$.ajax({
url: url.join(''),
dataType: 'json',
jsonp: 'jsonCallback',
success: function (jsonData) {
// First let's update map so user knows things are happening
if (table) {
if (!layer.getMap()) {
layer.setMap(map);
}
layer.setOptions({
query: {
select: "'Catalog', 'geometry'",
from: tableId,
where: where
}
});
// Now update the table
if (!(jsonData.error) && jsonData.rows !== undefined) {
$( ".google-visualization-table-tr-even" ).show();
$( ".google-visualization-table-tr-odd" ).show();
$( ".google-visualization-table-div-page" ).show();
};
};
if (!(jsonData.error) && jsonData.rows !== undefined) {
var rows = jsonData.rows;
if (!table) {
for (i=0; i 180) {
rows[i][0] = rows[i][0] - 360;
};
};
// Remove NaNs
for (i=rows.length-1; i>=0; i--) {
// for (i=2;i>=0;i--) {
// for (j=0;i<=1; i++) {
// console.log(rows[i][j],i,j);
if (rows[i][1] > -999) {
rows[i][2] = -999;
} else {
rows[i][1] = -999;
};
if (isNaN(rows[i][2])) {
rows[i][2] = -999;
// rows.splice(i, 1);
// console.log(rows[i][j]);
};
};
};
// for (i=rows.length-1; i>=0; i--) {
// if (isNaN(rows[i])) {
// rows[i] = [""];
// };
//};
var cols = Array(jsonData.columns); // Need to make array for concatenation
// Concatenate values. Required for arrayToDataTable.
values = cols.concat(rows);
// Create DataTable
callback.apply(google.visualization.arrayToDataTable(values));
} else {
if (jsonData.error) {
alert('Error in query. Results not updated. Error: ' + jsonData.error.errors[0]);
console.log(jsonData.error.errors[0].message);
};
if (table) {
// no data returned - hide table
if (jsonData.rows == undefined) {
$( ".google-visualization-table-tr-even" ).hide();
$( ".google-visualization-table-tr-odd" ).hide();
$( ".google-visualization-table-div-page" ).hide();
}
}
}
}
});
};
// Toggle the columns
function toggleColumns() {
// columns
var columns = document.getElementsByName('Column');
var filter = [0,1];
for (var i = 0, column; column = columns[i]; i++) {
if (column.checked) {
filter.push(parseFloat(column.id));
}
}
view.setColumns(filter);
table.draw(view, tableOptions);
};
// Create the data table
function drawTable() {
var columns = "'WISE Name', 'Catalog', 'GLong
(deg.)', 'GLat
(deg.)', 'RA', 'Dec', 'Radius
(arcsec.)', 'HII Region', 'Membership', 'VLSR
(km/s)', 'Author', 'VLSR (Mol.)
(km/s)', 'Molecule', 'KDAR', 'Dist.
(kpc)', 'Err Dist.
(kpc)', 'Dist. Method', 'RGal
(kpc)', 'z
(pc)', 'GLIMPSE 8um
(Jy)', 'WISE 12um
(Jy)', 'WISE 22um
(Jy)', 'MIPSGAL 24um
(Jy)', 'Hi-Gal 70um
(Jy)', 'Hi-Gal 160um
(Jy)', 'HRDS 3cm
(Jy)', 'MAGPIS 20cm
(Jy)', 'VGPS 21cm
(Jy)'";
// get data
getData(columns, null, 1, function() {
data = this;
// Create and draw table
view = new google.visualization.DataView(data);
table = new google.visualization.Table(document.getElementById('visualization'));
toggleColumns();
// Selection events
google.visualization.events.addListener(table, 'select', selectHandler);
});
};
// Create the LV diagram. Need to do with JSON because normal query restricted to 500 rows
function drawChart() {
var columns = "'GLong
(deg.)', 'VLSR
(km/s)', 'VLSR (Mol.)
(km/s)'";
// get data
getData(columns, null, 0, function() {
chartData = this;
// Create and draw chart
chart = new google.visualization.ScatterChart(document.getElementById('chart'));
// chart = new google.charts.Scatter(document.getElementById('chart'));
chart.draw(chartData, chartOptions)
});
};
function findNotNaNs(arr){
return arr.map(function(itm, i){
if(!isNaN(itm)) return i;
return false;
}).filter(function(itm){
return itm;
});
};
function findNaNs(arr){
return arr.map(function(itm, i){
if(isNaN(itm)) return i;
return false;
}).filter(function(itm){
return itm;
});
};