I've recently had to develop a context menu for a Google Maps API v3
map and decided that i'd share it with you all.
I searched and found no v3 context menu so hope this will be useful to
others.
Main project page:
http://code.martinpearman.co.uk/googlemapsapi/contextmenu/
Advanced example page:
http://code.martinpearman.co.uk/googlemapsapi/contextmenu/1.0/examples/advanced_example.htm
As always - constructive comments welcomed!
Thanks.
Martin.
On 11月21日, 下午5时00分, Martin(tm) <warwo...@gmail.com> wrote:
> Hi all.
>
> I've recently had to develop a context menu for a Google Maps API v3
> map and decided that i'd share it with you all.
>
> I searched and found no v3 context menu so hope this will be useful to
> others.
>
> Main project page:
>
> http://code.martinpearman.co.uk/googlemapsapi/contextmenu/
>
> Advanced example page:
>
> http://code.martinpearman.co.uk/googlemapsapi/contextmenu/1.0/example...
var pos = markerMenus.push(new ContextMenu(map, contextMenuOptions)) - 1;
google.maps.event.addListener(marker, 'rightclick', function(mouseEvent){
hideOtherMenus();
markerMenus[pos].show(mouseEvent.latLng);
});
function hideOtherMenus(){
addMenu.hide();
for(i=0;i<markerMenus.length;i++){
markerMenus[i].hide();
}
}
for(i=0;i<routeCoordinates.length-1;i++){
var tempCoords = [];
tempCoords.push(routeCoordinates[i].latLng);
tempCoords.push(routeCoordinates[i+1].latLng);
route.push(new google.maps.Polyline({
path: tempCoords,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 1,
map: map
}));
var leg = Math.round((~~distance(routeCoordinates[i], routeCoordinates[i+1])/1000));
legFormatted = (leg.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + unitsShort);
var contextMenuOptions={};
contextMenuOptions.classNames={menu:'context_menu displance_display', menuSeparator:'context_menu_separator'};
var menuItems=[];
menuItems.push({className:'context_menu_item', eventName:'distance_click', id:'distanceItem', label: legFormatted});
contextMenuOptions.menuItems=menuItems;
var pos = distanceLables.push(new ContextMenu(map, contextMenuOptions)) - 1;
google.maps.event.addListener(route[i], 'mouseover', function(mouseEvent){
distanceLables[pos].show(mouseEvent.latLng);
});
google.maps.event.addListener(route[i], 'mouseout', function(mouseEvent){
distanceLables[pos].hide();
});
}