Change the position of certain buttons

  • Driessen
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 11 months ago - 11 years 11 months ago #658 by Driessen
Change the position of certain buttons was created by Driessen
Hi, i like to change the position of certain buttons
and create my own if possible (like in google
documentation samples see link ).
For instance i like to position the location button
by px to the right and up.

Regards Ton
Last edit: 11 years 11 months ago by Driessen.

Please Log in or Create an account to join the conversation.

More
11 years 11 months ago #660 by Dima
Hi Ton.
You can set positions in "Control Positions" slider of map.
But where you find out you can set px-position.

Don't forget support my developments: post review in JED , donate , help with translation ;)

Please Log in or Create an account to join the conversation.

  • Driessen
  • Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 11 months ago - 11 years 11 months ago #661 by Driessen
Replied by Driessen on topic Re: Change the position of certain buttons
In the documentation of google maps i read about Positioning Custom Map Controls and
looked at the samples and thought that it could be possible to do it also with the existing controls.
I found the set home and home control interesting because you can set a marker as home creat a route to it?

View example (control-custom-state.html)
Adding State to Controls

Controls may also store state. The following example is similar to that shown before, but the control contains an additional "Set Home" button which sets the control to exhibit a new home location. We do so by creating a home_ property within the control to store this state and provide getters and setters for that state.

var map;
var chicago = new google.maps.LatLng(41.850033, -87.6500523);

/**
 * The HomeControl adds a control to the map that
 * returns the user to the control's defined home.
 */

// Define a property to hold the Home state.
HomeControl.prototype.home_ = null;

// Define setters and getters for this property.
HomeControl.prototype.getHome = function() {
  return this.home_;
}

HomeControl.prototype.setHome = function(home) {
  this.home_ = home;
}

function HomeControl(map, div, home) {

  // Get the control DIV. We'll attach our control UI to this DIV.
  var controlDiv = div;

  // We set up a variable for the 'this' keyword since we're adding event
  // listeners later and 'this' will be out of scope.
  var control = this;

  // Set the home property upon construction.
  control.home_ = home;

  // Set CSS styles for the DIV containing the control. Setting padding to
  // 5 px will offset the control from the edge of the map.
  controlDiv.style.padding = '5px';

  // Set CSS for the control border.
  var goHomeUI = document.createElement('div');
  goHomeUI.title = 'Click to set the map to Home';
  controlDiv.appendChild(goHomeUI);

  // Set CSS for the control interior.
  var goHomeText = document.createElement('div');
  goHomeText.innerHTML = '<strong>Home<strong>
  goHomeUI.appendChild(goHomeText);

  // Set CSS for the setHome control border.
  var setHomeUI = document.createElement('div');
  setHomeUI.title = 'Click to set Home to the current center';
  controlDiv.appendChild(setHomeUI);

  // Set CSS for the control interior.
  var setHomeText = document.createElement('div');
  setHomeText.innerHTML = '<strong>Set Home<strong>
  setHomeUI.appendChild(setHomeText);

  // Setup the click event listener for Home:
  // simply set the map to the control's current home property.
  google.maps.event.addDomListener(goHomeUI, 'click', function() {
    var currentHome = control.getHome();
    map.setCenter(currentHome);
  });

  // Setup the click event listener for Set Home:
  // Set the control's home to the current Map center.
  google.maps.event.addDomListener(setHomeUI, 'click', function() {
    var newHome = map.getCenter();
    control.setHome(newHome);
  });
}

function initialize() {
  var mapDiv = document.getElementById('map_canvas');
  var myOptions = {
    zoom: 12,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(mapDiv, myOptions);

  // Create the DIV to hold the control and call the HomeControl()
  // constructor passing in this DIV.
  var homeControlDiv = document.createElement('div');
  var homeControl = new HomeControl(map, homeControlDiv, chicago);

  homeControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
}
Last edit: 11 years 11 months ago by Driessen.

Please Log in or Create an account to join the conversation.

More
11 years 11 months ago #692 by Dima
Hi

In this example your custom control positioning into top right
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);

Don't forget support my developments: post review in JED , donate , help with translation ;)

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds

Donate


Go to top