forked from wboykinm/hoodsproj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhoods.js
More file actions
207 lines (190 loc) · 7.3 KB
/
hoods.js
File metadata and controls
207 lines (190 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//CONFIGURE AND EXTEND THIS LIST AS NEEDED FOR YOUR OWN NEIGHBORHOODS
var hoods = [
{name:"Speer",color:"#A6CEE3"},
{name:"East Colfax",color:"#1F78B4"},
{name:"Capitol Hill",color:"#B2DF8A"},
{name:"Five Points",color:"#33A02C"},
{name:"Westwood",color:"#FB9A99"},
{name:"University Park",color:"#E31A1C"},
{name:"Hilltop",color:"#FDBF6F"},
{name:"Globeville",color:"#FF7F00"},
{name:"Berkeley",color:"#CAB2D6"},
{name:"Virginia Village",color:"#6A3D9A"},
{name:"Ruby Hill",color:"#D47384"},
{name:"Mar Lee",color:"#604860"},
{name:"Hale",color:"#00688B"},
{name:"Congress Park",color:"#236B8E"},
];
var currentHood = Math.round( Math.random()*(hoods.length-1) );
var drawingManager;
var drawingOptions;
var polygonOptions;
var polygons = [];
var drawText = "Click points on the map to trace the shape. Double-click or click the starting point to finish the shape. Don't worry, you can edit it after you're finished!";
var editText = "Drag the white squares to edit the shape.";
//THIS SUPER-CLEAN BASEMAP WILL GIVE NO ONE ANY IDEAS
//ABOUT WHERE THE NEIGHBORHOOD BOUNDARIES ALREADY ARE . . .
function initialize() {
var styler = [
{
stylers: [
{ saturation: -99 },
{ visibility: "simplified" },
{ lightness: 30 }
]
},{
featureType: "water",
stylers: [
{ saturation: 10 },
{ hue: "#5f6074" },
{ lightness: -19 },
{ visibility: "simplified" }
]
},{
featureType: "road",
elementType: "geometry",
stylers: [
{ visibility: "simplified" },
{ lightness: 100 }
]
},{
featureType: "road",
elementType: "labels",
stylers: [
{ visibility: "on" },
{ saturation: -98 },
{ lightness: 30 }
]
},{
featureType: "poi.park",
elementType: "geometry",
stylers: [
{ visibility: "on" },
{ hue: "#a07c62" },
{ saturation: 10 }
]
},{
featureType: "administrative.land_parcel",
stylers: [
{ hue: "#ff001a" },
{ saturation: 95 },
{ visibility: "off" }
]
}
];
var myOptions = {
//CONFIGURE WITH YOUR OWN CITY CENTERPOINT (GETLATLON.COM)
center: new google.maps.LatLng(39.737, -104.985),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var hoodMapType = new google.maps.StyledMapType(hoodMapType,{name: "Hoods"});
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
map.setOptions({styles:styler});
//UNCOMMENT BELOW IF YOU HAVE A KML OF YOUR STUDY BOUNDARY TO INCLUDE
//var cityBorder = new //google.maps.KmlLayer('http://data.denvergov.org/download/gis/county_boundary/kml/county_boundary.kmz', {clickable: false, //preserveViewport: true});
//cityBorder.setMap(map);
polygonOptions = {
fillColor: hoods[currentHood].color,
fillOpacity: .6,
strokeWeight: 1,
strokeColor: "#666666",
clickable: false,
editable: true,
zIndex: 1
};
drawingOptions = { drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: false,
polygonOptions: polygonOptions
}
drawingManager = new google.maps.drawing.DrawingManager(drawingOptions);
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
drawingManager.setDrawingMode(null);
polygons[currentHood] = polygon;
$(".hood:eq("+currentHood+")").append("<span class='edit'>(edit)</span>");
$("#instruction-details").html( editText );
});
for ( var i in hoods ){
$("#hoodlist").append( "<div class='hood'><div class='colorchip' style='background:"+hoods[i].color+";'></div><p style='display:inline;'>"+hoods[i].name+"</p></div>" );
}
//$("#hoodlist").append( "<p id='finished'>Done drawing neighborhoods?</p><p id='submit'>SUBMIT YOUR MAP</p>");
$(".hood").click( function(){
selectHood( $(".hood").index( $(this) ) );
});
$("#next").click( function(){
if ( currentHood < hoods.length - 1 )
selectHood( currentHood + 1 );
else selectHood(0);
});
$(".hood:eq("+currentHood+")").addClass("active");
var name = hoods[currentHood].name;
if ( hoods[currentHood].prefix ) name = hoods[currentHood].prefix + " " + name;
$("#currenthoodname").html( name.toUpperCase() );
$("#submit").on("click", function(){
var str = "";
for ( var i in polygons ){
if ( polygons[i] ){
str += hoodToJson(i) + ",";
}
}
if ( str != "" ){
$("#submit").off("click");
$.post("hoods.php",{hoods: str},function(data){window.location.href = 'http://www.geosprocket.com/core/index.php/btvwards-thanks/';});
}
});
$( window ).resize( sizeMap );
sizeMap(null);
function sizeMap(event){
$('#map_canvas').css( 'height',Math.max( $(window).height(), $('#hoodlist').height() ) - $('#instructions').height() - 4 );
$("#instructions").css('width',$(window).width() - $('#hoodlist').width() - 10 );
}
}
function selectHood( index ){
if ( polygons[currentHood] ){
polygons[currentHood].setOptions( {editable: false} );
}
$(".active").removeClass("active");
$(".hood:eq("+index+")").addClass("active");
//$(this).addClass("active");
currentHood = index;
var name = hoods[currentHood].name;
if ( hoods[currentHood].prefix ) name = hoods[currentHood].prefix + " " + name;
$("#currenthoodname").html( name.toUpperCase() );
if ( polygons[currentHood] ){
drawingManager.setDrawingMode(null);
polygons[currentHood].setOptions( {editable: true} );
$("#instruction-details").html( editText );
} else {
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
polygonOptions.fillColor = hoods[currentHood].color;
drawingOptions.polygonOptions = null;
drawingOptions.polygonOptions = polygonOptions;
drawingManager.setOptions(null);
drawingManager.setOptions(drawingOptions);
$("#instruction-details").html( drawText );
}
}
function hoodToJson( hood ) {
var polygon = polygons[hood];
var array = polygon.getPath().getArray();
var coords = [];
for ( var i=0; i<array.length; i++ ){
coords.push( [ array[i].lng(), array[i].lat() ] );
}
return JSON2.stringify( { type: "Feature", geometry: { type: "Polygon", coordinates: [ coords ] }, properties: { name: hoods[hood].name } } );
}
//BELOW IS YOUR STARTING SPLASH SCREEN. DENVER'S INFO IS CURRENTLY IN THERE,
//BUT ADD YOUR OWN EXPLANATORY TEXT - PLEASE CREDIT BOSTONOGRAPHY FOR THE IDEA
$(document).ready(function() {
$.fancybox(
"<h2>Mapping Denver's neighborhoods</h2><hr><p>From East Colfax to Capitol Hill, Denver is composed of distinctive neighborhoods. Some of these are defined by natural features, but there is still much disagreement on where one neighborhood ends and another begins. Because both formal and informal lines have consequences on city services, politics, and identity, we want to make a map of Denver's neighborhoods by its residents and those who know the city well.</p><p>This map is a tool for drawing neighborhood boundaries as <strong>you</strong> see them, and submitting them to a collective map. You can submit as many or as few neighborhoods as you'd like, but <strong>please only draw a neighborhood if you think you have a decent idea of where it is</strong>. <br/><br/><i>We'd like to thank the mappers at <a href='http://bostonography.com/2012/crowdsourced-neighborhood-boundaries-part-one-consensus/' target='_blank'>Bostonography</a> for developing this concept from scratch.</i><br/><hr>",
{
'autoDimensions' : false,
'width' : 500,
'height' : 500,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
}
);
});