From f0edd5ef5e3b816468bdb0acddcc7a771491d1f4 Mon Sep 17 00:00:00 2001 From: Aaron Bauman Date: Wed, 13 Mar 2013 17:38:54 -0400 Subject: [PATCH 1/2] - Adding some additional data via OPA web service at http://api.phillyaddress.com. I'm interested in valuation per square foot, but OPA web service can return loads of information. These changes append an ajax callback to the tooltip to query the OPA web service and render the $ / sqft data inline with the other data. The only obtrusive change is the height of the tooltip, which must grow to accommodate the additional data. --- opa-api-wrapper.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 opa-api-wrapper.php diff --git a/opa-api-wrapper.php b/opa-api-wrapper.php new file mode 100644 index 0000000..51031d8 --- /dev/null +++ b/opa-api-wrapper.php @@ -0,0 +1,15 @@ + Date: Wed, 13 Mar 2013 17:45:36 -0400 Subject: [PATCH 2/2] Adding some additional data via OPA web service at http://api.phillyaddress.com. I'm interested in valuation per square foot, but OPA web service can return loads of information. These changes append an ajax callback to the tooltip to query the OPA web service and render the $ / sqft data inline with the other data. The only obtrusive change is the height of the tooltip, which must grow to accommodate the additional data. --- js/app.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/js/app.js b/js/app.js index 8261207..2d87e2b 100644 --- a/js/app.js +++ b/js/app.js @@ -31,6 +31,57 @@ function toTitleCase(str){ return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); } +function appendPropertyData(addr) { + var url = '/opa-api-wrapper.php/address/' + addr; + var data = $.ajax(url, { + // dataType: 'jsonp', + // jsonpCallback: 'json_callback', + success: function (res) { + res = jQuery.parseJSON(res); + // the property listing from api.phillyaddress is loaded with information. + // At this point i'm only interested in assessed value per square foot, + // but there's loads more data here that could be included in the listing. + var property = res.property.account_details; + var tax = res.property.valuation_details; + var land_sqft = parseFloat(property.land_area.replace(' SqFt', '')); + var bldg_sqft = parseFloat(property.improvement_area.replace(' SqFt', '')); + var land_ass_2013 = parseInt(tax[2013].assessed_land_exempt.replace(/[$,]/gi, '')) + parseInt(tax[2013].assessed_land_taxable.replace(/[$,]/gi, '')); + var land_ass_2014 = parseInt(tax[2014].assessed_land_exempt.replace(/[$,]/gi, '')) + parseInt(tax[2014].assessed_land_taxable.replace(/[$,]/gi, '')); + var bldg_ass_2013 = parseInt(tax[2013].assessed_improvement_exempt.replace(/[$,]/gi, '')) + parseInt(tax[2013].assessed_improvement_taxable.replace(/[$,]/gi, '')); + var bldg_ass_2014 = parseInt(tax[2014].assessed_improvement_exempt.replace(/[$,]/gi, '')) + parseInt(tax[2014].assessed_improvement_taxable.replace(/[$,]/gi, '')); + + var land_sqft_2013 = Math.floor(land_ass_2013 / land_sqft); + var land_sqft_2014 = Math.floor(land_ass_2014 / land_sqft); + var bldg_sqft_2013 = Math.floor(bldg_ass_2013 / bldg_sqft); + var bldg_sqft_2014 = Math.floor(bldg_ass_2014 / bldg_sqft); + var land_delta = 0; + var bldg_delta = 0; + + land_delta = Math.floor((land_sqft_2014 / land_sqft_2013) * 100); + if (land_sqft_2013 > land_sqft_2014) { + land_delta = -(100 - land_delta); + } + + bldg_delta = Math.floor((bldg_sqft_2014 / bldg_sqft_2013) * 100); + if (bldg_sqft_2013 > bldg_sqft_2014) { + bldg_delta = -(100 - bldg_delta); + } + $('#tooltip #opa-data-container').html( + 'OPA Data' + + '
improvement area: ' + property.improvement_area + + '
land area: ' + property.land_area + + '
2013 improvement value / sqft: $' + bldg_sqft_2013 + + '
2014 improvement value / sqft: $' + bldg_sqft_2014 + + '
% change: ' + bldg_delta + '%' + + '
2013 land value / sqft: $' + land_sqft_2013 + + '
2014 land value / sqft: $' + land_sqft_2014 + + '
% change: ' + land_delta + '%' + ); + } + }); + $('#tooltip').append('
acquiring OPA data...'); +} + // Create the map app.initMap = function(callback) { var mapSettings = app.mergeMapSettings(); @@ -55,10 +106,12 @@ app.initMap = function(callback) { "2013 Tax: $" + Number(o.data.tx_2013).formatMoney() + "
" + "2014 Market Value: $" + Number(o.data.mktval_14).formatMoney() + "
" + "2014 Tax: $" + Number(o.data.tx_2014).formatMoney() + "
" + - "Change in Tax: " + Number(o.data.tax_change * 100).toFixed(0) + '%'; + "Change in Tax: " + Number(o.data.tax_change * 100).toFixed(0) + '% ' + // Append property data on a time callback, so that we're not hammering the data api server: + ''; if ($('#tooltip').length) { + window.clearTimeout(mapSettings.myTimeout); $('#tooltip').html(contents).show(); } else { $('
', { @@ -71,7 +124,7 @@ app.initMap = function(callback) { $(document).mousemove(function(e){ var posX = e.pageX - offset.left - 130; - posY = e.pageY - offset.top - 150; + posY = e.pageY - offset.top - 300; $('#tooltip').css({ left: posX, top: posY }); });