Page 1 of 1

Button on the map.

Posted: Thu Nov 07, 2013 10:34 am
by laura6372139

Hello!

I have a question!

Can I put a button on my map ?

I add an image. I want to something similar.

Thaks! Image


Button on the map.

Posted: Thu Nov 07, 2013 11:21 am
by Maryna Brodina

Hi, you would need to check Google maps API https://developers.google.com/maps/do.... Here you can find the list of supported by Google maps features and detailed description on how to implement it.


Button on the map.

Posted: Thu Nov 07, 2013 11:40 am
by laura6372139

ok! thaks!


Button on the map.

Posted: Thu Nov 07, 2013 12:23 pm
by laura6372139

Hello! I put this code but I don't load de map!

var map;
var chicago = new google.maps.LatLng(38.845, -0.468);

function HomeControl(controlDiv, map) {

controlDiv.style.padding = '5px';

var controlUI = document.createElement('div');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '2px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to set the map to Home';
controlDiv.appendChild(controlUI);

// Set CSS for the control interio
var controlText = document.createElement('div');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '12px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.innerHTML = 'Home';
controlUI.appendChild(controlText);

google.maps.event.addDomListener(controlUI, 'click', function() {
map.setCenter(chicago)
});

}

function initialize() {
var mapDiv = document.getElementById('googlemap_1');
var myOptions = {
zoom :10,
center: new google.maps.LatLng(38.845, -0.468),
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map($('div[dsid="googlemap_1"]').get(0), myOptions);

var homeControlDiv = document.createElement('div');
var homeControl = new HomeControl(homeControlDiv, map);

homeControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
}

google.maps.event.addDomListener(window, 'load', initialize);


Button on the map.

Posted: Thu Nov 07, 2013 12:36 pm
by Maryna Brodina

Could you clarify where did you put that code. Also please check console, are there any errors?


Button on the map.

Posted: Thu Nov 07, 2013 3:21 pm
by laura6372139

event < load < run javascript.

The console say me:

Image


Button on the map.

Posted: Thu Nov 07, 2013 4:13 pm
by laura6372139

Now I have loaded this code but does not work...

var map;
var chicago = new google.maps.LatLng(38.82074, -0.6122);

/**

  • 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;
    }

    /** @constructor */
    function HomeControl(controlDiv, map, home) {

    // We set up a variable for this since we're adding
    // event listeners later.
    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.style.backgroundColor = 'white';
    goHomeUI.style.borderStyle = 'solid';
    goHomeUI.style.borderWidth = '2px';
    goHomeUI.style.cursor = 'pointer';
    goHomeUI.style.textAlign = 'center';
    goHomeUI.title = 'Click to set the map to Home';
    controlDiv.appendChild(goHomeUI);

    // Set CSS for the control interior
    var goHomeText = document.createElement('div');
    goHomeText.style.fontFamily = 'Arial,sans-serif';
    goHomeText.style.fontSize = '12px';
    goHomeText.style.paddingLeft = '4px';
    goHomeText.style.paddingRight = '4px';
    goHomeText.innerHTML = 'Home';
    goHomeUI.appendChild(goHomeText);

    // Set CSS for the setHome control border
    var setHomeUI = document.createElement('div');
    setHomeUI.style.backgroundColor = 'white';
    setHomeUI.style.borderStyle = 'solid';
    setHomeUI.style.borderWidth = '2px';
    setHomeUI.style.cursor = 'pointer';
    setHomeUI.style.textAlign = 'center';
    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.style.fontFamily = 'Arial,sans-serif';
    setHomeText.style.fontSize = '12px';
    setHomeText.style.paddingLeft = '4px';
    setHomeText.style.paddingRight = '4px';
    setHomeText.innerHTML = 'Set Home';
    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 = Appery("googlemap_1").gmap;
    var myOptions = {
    zoom: 12,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(mapDiv, mapOptions);

    // 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(homeControlDiv, map, chicago);

    homeControlDiv.index = 1;
    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
    }

    google.maps.event.addDomListener(window, 'load', initialize);


Button on the map.

Posted: Thu Nov 07, 2013 10:09 pm
by Kateryna Grynko

Hi Laura,

Sorry, no news yet. We are working on it.


Button on the map.

Posted: Fri Nov 08, 2013 8:51 am
by Oleg Danchenkov

You have few errors. Try this code:
precode
var map;
var chicago = new google&#46;maps&#46;LatLng(38&#46;82074, -0&#46;6122);

&#47;**

  • The HomeControl adds a control to the map that

  • returns the user to the control's defined home&#46;
    *&#47;

    &#47;&#47; Define a property to hold the Home state
    HomeControl&#46;prototype&#46;home_ = null;

    &#47;&#47; Define setters and getters for this property
    HomeControl&#46;prototype&#46;getHome = function() {
    return this&#46;home_;
    }

    HomeControl&#46;prototype&#46;setHome = function(home) {
    this&#46;home_ = home;
    }

    &#47;** @constructor *&#47;
    function HomeControl(controlDiv, map, home) {

    &#47;&#47; We set up a variable for this since we're adding
    &#47;&#47; event listeners later&#46;
    var control = this;

    &#47;&#47; Set the home property upon construction
    control&#46;home_ = home;

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

    &#47;&#47; Set CSS for the control border
    var goHomeUI = document&#46;createElement('div');
    goHomeUI&#46;style&#46;backgroundColor = 'white';
    goHomeUI&#46;style&#46;borderStyle = 'solid';
    goHomeUI&#46;style&#46;borderWidth = '2px';
    goHomeUI&#46;style&#46;cursor = 'pointer';
    goHomeUI&#46;style&#46;textAlign = 'center';
    goHomeUI&#46;title = 'Click to set the map to Home';
    controlDiv&#46;appendChild(goHomeUI);

    &#47;&#47; Set CSS for the control interior
    var goHomeText = document&#46;createElement('div');
    goHomeText&#46;style&#46;fontFamily = 'Arial,sans-serif';
    goHomeText&#46;style&#46;fontSize = '12px';
    goHomeText&#46;style&#46;paddingLeft = '4px';
    goHomeText&#46;style&#46;paddingRight = '4px';
    goHomeText&#46;innerHTML = '<b>Home<&#47;b>';
    goHomeUI&#46;appendChild(goHomeText);

    &#47;&#47; Set CSS for the setHome control border
    var setHomeUI = document&#46;createElement('div');
    setHomeUI&#46;style&#46;backgroundColor = 'white';
    setHomeUI&#46;style&#46;borderStyle = 'solid';
    setHomeUI&#46;style&#46;borderWidth = '2px';
    setHomeUI&#46;style&#46;cursor = 'pointer';
    setHomeUI&#46;style&#46;textAlign = 'center';
    setHomeUI&#46;title = 'Click to set Home to the current center';
    controlDiv&#46;appendChild(setHomeUI);

    &#47;&#47; Set CSS for the control interior
    var setHomeText = document&#46;createElement('div');
    setHomeText&#46;style&#46;fontFamily = 'Arial,sans-serif';
    setHomeText&#46;style&#46;fontSize = '12px';
    setHomeText&#46;style&#46;paddingLeft = '4px';
    setHomeText&#46;style&#46;paddingRight = '4px';
    setHomeText&#46;innerHTML = '<b>Set Home<&#47;b>';
    setHomeUI&#46;appendChild(setHomeText);

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

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

    function initialize() {
    var mapDiv = $("[dsid=googlemap_1]")[0];
    var mapOptions = {
    zoom: 12,
    center: chicago,
    mapTypeId: google&#46;maps&#46;MapTypeId&#46;ROADMAP
    }
    var map = new google&#46;maps&#46;Map(mapDiv, mapOptions);
    &#47;&#47; Create the DIV to hold the control and
    &#47;&#47; call the HomeControl() constructor passing
    &#47;&#47; in this DIV&#46;
    var homeControlDiv = document&#46;createElement('div');
    var homeControl = new HomeControl(homeControlDiv, map, chicago);
    homeControlDiv&#46;index = 1;
    map&#46;controls[google&#46;maps&#46;ControlPosition&#46;TOP_RIGHT]&#46;push(homeControlDiv);
    }

    google&#46;maps&#46;event&#46;addDomListener(window, 'load', initialize);
    /code/pre