Commit a2c558fa authored by Abbey Joy Roelofs's avatar Abbey Joy Roelofs
Browse files

Basic code for normalization field added, checkbox created, popupTemplate updated.

parent c187b07a
...@@ -24,11 +24,14 @@ ...@@ -24,11 +24,14 @@
<span id="sign-out" class="action">Sign Out</span> <span id="sign-out" class="action">Sign Out</span>
</div> </div>
<div id="parameter-picker" class="esri-widget"> <div id="parameter-picker" class="esri-widget">
<label for="parameter-1">NWS Parameter:</label> <label for="parameter-1-select">NWS Parameter:</label>
<select id="parameter-1-select"></select> <select id="parameter-1-select"></select>
<br> <br>
<label for="parameter-2-">Yale Parameter:</label> <label for="parameter-2-select">Yale Parameter:</label>
<select id="parameter-2-select"></select> <select id="parameter-2-select"></select>
<br>
<label for="normalize-check">Normalize occurrences by area?</label>
<input type="checkbox" id="normalize-check" />
</div> </div>
<div id="akViewDiv" class="esri-widget"></div> <div id="akViewDiv" class="esri-widget"></div>
<div id="hiViewDiv" class="esri-widget"></div> <div id="hiViewDiv" class="esri-widget"></div>
......
...@@ -108,6 +108,12 @@ require([ ...@@ -108,6 +108,12 @@ require([
// Add username and sign out link. // Add username and sign out link.
mainView.ui.add('title-view', 'top-right'); mainView.ui.add('title-view', 'top-right');
const outlineLayer = new FeatureLayer({
url: 'https://services1.arcgis.com/4ezfu5dIwH83BUNL/arcgis/rest/services/USA_States_Generalized_share_air/FeatureServer/0',
legendEnabled: false,
popupEnabled: false
});
// Create a layer from Perry's alert and Yale's opinion data at the level of Congressional Districts (115th). // Create a layer from Perry's alert and Yale's opinion data at the level of Congressional Districts (115th).
const layer = new FeatureLayer({ const layer = new FeatureLayer({
//url: 'https://services1.arcgis.com/4ezfu5dIwH83BUNL/arcgis/rest/services/Yale_Congressional_District_115_Level/FeatureServer/0', //url: 'https://services1.arcgis.com/4ezfu5dIwH83BUNL/arcgis/rest/services/Yale_Congressional_District_115_Level/FeatureServer/0',
...@@ -115,12 +121,41 @@ require([ ...@@ -115,12 +121,41 @@ require([
//popupTemplate: popupTemplate, //popupTemplate: popupTemplate,
//outFields: ['NAME', 'TotalPop', 'happening', 'happeningOppose'], //outFields: ['NAME', 'TotalPop', 'happening', 'happeningOppose'],
outFields: ['*'], outFields: ['*'],
title: 'U.S. 115th Congressional Districts' title: 'U.S. 115th Congressional Districts',
renderer: {
type: "simple",
symbol: {
type: "simple-fill",
color: [200, 200, 200, 0], // Draw everything transparent first (or change the 0 to .5 to draw it all grey first)
// Note that in spite of this, the opacity of the relationship renderer seems to default to what's set in the layer's default visualization
outline: {
width: 0
}
}
}
}); });
// Define initial set of parameters to display. // Define initial set of parameters to display.
var parameter1 = 'FL'; var parameter1 = 'FL';
var parameter2 = 'happening'; var parameter2 = 'happening';
var chkNormalize = true;
var normFieldName = 'SQMI'; // TODO: Check to see if this is the correct field to use.
const parameter2options = {
'happening' : 'Estimated percentage who think that global warming is happening',
'happeningOppose' : 'Estimated percentage who do not think that global warming is happening',
'congress' : 'Estimated percentage who think Congress should be doing more/much more to address global warming',
'congressOppose' : 'Estimated percentage who think Congress should be doing less/much less to address global warming',
'worried' : 'Estimated percentage who are somewhat/very worried about global warming',
'worriedOppose' : 'Estimated percentage who are not very/not at all worried about global warming'
};
const parameter1options = {
// 'HT' : 'Heat Advisory', // Not enough data...
'FL' : 'Flood Advisory',
//'HU' : 'Hurricane Warning', // Not enough data...
//'RP' : 'Rip Current', // Not enough data...
'SV' : 'Severe Thunderstorm'
//'WS' : 'Winter Storm' // Not enough data...
};
// Populate selection lists for parameters. // Populate selection lists for parameters.
setParameterSelectionLists(); setParameterSelectionLists();
...@@ -135,7 +170,7 @@ require([ ...@@ -135,7 +170,7 @@ require([
layer.popupTemplate = popupTemplate; layer.popupTemplate = popupTemplate;
const map = new Map({ const map = new Map({
layers: [layer] layers: [outlineLayer, layer]
}); });
// Add map to mainView. // Add map to mainView.
...@@ -360,12 +395,15 @@ require([ ...@@ -360,12 +395,15 @@ require([
} }
// Create relationship (or bivariate) renderer. // Create relationship (or bivariate) renderer.
//$feature.SV/$feature.SQMI
function setRelationshipRenderer() { function setRelationshipRenderer() {
let normField = chkNormalize ? normFieldName : null;
const params = { const params = {
layer: layer, layer: layer,
view: mainView, view: mainView,
field1: { field1: {
field: parameter1 field: parameter1,
normalizationField: normField
}, },
field2: { field2: {
field: parameter2 field: parameter2
...@@ -383,9 +421,12 @@ require([ ...@@ -383,9 +421,12 @@ require([
// Set the popup template // Set the popup template
function setPopupTemplate() { function setPopupTemplate() {
// This part could possibly be done just by setting fieldname aliases, but I don't have access to that.
let eventLabel = parameter1options[parameter1];
let pctLabel = parameter2options[parameter2];
popupTemplate = { popupTemplate = {
title:'{CD_Code}', title:'{CD_Code}',
content: [ /*content: [
{ {
type:'fields', type:'fields',
fieldInfos: [ fieldInfos: [
...@@ -403,12 +444,35 @@ require([ ...@@ -403,12 +444,35 @@ require([
} }
] ]
} }
] ] */
fieldInfos: [
{
fieldName: "expression/expr0",
format: {
places: 4,
digitSeparator: true
}
}
],
expressionInfos: [
{
name: "expr0",
title: "normalizedSV",
expression: "$feature." + parameter1 + "/$feature.SQMI",
returnType: "number"
}
],
content: "Total Population: {TotalPop}<br /> <br />" +
eventLabel + ": {" + parameter1 + "} <br /> " +
" Per Square Mile: {expression/expr0} <br /> <br />" +
pctLabel + ": {" + parameter2 + "}%",
} }
}; }
// Set the options for the parameter select lists. // Set the options for the parameter select lists.
function setParameterSelectionLists() { function setParameterSelectionLists() {
/* Moving this out of the function to make it accessible to other functions as well
var parameter1options = { var parameter1options = {
// 'HT' : 'Heat Advisory', // Not enough data... // 'HT' : 'Heat Advisory', // Not enough data...
'FL' : 'Flood Advisory', 'FL' : 'Flood Advisory',
...@@ -416,13 +480,14 @@ require([ ...@@ -416,13 +480,14 @@ require([
//'RP' : 'Rip Current', // Not enough data... //'RP' : 'Rip Current', // Not enough data...
'SV' : 'Severe Thunderstorm' 'SV' : 'Severe Thunderstorm'
//'WS' : 'Winter Storm' // Not enough data... //'WS' : 'Winter Storm' // Not enough data...
}; };*/
var select = document.getElementById('parameter-1-select'); var select = document.getElementById('parameter-1-select');
select.options.length = 0 select.options.length = 0
for(index in parameter1options) { for(index in parameter1options) {
select.options[select.options.length] = new Option(parameter1options[index], index); select.options[select.options.length] = new Option(parameter1options[index], index);
} }
/* Moving this out of the function to make it accessible to other functions as well
var parameter2options = { var parameter2options = {
'happening' : 'Estimated percentage who think that global warming is happening', 'happening' : 'Estimated percentage who think that global warming is happening',
'happeningOppose' : 'Estimated percentage who do not think that global warming is happening', 'happeningOppose' : 'Estimated percentage who do not think that global warming is happening',
...@@ -430,7 +495,7 @@ require([ ...@@ -430,7 +495,7 @@ require([
'congressOppose' : 'Estimated percentage who think Congress should be doing less/much less to address global warming', 'congressOppose' : 'Estimated percentage who think Congress should be doing less/much less to address global warming',
'worried' : 'Estimated percentage who are somewhat/very worried about global warming', 'worried' : 'Estimated percentage who are somewhat/very worried about global warming',
'worriedOppose' : 'Estimated percentage who are not very/not at all worried about global warming' 'worriedOppose' : 'Estimated percentage who are not very/not at all worried about global warming'
}; };*/
var select = document.getElementById('parameter-2-select'); var select = document.getElementById('parameter-2-select');
select.options.length = 0 select.options.length = 0
for(index in parameter2options) { for(index in parameter2options) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment