Skip to content

Commit

Permalink
update 2 city data
Browse files Browse the repository at this point in the history
  • Loading branch information
lishugo committed Feb 11, 2011
1 parent 663d18d commit df6a6e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
31 changes: 31 additions & 0 deletions city_stats.js
@@ -0,0 +1,31 @@
var city_stats = [
{ id: "beijing", code: "Th", population: 19720000, price_per_m:22650, annual_rent:36000, price_rent_ratio:47, salary:48444, lat: 39.904214, lon: 116.407413 },
{ id: "shanghai", code: "SA", population: 19213200, price_per_m:23478, annual_rent:9233.23, price_rent_ratio:52, salary:42789, lat: 31.230393, lon: 121.473704 },
/* { id: "guangzhou", code: "Th", date: "2009-03-20T00:00:00-07:00", lat: 37.776394, lon: -122.160752 },
{ id: "shenzhen", code: "Bu", date: "2009-03-20T00:00:00-07:00", lat: 37.739572, lon: -122.153254 },
{ id: "tianjin", code: "Va", date: "2009-03-19T23:30:00-07:00", lat: 37.810612, lon: -122.283648 },
{ id: "nanjing", code: "SA", date: "2009-03-19T23:09:00-07:00", lat: 37.804087, lon: -122.271248 },
{ id: "hangzhou", code: "Ro", date: "2009-03-19T23:00:00-07:00", lat: 37.771985, lon: -122.148367 },
{ id: "chengdu", code: "SA", date: "2009-03-19T22:30:00-07:00", lat: 37.82387, lon: -122.257414 },
{ id: "dalian", code: "Th", date: "2009-03-19T22:30:00-07:00", lat: 37.812051, lon: -122.207804 },
{ id: "qingdao", code: "SA", date: "2009-03-19T22:20:00-07:00", lat: 37.806634, lon: -122.287244 },
{ id: "shenyang", code: "VT", date: "2009-03-19T22:15:00-07:00", lat: 37.728821, lon: -122.17316 }
other cities
*/
];

var codes = [
{ code: "AA", name: "Aggravated Assault", category: "violent" },
{ code: "Mu", name: "Murder", category: "violent" },
{ code: "Ro", name: "Robbery", category: "violent" },
{ code: "SA", name: "Simple Assault", category: "violent" },
{ code: "Ar", name: "Arson", category: "property" },
{ code: "Bu", name: "Burglary", category: "property" },
{ code: "Th", name: "Theft", category: "property" },
{ code: "Va", name: "Vandalism", category: "property" },
{ code: "VT", name: "Vehicle Theft", category: "property" },
{ code: "Al", name: "Alcohol", category: "quality" },
{ code: "DP", name: "Disturbing the Peace", category: "quality" },
{ code: "Na", name: "Narcotics", category: "quality" },
{ code: "Pr", name: "Prostitution", category: "quality" }
];
18 changes: 9 additions & 9 deletions rentbuy.html
Expand Up @@ -3,7 +3,7 @@
<title>rent or buy</title>
<script src="protovis-d3.2.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAYZ9eMYFYusxZt-1RKXLI7RQGpXqX26B62_lhdlIUxPTUm0CSORRw1BkwdprB1xQ3Xa8KfbgKAacxlw" type="text/javascript"></script>
<script src="house.js" type="text/javascript"></script>
<script src="city_stats.js" type="text/javascript"></script>
<style type="text/css">

body {
Expand All @@ -29,8 +29,8 @@

codes.forEach(function(x) colors[x.code] = colors[x.category]);

function Canvas(rentbuy) {
this.rentbuy = rentbuy;
function Canvas(city_stats) {
this.city_stats = city_stats;
}

Canvas.prototype = pv.extend(GOverlay);
Expand All @@ -46,8 +46,8 @@
if (!force) return;
var c = this.canvas, m = this.map, r = 20;

/* Get the pixel locations of the rentbuy. */
var pixels = this.rentbuy.map(function(d) {
/* Get the pixel locations of the city_stats. */
var pixels = this.city_stats.map(function(d) {
return m.fromLatLngToDivPixel(new GLatLng(d.lat, d.lon));
});

Expand All @@ -66,7 +66,7 @@
.left(-x.min)
.top(-y.min)
.add(pv.Panel)
.data(this.rentbuy)
.data(this.city_stats)
.add(pv.Dot)
.left(function() pixels[this.parent.index].x)
.top(function() pixels[this.parent.index].y)
Expand All @@ -80,13 +80,13 @@
};

/* Restrict minimum and maximum zoom levels. */
G_NORMAL_MAP.getMinimumResolution = function() 11;
G_NORMAL_MAP.getMinimumResolution = function() 4;
G_NORMAL_MAP.getMaximumResolution = function() 14;

var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.78, -122.22), 12);
map.setCenter(new GLatLng(35, 112), 5);
map.setUI(map.getDefaultUI());
map.addOverlay(new Canvas(rentbuy));
map.addOverlay(new Canvas(city_stats));

</script>
</head>
Expand Down

0 comments on commit df6a6e4

Please sign in to comment.