Permalink
Browse files

Allow create context menus for markers

  • Loading branch information...
1 parent 8b87f70 commit cc32588f88843622c7e878d623d4baa59033b54f @hpneo committed Dec 24, 2012
Showing with 31 additions and 3 deletions.
  1. +4 −0 README.md
  2. +10 −0 examples/context_menu.html
  3. +17 −3 gmaps.js
View
4 README.md
@@ -8,6 +8,10 @@ Visit the examples in [hpneo.github.com/gmaps](http://hpneo.github.com/gmaps/)
Changelog
---------
+0.2.27
+-----------------------
+* Allow create context menus for markers
+
0.2.26
-----------------------
* Fix bug in getElevations
View
10 examples/context_menu.html
@@ -37,6 +37,16 @@
}
}]
});
+ map.setContextMenu({
+ control: 'marker',
+ options: [{
+ title: 'Center here',
+ name: 'center_here',
+ action: function(e){
+ this.setCenter(e.latLng.lat(), e.latLng.lng());
+ }
+ }]
+ });
});
</script>
</head>
View
20 gmaps.js
@@ -1,5 +1,5 @@
/*!
- * GMaps.js v0.2.26
+ * GMaps.js v0.2.27
* http://hpneo.github.com/gmaps/
*
* Copyright 2012, Gustavo Leon
@@ -134,7 +134,7 @@ if(window.google && window.google.maps){
var context_menu_items_count = context_menu_items.length;
- for(var i=0;i<context_menu_items_count;i++){
+ for(var i = 0; i < context_menu_items_count; i++){
var context_menu_item = context_menu_items[i];
var assign_menu_item_action = function(ev){
@@ -251,7 +251,9 @@ if(window.google && window.google.maps){
options.rightclick.apply(this, [e]);
}
- buildContextMenu('map', e);
+ if(window.context_menu['map'] != undefined) {
+ buildContextMenu('map', e);
+ }
});
this.refresh = function() {
@@ -443,6 +445,18 @@ if(window.google && window.google.maps){
}
});
+ google.maps.event.addListener(marker, 'rightclick', function(e) {
+ e.marker = this;
+
+ if (options.rightclick) {
+ options.rightclick.apply(this, [e]);
+ }
+
+ if (window.context_menu['marker'] != undefined) {
+ buildContextMenu('marker', e);
+ }
+ });
+
if (options.dragend || marker.fences) {
google.maps.event.addListener(marker, 'dragend', function() {
if (marker.fences) {

0 comments on commit cc32588

Please sign in to comment.