Created
May 10, 2016 17:49
-
-
Save stuartlynn/abaf9118e52fbd9edaa2595b0e1ee982 to your computer and use it in GitHub Desktop.
Working segmentation namer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title></title> | |
| <!-- Bootstrap --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> | |
| <link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
| <script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
| <style> | |
| body,html{ | |
| width:100%; | |
| height:100%; | |
| margin:0px; | |
| padding:0px; | |
| } | |
| #map{ | |
| width:100%; | |
| height: 100%; | |
| } | |
| #controls{ | |
| width: 35%; | |
| height: 360px; | |
| min-width: 200px; | |
| background-color: white; | |
| box-sizing: border-box; | |
| padding:10px; | |
| padding-top:0px; | |
| position: absolute; | |
| right:20px; | |
| top:56px; | |
| z-index: 2000; | |
| } | |
| .smaller{ | |
| font-size: 12px; | |
| } | |
| .not_ready input{ | |
| display:none; | |
| } | |
| .not_ready p{ | |
| display:none; | |
| } | |
| #controls h3{ | |
| font-size:15px; | |
| } | |
| </style> | |
| <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | |
| <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
| <!--[if lt IE 9]> | |
| <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.js"></script> | |
| <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | |
| <![endif]--> | |
| </head> | |
| <body> | |
| <div class='cartodb-legend-stack' id='controls' style='top:56px'> | |
| <form class='not_ready' id='suggestion_input'> | |
| <h3>Select an area you know well. Look at the seccondary description. | |
| If you disagree with it think of a new description. Compare this to other areas with | |
| them same color. Enter it in the box and hit submit</h3> | |
| <p> | |
| Class no <span id='x55_no'></span></br> | |
| <a id='comparison_pdf' target="_blank" href=''>Click to see comparison with similar</a><br/> | |
| <a id='histogram_pdf' target="_blank" href=''>Click to see histograms of this class</a> | |
| </p> | |
| <p style='color:#013A71;'>Primary category</p> | |
| <p class='smaller' id='current_name_x10'></p> | |
| <p style='color:#013A71;'>Secondary category</p> | |
| <p class='smaller' id='current_name_x55'></p> | |
| <p style='color:#013A71;'>Your suggestion</p> | |
| <input type='text' id='suggestion'></input> | |
| <input style='margin-top:10px' type='submit'></input> | |
| </form> | |
| </div> | |
| <div id='map'> | |
| </div> | |
| <script> | |
| window.onload = function() { | |
| var current_x55; | |
| var current_geom_id; | |
| var sql = new cartodb.SQL({ user: 'observatory' , api_key:'bf40056ab6e223c07a7aa7731861a7bda1043241'}); | |
| var base_carto_css ='' | |
| cartodb.createVis('map', 'https://observatory.cartodb.com/api/v2/viz/2b7d3e2a-1632-11e6-b954-0ea31932ec1d/viz.json') | |
| .done(function(vis, layers) { | |
| // layer 0 is the base layer, layer 1 is cartodb layer | |
| // when setInteraction is disabled featureOver is triggered | |
| base_carto_css = layers[1].layers[0].options.cartocss; | |
| console.log(base_carto_css) | |
| layers[1].setInteraction(true); | |
| layers[1].setInteractivity('cartodb_id,x10,x55,x10_cat,x55_cat') | |
| layers[1].on('featureClick', function(e, latlng, pos, data, layerNumber) { | |
| current_x55=data.x55; | |
| current_geom_id = data.cartodb_id; | |
| updated_css =base_carto_css+ '#spielman_singleton_demographics {polygon-opacity:0.4; [x55='+current_x55+']{polygon-opacity:1; line-opacity:1.0; line-color:black; line-width:1;}}' | |
| layers[1].setCartoCSS(updated_css) | |
| $("#x55_no").html(data.x55) | |
| $("#suggestion_input").removeClass('not_ready'); | |
| $("#current_name_x55").html(data.x55_cat); | |
| $("#current_name_x10").html(data.x10_cat); | |
| $("#comparison_pdf").attr('href', 'http://52.71.151.140:8888/files/basic_report_'+data.x10+'.0.pdf' ) | |
| $("#histogram_pdf").attr('href', 'http://52.71.151.140:8888/files/histogram_comp_x55_'+data.x55+'.pdf' ) | |
| }); | |
| $("#suggestion_input").on("submit", function(e){ | |
| e.preventDefault(); | |
| suggestion = $('#suggestion').val(); | |
| values = [current_geom_id, current_x55 ,"$string$"+suggestion+"$string$"].join(',') | |
| query = 'insert into x55_demographic_suggestions (suggestion_geom_id, x55, suggestion) values ('+ | |
| values + ')' | |
| console.log('query is ', query) | |
| sql.execute(query) | |
| $('#suggestion').val('') | |
| $("#suggestion_input").addClass('not_ready'); | |
| layers[1].setCartoCSS(base_carto_css) | |
| }); | |
| // you can get the native map to work with it | |
| var map = vis.getNativeMap(); | |
| // now, perform any operations you need, e.g. assuming map is a L.Map object: | |
| // map.setZoom(3); | |
| // map.panTo([50.5, 30.5]); | |
| }); | |
| } | |
| </script> | |
| <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
| <!-- Include all compiled plugins (below), or include individual files as needed --> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment