Permalink
Browse files

new tiles and getting json data from server

  • Loading branch information...
1 parent 1eb7382 commit 1dbe3abaeef8e4385d91d2dce56e35018489f6fd @xavijam xavijam committed May 11, 2011
View
@@ -1,3 +1,4 @@
.DS_Store
json/generated_data/google_names_cache
-json/generated_data/tiles
+json/generated_data/tiles
+tiles/
View
@@ -45,7 +45,7 @@
<div class="share">
<div class="outer_share">
<p>Compartir</p>
- <a class="facebook">Facebook</a>
+ <a href="http://www.facebook.com/sharer.php?u=http://www.vizzuality.com/&t=Mapa%20de%20Elecciones%202011" target="_blank" class="facebook">Facebook</a>
<a class="twitter">Twitter</a>
<p class="total">1k</p>
</div>
@@ -91,6 +91,7 @@
<span class="slider"></span>
<a href="#zoom_menos" class="zoom_out">Zoom menos</a>
</div>
+ <a class="vizzuality" href="http://www.vizzuality.com" target="_blank">Vizzuality</a>
<div id="peninsula"></div>
<div id="canary_island"></div>
</div>
View
Binary file not shown.
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -33,7 +33,12 @@
}
// Check length of the array
- if (route.length!=5) {
+ if (route.length!=6) {
+ return false;
+ }
+
+ // Check provincia-autonomia-municipio
+ if (route[5]!="autonomia" && route[5]!="municipio" && route[5]!="provincia") {
return false;
}
@@ -84,6 +89,13 @@
function changeHash() {
var latlng = peninsula.getCenter();
var zoom = peninsula.getZoom();
- window.location.hash = "#" + latlng.lat().toFixed(3)+"_"+latlng.lng().toFixed(3)+"_"+zoom+"_"+year+"_"+compare;
+ if (zoom==6) {
+ level = "autonomia";
+ } else if (zoom>6 && zoom<10) {
+ level = "provincia";
+ } else {
+ level = "municipio";
+ }
+ window.location.hash = "#" + latlng.lat().toFixed(3)+"_"+latlng.lng().toFixed(3)+"_"+zoom+"_"+year+"_"+compare+"_"+level;
}
View
@@ -24,18 +24,16 @@
// Procesos_electorales var
- $.ajax({
- method: "GET",
- dataType: 'jsonp',
- url: 'https://api.cartodb.com/v1',
- data: {sql:'SELECT * FROM procesos_electorales',api_key:'8c587c9f93c36d146c9e66a29cc8a3499e869609'},
- success: function(data) {
- procesos_electorales = data.rows;
- },
- error: function(e) {
-
- }
- });
+ // $.ajax({
+ // method: "GET",
+ // dataType: 'jsonp',
+ // url: 'https://api.cartodb.com/v1',
+ // data: {sql:'SELECT * FROM procesos_electorales',api_key:'8c587c9f93c36d146c9e66a29cc8a3499e869609'},
+ // success: function(data) {
+ // procesos_electorales = data.rows;
+ // },
+ // error: function(e) {console.debug(e)}
+ // });
// Year Slider
@@ -70,6 +68,7 @@
ev.preventDefault();
$('div.select').each(function(i,ele){$(ele).removeClass('opened');});
+
if (!$(this).closest('div.select').hasClass('opened')) {
if ($(this).parent().find('li.selected').length) {
var index = $(this).parent().find('li.selected').index();
@@ -4,6 +4,7 @@
function CoordMapType(tileSize) {
this.tileSize = tileSize;
+ this.json_tile_url = "/json/generated_data/tiles/";
}
CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
@@ -20,22 +21,18 @@
hash[coord.x+'_'+coord.y+'_'+zoom] = [];
//Select query/json to take data from this tile
- var query;
var x,y;
if (zoom>9) {
-
if (zoom==12) {
x = coord.x/2;
y = coord.y/2;
} else {
x = coord.x;
y = coord.y;
}
- query = query_municipio + "WHERE v_get_tile("+Math.floor(x)+","+Math.floor(y)+",11) && centre_geom_webmercator and proceso_electoral_id=73";
-
+ z = 11;
} else if (zoom>6 && zoom<=9) {
-
if (zoom>7) {
var difference = (zoom - 7)*2;
x = coord.x/difference;
@@ -44,20 +41,21 @@
x = coord.x;
y = coord.y;
}
-
- query = query_provincia + " WHERE v_get_tile("+x+","+y+",7) && centre_geom_webmercator AND proceso_electoral_id = '73'";
+ z = 7;
} else {
- query = query_comunidad + " WHERE v_get_tile("+coord.x+","+coord.y+","+zoom+") && centre_geom_webmercator AND proceso_electoral_id = '73'";
+ x = coord.x;
+ y = coord.y;
+ z = 6;
}
if (x==undefined || ((x%1==0) && (y%1==0))) {
// Call service
$.ajax({
method: "GET",
- dataType: 'jsonp',
- url: 'https://api.cartodb.com/v1',
- data: {sql:query,api_key:'8c587c9f93c36d146c9e66a29cc8a3499e869609'},
- success: function(data) {
+ dataType: 'json',
+ url: me.json_tile_url+z+'_'+x+'_'+y+'.json',
+ success: function(points) {
+
// Normalize latlng of the tile to transform it to point(x,y)
var pixelcoord = {x:coord.x*256,y:coord.y*256,z:zoom} ;
var worldcoord = new google.maps.Point(pixelcoord.x/Math.pow(2,zoom),pixelcoord.y/Math.pow(2,zoom));
@@ -66,21 +64,19 @@
var normalizedPoint = peninsula.getProjection().fromLatLngToPoint(ne);
var scale = Math.pow(2, zoom);
var tileCoordinate = new google.maps.Point(normalizedPoint.x * scale, normalizedPoint.y * scale);
-
- // Tile data points
- var points = data.rows;
+
// Remove previous data of this tile
delete hash[coord.x+'_'+coord.y+'_'+zoom];
hash[coord.x+'_'+coord.y+'_'+zoom] = {};
-
+
//Loop data points
_.each(points,function(point,i){
- me.createBubble(div,point,tileCoordinate,scale,coord,zoom,ownerDocument);
+ me.createBubble(div,point.data,tileCoordinate,scale,coord,zoom,ownerDocument);
});
-
+
return div;
},
- error: function(error) {
+ error: function(e) {
return div;
}
});
@@ -99,12 +95,9 @@
};
-
-
-
CoordMapType.prototype.createBubble = function(div,point,tileCoordinate,scale,coord,zoom,ownerDocument) {
hash[coord.x+'_'+coord.y+'_'+zoom][point.id] = point;
-
+
var latlng = new google.maps.LatLng(point.center_latitude,point.center_longitude);
var normalizedPoint = peninsula.getProjection().fromLatLngToPoint(latlng); // returns x,y normalized to 0~255
var pixelCoordinate = new google.maps.Point(normalizedPoint.x * scale, normalizedPoint.y * scale);
View
@@ -20,7 +20,7 @@
function initializeMap() {
var peninsula_ops = {zoom: start_zoom,center: start_center,disableDefaultUI: true,mapTypeId: google.maps.MapTypeId.ROADMAP,minZoom: 6,maxZoom: 12, mapTypeControlOptions: {mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'rtve']}};
- var canary_ops = {zoom: 6,center: canary_center,disableDefaultUI: true,mapTypeId: google.maps.MapTypeId.ROADMAP,minZoom: 6,maxZoom: 12};
+ // var canary_ops = {zoom: 6,center: canary_center,disableDefaultUI: true,mapTypeId: google.maps.MapTypeId.ROADMAP,minZoom: 6,maxZoom: 12};
peninsula = new google.maps.Map(document.getElementById("peninsula"),peninsula_ops);
@@ -53,19 +53,12 @@
//Political tiles
var political_parties = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
- var c=Math.pow(2,zoom);
- var d=c-1-tile.y;
- var e=tile.x%c;
-
- var rand_no = Math.floor((4)*Math.random());
- var url = this.urlPattern.replace("{n}",tileServers[rand_no]);
-
- return url+zoom+"/"+e+"/"+d+".png";
+ return this.urlPattern+tile.x+"_"+tile.y+'_'+zoom+"_"+procesos_electorales[year]+".png";
},
tileSize: new google.maps.Size(256, 256),
opacity:0.65,
isPng: true,
- urlPattern:'http://{n}.tiles.mapbox.com/vizzuality/1.0.0/election_data_816f6c/'
+ urlPattern:'/tiles/'
});
peninsula.overlayMapTypes.setAt(1,political_parties);
//canary_island.overlayMapTypes.setAt(0,political_parties);
Oops, something went wrong.

0 comments on commit 1dbe3ab

Please sign in to comment.