Assembla home | Assembla project page
 

Changeset 83

Show
Ignore:
Timestamp:
07/10/07 16:57:01 (1 year ago)
Author:
digitalspaghetti
Message:

Working on GMapp

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branch/controllers/venues_controller.php

    r79 r83  
    88        function admin_index() { 
    99                $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); 
    1127        } 
    1228 
     
    1531                        $this->render(); 
    1632                } 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();                  
    3434                        if($this->Venue->save($this->data)) { 
    3535                                $this->Session->setFlash('The Venue has been saved'); 
    36                                 //$this->redirect('/venues/index'); 
     36                                $this->redirect('/venues/index'); 
    3737                        } else { 
    3838                                $this->Session->setFlash('Please correct errors below.'); 
     
    7878                } 
    7979        } 
     80         
     81        function venuesjson() 
     82        { 
     83                $this->layout = "ajax"; 
     84                $this->Venue->recursive = 0; 
     85                $this->set('points', $this->Venue->findAll());   
     86        } 
    8087 
    8188} 
  • branch/views/venues/admin_add.ctp

    r81 r83  
    11<h2>New Point</h2> 
    2  
     2<?php e($javascript->codeBlock('$j().ready(function(){$j("#gmap").gmapp();});'));?> 
    33<div id="gmap" style="float:left;width:800px;height:400px;"></div> 
    44 
     
    2121<?php e($form->input('state'));?> 
    2222<?php e($form->input('postcode'));?> 
     23<?php e($form->input('latitude'));?> 
     24<?php e($form->input('longitude'));?> 
    2325<?php e($form->input('zoom'));?> 
    2426<?php e($form->submit());?> 
  • branch/views/venues/admin_index.ctp

    r79 r83  
    11<h2>List Venues</h2> 
    2 <div style="float:left;width:80%;"> 
    3 <?php 
    4 $avg_lat = 0; 
    5 $avg_lon = 0; 
    6 $count=0; 
    72 
    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});});'));?> 
    154 
    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> 
    246 
    25  
    26 ?> 
    27 </div> 
    28 <style> 
    29 tr:hover { 
    30         cursor: pointer; 
    31         } 
    32 </style> 
    337<div style="float:left;width:15%"> 
    348        <span style="font-size:12pt;font-weight:bold;background:#239855;"><?php echo $html->link('Create A New Venue', '/points/add'); ?></span> 
     
    4014</tr> 
    4115<?php foreach ($points as $point): ?> 
    42 <tr onclick="<?php echo $point['Venue']['js'] ?>" 
     16<tr
    4317        <td><?php echo $point['Venue']['name'] ?></td> 
    4418        <td><?php echo $point['Venue']['city'] ?></td> 
     
    4721<?php endforeach; ?> 
    4822</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" /> 
    5623</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 
    119jQuery.gmapp = { 
    220         
    3         build : function(settings) { 
     21        buildApp : function(settings) { 
     22                 
     23                var version = "0.1"; 
    424                 
    525                /* Default Settings*/    
     
    1131                        showtype: true, 
    1232                        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" 
    1439                },settings); 
    1540                 
     
    4166                                        map.addControl(new GOverviewMapControl()); 
    4267                                } 
     68                                /*jQuery(this).after('<p><strong>Google Map Application Version ' + version + '</strong></p>');*/ 
    4369                                 
    4470                                /* 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); 
    4773                                });      
    4874                        }); 
     
    5076        }, 
    5177         
    52         searchAddress : function(address,map,geocoder) { 
     78        searchAddress : function(address, map, geocoder, infoarea) { 
    5379                geocoder.getLatLng( 
    5480                address, 
     
    5884                        } else { 
    5985                                map.setCenter(point,12); 
    60                                 var marker = new GMarker(point); 
     86                                var marker = new GMarker(point, {draggable: true}); 
    6187                                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                                 
    6394                        } 
    6495                }); 
     96        }, 
     97         
     98        showAllPoints : function (map, settings) { 
     99                jQuery.get(settings.loadpoints); 
    65100        } 
    66101} 
    67102 
    68 jQuery.fn.gmapp = jQuery.gmapp.build
     103jQuery.fn.gmapp = jQuery.gmapp.buildApp
  • branch/webroot/js/webrocket.js

    r80 r83  
    5959        }); 
    6060         
    61         $('#gmap').gmapp(); 
    62          
    6361        /*var options = {  
    6462        target:        '#content',   // target element(s) to be updated with server response