about ControlPosition optionally specify an offset

661 views
Skip to first unread message

YeeFung Man

unread,
Apr 1, 2011, 12:01:33 AM4/1/11
to Google Maps JavaScript API v3
hi,everybody!
      i have a problem about how to change some codes from v2 to v3. the codes in v2 is that"var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,20)); "  ,then i can find the "ControlPosition"in v3,but it has no Parameters,i don't know how to optionally specify an offset.
      thanks a lot!!!

Martin™

unread,
Apr 1, 2011, 2:53:01 AM4/1/11
to Google Maps JavaScript API v3
Use CSS margin styles on your custom control element.

<div id="myControl" style="margin-left:10px; margin-top:20px">my html</
div>

Martin.

YeeFung Man

unread,
Apr 1, 2011, 3:01:01 AM4/1/11
to google-map...@googlegroups.com
thanks a lot.
but I wonder whether Google api has a similar function,thank you.

2011/4/1 Martin™ <warw...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


en4ce

unread,
Apr 1, 2011, 3:26:36 AM4/1/11
to Google Maps JavaScript API v3
maybe like that ?

var customMapControls = document.createElement('div');
var customMapControlsExtra = document.createElement('div');

customControlDiv =
document.getElementById("filterspot").innerHTML;
extaControlDiv = document.getElementById("extralayers").innerHTML;

customMapControlsExtra = extaControlDiv;
customMapControls.innerHTML = customControlDiv
+""+customMapControlsExtra;

customMapControls.id = "customMapControls";
customMapControlsExtra.id = "customMapControlsExtras";


map.controls[google.maps.ControlPosition.RIGHT_TOP].push(customMapControls);

On 1 Apr., 09:01, YeeFung Man <angel14yeef...@gmail.com> wrote:
> thanks a lot.
> but I wonder whether Google api has a similar function,thank you.
>
> 2011/4/1 Martin™ <warwo...@gmail.com>

YeeFung Man

unread,
Apr 1, 2011, 4:04:02 AM4/1/11
to google-map...@googlegroups.com
      thanks.
      i just want to create a control about "right click Menu",so i must let the control optionally specify an offset from right-click's location.
      the following codes found on Internet  are written using v2.
     GEvent.addListener(map,"singlerightclick",function(pixel,tile) 
     { 
         clickedPixel = pixel; 
         var x=pixel.x; 
         var y=pixel.y; 
         if (x > map.getSize().width - 120) 
         { 
           x = map.getSize().width - 120 
         } 
         if (y > map.getSize().height - 100) 
         { 
           y = map.getSize().height - 100 
         } 
         var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y)); 
         pos.apply(contextmenu); 
         contextmenu.style.visibility = "visible"; 
    }); 
      thanks again.


2011/4/1 en4ce <dje...@googlemail.com>
GEvent_Right_Menu.html

Martin™

unread,
Apr 1, 2011, 4:19:19 AM4/1/11
to Google Maps JavaScript API v3
I'm sure my solution is the only one to be honest.

Look at the tutorial map:
http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html

Use Firefox and Firebug and inspect the map type control.
The outmost element of the map type control is a div with CSS style
margin:5px:

<div class="gmnoprint" style="margin: 5px; z-index: 11; position:
absolute; cursor: pointer; right: 0px; top: 0px;">
// more html here
</div>

Martin.


On Apr 1, 8:01 am, YeeFung Man <angel14yeef...@gmail.com> wrote:
> thanks a lot.
> but I wonder whether Google api has a similar function,thank you.
>
> 2011/4/1 Martin™ <warwo...@gmail.com>

YeeFung Man

unread,
Apr 1, 2011, 4:23:59 AM4/1/11
to google-map...@googlegroups.com
thank you very much!!!

2011/4/1 Martin™ <warw...@gmail.com>
Reply all
Reply to author
Forward
0 new messages