Changeset 83
- Timestamp:
- 07/10/07 16:57:01 (1 year ago)
- Files:
-
- branch/controllers/venues_controller.php (modified) (3 diffs)
- branch/views/venues/admin_add.ctp (modified) (2 diffs)
- branch/views/venues/admin_index.ctp (modified) (3 diffs)
- branch/views/venues/venuesjson.ctp (added)
- branch/webroot/js/jquery.gmapp.js (modified) (5 diffs)
- branch/webroot/js/webrocket.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branch/controllers/venues_controller.php
r79 r83 8 8 function admin_index() { 9 9 $this->Venue->recursive = 0; 10 $this->set('points', $this->Venue->findAll()); 10 11 $avg_lat = 0; 12 $avg_lon = 0; 13 $count=0; 14 15 $points = $this->Venue->findAll(); 16 17 foreach($points as $n=>$point){ 18 $avg_lat += $point['Venue']['latitude']; 19 $avg_lon += $point['Venue']['longitude']; 20 $count++; 21 } 22 23 $avg_lat = $avg_lat/$count; 24 $avg_lon = $avg_lon/$count; 25 $this->set('default', "center: [" . $avg_lat . "," . $avg_lon . "]"); 26 $this->set('points', $points); 11 27 } 12 28 … … 15 31 $this->render(); 16 32 } else { 17 $this->cleanUpFields(); 18 19 $address = $this->data['Venue']; 20 unset( 21 $address['id'], 22 $address['name'],$address['description'], 23 $address['latitude'], $address['longitude'], 24 $address['zoom'], $address['js'], 25 $address['created'], $address['modified'] 26 ); 27 var_dump($address); 28 vendor('googlegeo'); 29 $googleGeo = new GoogleGeo($address); 30 $geo = $googleGeo->geo(); 31 var_dump($geo); 32 $this->data = array_merge($this->data['Venue'],$geo); 33 33 $this->cleanUpFields(); 34 34 if($this->Venue->save($this->data)) { 35 35 $this->Session->setFlash('The Venue has been saved'); 36 //$this->redirect('/venues/index');36 $this->redirect('/venues/index'); 37 37 } else { 38 38 $this->Session->setFlash('Please correct errors below.'); … … 78 78 } 79 79 } 80 81 function venuesjson() 82 { 83 $this->layout = "ajax"; 84 $this->Venue->recursive = 0; 85 $this->set('points', $this->Venue->findAll()); 86 } 80 87 81 88 } branch/views/venues/admin_add.ctp
r81 r83 1 1 <h2>New Point</h2> 2 2 <?php e($javascript->codeBlock('$j().ready(function(){$j("#gmap").gmapp();});'));?> 3 3 <div id="gmap" style="float:left;width:800px;height:400px;"></div> 4 4 … … 21 21 <?php e($form->input('state'));?> 22 22 <?php e($form->input('postcode'));?> 23 <?php e($form->input('latitude'));?> 24 <?php e($form->input('longitude'));?> 23 25 <?php e($form->input('zoom'));?> 24 26 <?php e($form->submit());?> branch/views/venues/admin_index.ctp
r79 r83 1 1 <h2>List Venues</h2> 2 <div style="float:left;width:80%;">3 <?php4 $avg_lat = 0;5 $avg_lon = 0;6 $count=0;7 2 8 foreach($points as $n=>$point){ 9 $points[$n]['Venue']['title'] = "<b>".$point['Venue']['name']."</b>"; 10 $points[$n]['Venue']['html'] = $point['Venue']['description']; 11 $avg_lat += $point['Venue']['latitude']; 12 $avg_lon += $point['Venue']['longitude']; 13 $count++; 14 } 3 <?php e($javascript->codeBlock('$j().ready(function(){$j("#gmap").gmapp({' . $default . ', zoom: 9});});'));?> 15 4 16 $avg_lat = $avg_lat/$count; 17 $avg_lon = $avg_lon/$count; 18 //echo $avg_lat,' ',$avg_lon; 19 $default = array('type'=>'2','zoom'=>13,'lat'=>$avg_lat,'long'=>$avg_lon); 20 echo $googleMap->map($default, $style = 'width:100%; height: 800px' ); 21 //if(isset($points)){ 22 echo $googleMap->addMarkers($points); 23 // } 5 <div id="gmap" style="float:left;width:800px;height:400px;"></div> 24 6 25 26 ?>27 </div>28 <style>29 tr:hover {30 cursor: pointer;31 }32 </style>33 7 <div style="float:left;width:15%"> 34 8 <span style="font-size:12pt;font-weight:bold;background:#239855;"><?php echo $html->link('Create A New Venue', '/points/add'); ?></span> … … 40 14 </tr> 41 15 <?php foreach ($points as $point): ?> 42 <tr onclick="<?php echo $point['Venue']['js'] ?>">16 <tr> 43 17 <td><?php echo $point['Venue']['name'] ?></td> 44 18 <td><?php echo $point['Venue']['city'] ?></td> … … 47 21 <?php endforeach; ?> 48 22 </table> 49 50 <input type="text" id="postcode" size="10" />51 <input type="submit" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, setCenterToPoint)" value="Center Map"/>52 <input type="submit" value="Place Marker" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint)" />53 <input type="submit" value="Do whatever" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, function (point) { alert('Latitude: ' + point.lat() + '\nLongitude: ' + point.lng());})" />54 <br />55 <input id="lat" /><input id="lng" />56 23 </div> branch/webroot/js/jquery.gmapp.js
r82 r83 1 /* 2 * Google Map Application (GMApp) 3 * Author: Tane Piper (digitalspaghetti@gmail.com) 4 * Website: http://digitalspaghetti.tooum.net 5 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php 6 * 7 * === Changelog === 8 * Version 0.1 9 * + Initial Version 10 * 11 * === Instructions === 12 * Create your div and form. The form submit button must be called id="findaddress". 13 * Then insert your jQuery to activate (i.e. $('#mydiv').gmapp(); 14 * Now type in the address or postcode to search for the location you like, this will drop 15 * a marker there, which you can drag around. 16 */ 17 18 1 19 jQuery.gmapp = { 2 20 3 build : function(settings) { 21 buildApp : function(settings) { 22 23 var version = "0.1"; 4 24 5 25 /* Default Settings*/ … … 11 31 showtype: true, 12 32 showoverview: true, 13 infoarea: "#gmapp-info" 33 infoarea: "#gmapp-info", 34 geocode: "#Address", 35 latfield: "#VenueLatitude", 36 lngfield: "#VenueLongitude", 37 loadpoints: "/venues/", 38 savepoint: "save.php" 14 39 },settings); 15 40 … … 41 66 map.addControl(new GOverviewMapControl()); 42 67 } 68 /*jQuery(this).after('<p><strong>Google Map Application Version ' + version + '</strong></p>');*/ 43 69 44 70 /* Seach for the lat & lng of our address*/ 45 $('#findaddress').bind('click', function(){46 jQuery.gmapp.searchAddress( $('#Address').attr('value'), map, geocoder);71 jQuery('#findaddress').bind('click', function(){ 72 jQuery.gmapp.searchAddress(jQuery(settings.geocode).attr('value'), map, geocoder, infoarea); 47 73 }); 48 74 }); … … 50 76 }, 51 77 52 searchAddress : function(address, map,geocoder) {78 searchAddress : function(address, map, geocoder, infoarea) { 53 79 geocoder.getLatLng( 54 80 address, … … 58 84 } else { 59 85 map.setCenter(point,12); 60 var marker = new GMarker(point );86 var marker = new GMarker(point, {draggable: true}); 61 87 map.addOverlay(marker); 62 marker.openInfoWindowHtml(address); 88 marker.openInfoWindowHtml("Lat: " + point.lat() + " Lng: " + point.lng()); 89 GEvent.addListener(marker, "dragend", function(){ 90 mylocation = marker.getPoint(); 91 marker.openInfoWindowHtml("Latitude: " + mylocation.lat() + "<br />Longitude: " + mylocation.lng()); 92 }); 93 63 94 } 64 95 }); 96 }, 97 98 showAllPoints : function (map, settings) { 99 jQuery.get(settings.loadpoints); 65 100 } 66 101 } 67 102 68 jQuery.fn.gmapp = jQuery.gmapp.build ;103 jQuery.fn.gmapp = jQuery.gmapp.buildApp; branch/webroot/js/webrocket.js
r80 r83 59 59 }); 60 60 61 $('#gmap').gmapp();62 63 61 /*var options = { 64 62 target: '#content', // target element(s) to be updated with server response