/*function toggleBase(){
if(Base._url=="https://{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}") {
Base.removeFrom(map);
Base=L.esri.basemapLayer('Streets').addTo(map);
featureLayerTwo.setStyle({fillOpacity:0});
//MIM - Setting HUC12s to tranparent also when toggle turned ON, setting boolean variable to TRUE
featureLayerThree.setStyle({fillOpacity:0});
toggleOn = true;
map.removeControl(legend);
} else {
Base.removeFrom(map);
Base=L.esri.basemapLayer('Gray').addTo(map);
featureLayerTwo.setStyle({fillOpacity:0.9});
featureLayerThree.setStyle({fillOpacity:0.9});
toggleOn = false;
legend.addTo(map);
}
}
*/
/*
function onHUCSearch(stateAbv, hucCode) {
console.log(stateAbv+'----'+hucCode);
whereStmt = "states like '%" + stateAbv + "%'";
stateWhereStmt = whereStmt;
//UPDATE COLOR
L.esri.featureLayer({
url: 'https://wxatersgeo.epa.gov/arcgis/rest/services/Support/HydrologicUnits/Mapserver/4'
}).query().where(whereStmt).run(function(error, featureCollection, response) {
if (error) {
console.log(error);
return;
}
var temp_huc_8 = [];
var temp_huc_8_density = [];
featureCollection.features.forEach(function(item) {
if ((huc8_density[huc8.indexOf(item.properties.huc8)])) {
temp_huc_8.push(item.properties.huc8);
temp_huc_8_density.push(huc8_density[huc8.indexOf(item.properties.huc8)]);
}
});
dupe = temp_huc_8_density.map(Number);
q1_8 = quantile(dupe, .3);
q2_8 = quantile(dupe, .6);
q3_8 = quantile(dupe, .9);
q4_8 = quantile(dupe, 1);
});
//END UPDATE COLOR
var l;
geojson.eachLayer(
function(layer) {
layer.setStyle({
fillOpacity: 0
});
layer.bringToBack();
}
);
// if (featureLayerTwo) map.removeLayer(featureLayerTwo);
/*
//MIM ...calling layer 14, which is the detailed HUC8 layer
featureLayerTwo =
L.esri.featureLayer({
onEachFeature: onHucEightLayer,
style: style_huc8,
url: 'https://wxatersgeo.epa.gov/arcgis/rest/services/Support/HydrologicUnits/Mapserver/14',
where: whereStmt
});
} else {
*/
//MIM ...calling layer 4, which is the simplified HUC8 layer
featureLayerTwo =
L.esri.featureLayer({
onEachFeature: onHucEightLayer,
style: style_huc8,
url: 'https://gispub.epa.gov/arcgis/rest/services/OW/HydrologicUnits/Mapserver/4',
where: whereStmt
});
// }
/*
featureLayerTwo =
L.esri.featureLayer({
onEachFeature: onHucEightLayer,
style: style_huc8, //{color: '#1d542b', opacity: .75, weight: 2 },
url: 'https://wxatersgeo.epa.gov/arcgis/rest/services/Support/HydrologicUnits/Mapserver/4',
where: whereStmt
});
*/
featureLayerTwo.addTo(map);
whereStmt = "huc8 = \x27" + hucCode.substring(0, 8) + "\x27";
featureLayerTwo.query().where(whereStmt).run(function(error, response) {
if (error) {
console.log(error);
return;
}
if (huc8_density[huc8.indexOf(x.huc8)] === undefined) {
$('#stuff').html(x.name + ' (' + x.huc8 + ') - 0 Stories');
} else {
$('#stuff').html(x.name + ' (' + x.huc8 + ') - ' + huc8_density[huc8.indexOf(x.huc8)] + ' Stories
[NOTE: Map does not include projects marked "statewide" or those not indexed to specific watersheds.]');
}
});
if ('CODE' == 'HUC8' || ('').length == 8) {
setTimeout(function() {
console.log('kkkkk'+hucCode);
featureLayerTwo.eachFeature(function(layer) {
if (layer.feature.properties.huc8 == hucCode) {
$s("P9940_SAVED_HUC_NAME", layer.feature.properties.name);
l = layer;
console.log('jjjj'+l);
document.getElementById('reportHeader').innerHTML = '
' + $v("P9940_TITLE") + ' for ' + (layer.feature.properties.name) + ' (' + layer.feature.properties.huc8 + ') ';
document.getElementById('subRptHeader').innerHTML = "
";
}
});
}, 1000);
}
whereStmt = "substring(huc12,1,8) = \x27" + hucCode.substring(0, 8) + "\x27";
//UPDATE COLOR
L.esri.featureLayer({
url: 'https://gispub.epa.gov/arcgis/rest/services/OW/HydrologicUnits/MapServer/6'
}).query().where(whereStmt).run(function(error, featureCollection, response) {
if (error) {
console.log(error);
return;
}
var temp_huc_12 = [];
var temp_huc_12_density = [];
featureCollection.features.forEach(function(item) {
if ((huc12_density[huc12.indexOf(item.properties.huc12)])) {
temp_huc_12.push(item.properties.huc12);
temp_huc_12_density.push(huc12_density[huc12.indexOf(item.properties.huc12)]);
}
});
dupe = temp_huc_12_density.map(Number);
q1_12 = quantile(dupe, .25);
q2_12 = quantile(dupe, .5);
q3_12 = quantile(dupe, .75);
q4_12 = quantile(dupe, 1);
});
//END UPDATE COLOR
setTimeout(function(){
featureLayerThree =
L.esri.featureLayer({
onEachFeature: onHucTwelveLayer,
style: style_huc12, //{color: '#54421d', opacity: .75, weight: 2 },
url: 'https://gispub.epa.gov/arcgis/rest/services/OW/HydrologicUnits/MapServer/6',
where: whereStmt
});
featureLayerThree.addTo(map);
target = 1;
featureLayerThree.query().where(whereStmt).bounds(function(error, latLngBounds, response) {
if (error) {
console.log(error);
return;
}
map.fitBounds(latLngBounds);
});
if ('CODE' != 'HUC8') {
setTimeout(function(){
featureLayerThree.eachActiveFeature(function(layer) {
if (layer.feature.properties.huc12 == hucCode) {
$s("P9940_SAVED_HUC_NAME", layer.feature.properties.name);
l = layer;
//layer.openPopup();
layer.fireEvent('click');
document.getElementById('reportHeader').innerHTML = '
' + $v("P9940_TITLE") + ' for ' + (layer.feature.properties.name) + ' (' + layer.feature.properties.huc12 + ') ';
// document.getElementById('reportHeader').innerHTML = '
' + $v("P9940_TITLE") + ' for ' + (layer.feature.properties.name) + ' (' + layer.feature.properties.huc12 + ') ';
document.getElementById('subRptHeader').innerHTML = "
";
}
});
},1000);
/* if(!legend2._map) //SL added
legend2.addTo(map);*/
$('#basemaps-wrapper').css('display','block'); //SL
}
setTimeout(function(){
if (l != null) {
console.log("START SETSTYLE12");
l.setStyle({
color: 'yellow',
weight: 10,
fillOpacity: 1,
dashArray: null
});
console.log("END SETSTYLE12");
yellow = l;
l.bringToFront();
featureLayerThree.bringToFront();
}
},1000);
legend.onAdd = function(map) {
console.log([q1_12,q2_12,q3_12,q4_12]);
var div = L.DomUtil.create('div', 'info legend'),
grades = Array.from(new Set([0, Math.ceil(q1_12), Math.ceil(q2_12), Math.ceil(q3_12), Math.ceil(q4_12)])),
labels = [];
div.innerHTML +=
'
0' + '
';
for (var i = 0; i < grades.length - 1; i++) {
console.log('Y range: grades[i]=' + grades[i] + ', ' + 'grades[i+1]=' + grades[i+1] + ', ' + 'grades[i-1]=' + grades[i-1]) ;
if ((grades[i]+1) == grades[i + 1] || i+1 == grades.length){
div.innerHTML +=
'
' +
(grades[i]+1)+ '
';console.log(i+' 2');
}
else if (grades[i] !== grades[i + 1]) {
div.innerHTML +=
'
' +
(grades[i]+1) + (grades[i + 1] ? '–' + (grades[i + 1]) + '
' : '+');
console.log(i+' 3');
}
}
return div;
};
legend.addTo(map);
},2000);
setTimeout(function() {
if ('CODE' == 'HUC8' || ('').length == 8) {
console.log("START SETSTYLE8");
console.log(l+yellow);
if (l) {
l.setStyle({
color: 'yellow',
weight: 10,
fillOpacity: 0,
dashArray: null
});
yellow = l;
}
console.log("END SETSTYLE8");
featureLayerTwo.bringToBack();
geojson.bringToBack();
if (yellow) yellow.bringToFront();
if (featureLayerThree) featureLayerThree.bringToFront();
} else {
if (featureLayerThree) featureLayerThree.bringToFront();
if (yellow) yellow.bringToFront();
}
}, 8000);*/