Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

GoogleMapAPI: Draggable Markers and MouseWheel Zoom

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
wolfgang
Smarty n00b


Joined: 23 May 2008
Posts: 1

PostPosted: Fri May 23, 2008 3:38 pm    Post subject: GoogleMapAPI: Draggable Markers and MouseWheel Zoom Reply with quote

To zoom by MouseWheel just add the following line to function getMapJS()

Code:
 
$_output .= 'map.enableScrollWheelZoom();'."\n";


If you like draggable markers:

Code:

var $draggable = false;
// Make Marker draggable and output coords to "coords_lat" and "coords_lon"
function enableDraggable() {
  $this->draggable = true;
}
// disable draggable Markers
function disableDraggable() {
  $this->draggable = false;
}


Change following in getCreateMarkerJS:

Code:

if(!empty($this->_icons)) {
  if($this->draggable) {
    $_output .= 'var marker = new GMarker(point,{\'icon\': icon[n], \'draggable\': true, \'title\': tooltip});' . "\n";
  } else {
    $_output .= 'var marker = new GMarker(point,{\'icon\': icon[n], \'title\': tooltip});' . "\n";
  }
} else {
  if($this->draggable) {
    $_output .= 'var marker = new GMarker(point,{\'draggable\': true, \'title\': tooltip});' . "\n";
  } else {
    $_output .= 'var marker = new GMarker(point,{\'title\': tooltip});' . "\n";
  }
}


Add the following at the end of this function, before "return marker;":

Code:
 
if($this->draggable) {
  $_output .= 'marker.enableDragging();'."\n";
  $_output .= 'GEvent.addListener(marker, "drag", function(){ ';
  $_output .= 'document.getElementById("coords_lat").value=marker.getPoint().lat();';
  $_output .= 'document.getElementById("coords_lon").value=marker.getPoint().lng();';
  $_output .= '});'."\n";
}


This could be implemented smarter I think, maybe the author could do it, who has done a great job btw.

Comments and tips welcome, have a look in action at www.bandliste.de
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP