-
Notifications
You must be signed in to change notification settings - Fork 4
/
map.php
168 lines (136 loc) · 4.92 KB
/
map.php
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
<?php /* Template Name: map
*/ ?>
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
get_header(); ?>
<div id="header3">
<a href="<?php echo get_settings('home'); ?>">
<canvas id="clockcanvas" width="50" height="50"></canvas>
</a>
</div>
<script>
//var queryTask = new esri.tasks.QueryTask("http://gis.cityofsantacruz.com/ArcGIS/rest/services/AddressSeach/MapServer/0");
//var query = new esri.tasks.Query();
//query.returnGeometry = true;
//query.outFields = ["*"];
function executeQuery(address){
var result;
while(address.indexOf(" ") > -1){
address = address.replace(" "," ");
}
var lcadd = address.toLowerCase();
// filter addresses which end with ", Santa Cruz, CA" but not "Santa Cruz St"
if(lcadd.indexOf("santa cruz") != -1){
if(lcadd.lastIndexOf("santa cruz") > lcadd.lastIndexOf("st")){
address = address.substring(0, lcadd.lastIndexOf("santa cruz"));
}
}
while(address.indexOf(",") > -1){
address = address.replace(",","");
}
lcadd = address.toLowerCase();
// abbreviate addresses to match GIS data
if(lcadd.indexOf(" street") > -1){
address = address.substring(0, lcadd.indexOf(" street") + 3);
}
if(lcadd.indexOf(" avenue") > -1){
address = address.substring(0, lcadd.indexOf(" avenue") + 4);
}
if(lcadd.indexOf(" drive") > -1){
address = address.substring(0, lcadd.indexOf(" drive") + 3);
}
if(lcadd.indexOf(" circle") > -1){
address = address.substring(0, lcadd.indexOf(" circle") + 4);
}
if(lcadd.indexOf(" lane") > -1){
address = address.substring(0, lcadd.indexOf(" lane")) + " Ln";
}
if(lcadd.indexOf(" boulevard") > -1){
address = address.substring(0, lcadd.indexOf(" boulevard")) + " Blvd";
}
if(lcadd.indexOf(" court") > -1){
address = address.substring(0, lcadd.indexOf(" court")) + " Ct";
}
if(lcadd.indexOf(" place") > -1){
address = address.substring(0, lcadd.indexOf(" place")) + " Pl";
}
address = address.replace(/^\s+|\s+$/g,"");
//query.where = "ADD_ LIKE upper ('%" + address + "%')";
//queryTask.execute(query, mapAddress);
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://gis.cityofsantacruz.com/ArcGIS/rest/services/AddressSeach/MapServer/0/query?f=json&where=ADD_%20LIKE%20upper%20('%25" + escape(address) + "%25')&returnGeometry=true&spatialRel=esriSpatialRelIntersects&outFields=*&callback=mapAddress";
document.body.appendChild(s);
}
function mapAddress(results){
if(results.features.length == 0){
// if address lookup fails, turn text box red
document.getElementById("address").style.backgroundColor = "#f44";
}
else{
document.getElementById("address").style.backgroundColor = "#fff";
var zone = results.features[0].attributes['Zoning1'];
var street = results.features[0].attributes['ADD_'];
var usecode = results.features[0].attributes['USECDDESC'];
var latlng = new L.LatLng(results.features[0].geometry.y, results.features[0].geometry.x);
//console.log(latlng);
var marker = new L.Marker(latlng);
map.addLayer(marker);
marker.bindPopup(street + "<br/>Zone: " + zone + "<br/>Current Use (Prior Use): " + usecode).openPopup();
// test: store zone and use code as a cookie
//setCookie("zone_and_use", zone + "|" + usecode, 21);
Cookies.defaults = {
path: '/',
expires: 60 * 60 * 24 * 21,
secure: false
}
Cookies.set('address', document.getElementById("address").value );
Cookies.set('zone_and_use', zone + "|" + usecode);
}
}
var map;
var _tilejson;
wax.tilejson('http://a.tiles.mapbox.com/v3/tamaracfa.map-lhp1bb4f.jsonp',
function(tilejson) {
_tilejson = tilejson;
map = new L.Map('map-div', { scrollWheelZoom: false, maxZoom: 17 })
.addLayer(new wax.leaf.connector(tilejson))
.setView(new L.LatLng(36.9749, -122.0263), 13);
wax.leaf.interaction()
.map(map)
.tilejson(tilejson)
.on(wax.tooltip().animate(false).parent(map._container).events())
}
);
function codeAddress() {
var address = document.getElementById("address").value;
executeQuery(address);
}
function checkForEnter(e){
if(e.keyCode == 13){
codeAddress();
}
}
</script>
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<?php the_content('<p class="serif">' . __('Read the rest of this page »', 'kubrick') . '</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>' . __('Pages:', 'kubrick') . '</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<div class="navigation">
<?php previous_link(); ?>
<?php next_link(); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(__('Edit this entry.', 'kubrick'), '<p>', '</p>'); ?>
</div>
<div class="progbar">
<?php echo get_post_meta($post->ID, 'percent', 1); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>