javascript - How to create and bind a context menu with array of markers on the Google map? -


i working on treasure hunting project using jsp, postgres , tomcat. after logging in, should allow admin specify map location, add various objects (like treasure , npcs saved in database) map , able copy, paste , delete objects. login, , insert objects of various types, working want enable right-click context menu each marker give admin 3-4 options; copy, paste, delete, edit.

to achieve this, have found link useful source code context menu provided: http://code.martinpearman.co.uk/googlemapsapi/contextmenu/1.0/src/contextmenu.js

i created contextmenu.js file , copied above code , have following function in jsp file. please note i'm retrieving list of markers database json object , looping through create , place markers on map.

function drawmap(){             var markers = {};             var contextmenu;      var contextmenuoptions={};     contextmenuoptions.classnames={menu:'context_menu',      menuseparator:'context_menu_separator'};      //  create array of contextmenuitem objects     var menuitems=[];      menuitems.push({id: "copy", classname:'context_menu_item',      eventname:'copy_click', label:'copy'});      menuitems.push({id: "paste", classname:'context_menu_item',      eventname:'paste_click', label:'paste'});      menuitems.push({id: "delete", classname:'context_menu_item',      eventname:'delete_click', label:'delete'});      contextmenuoptions.menuitems=menuitems;              lat='43.56873147104461';             lng='-79.76628009520937';              map = new google.maps.map(                     document.getelementbyid("map_container"), {                       center: new google.maps.latlng(lat,lng),                       zoom: 15,                       maptypeid: google.maps.maptypeid.roadmap                     });  json ='<%=request.getsession().getattribute("data")%>'                  json = json.parse(json);                   (i = 0; <= json.length; i++) {                     var lt,ln;                      lat = json[i].latstr;                     lng = json[i].lngstr;                  marker = new google.maps.marker({                         position:  new google.maps.latlng(lat, lng),                         map: map                     });            contextmenu = new contextmenu(map, contextmenuoptions); //stops @ point             google.maps.event.addlistener(marker, 'rightclick',function(e) {            contextmenu.show(e.latlng);                   });         }  //end loop    google.maps.event.addlistener(contextmenu, 'menu_item_selected',    function(object, latlng, eventname){         //  latlng position of contextmenu         //  eventname eventname defined clicked              contextmenuitem in contextmenuoptions             switch(eventname){                 case 'copy_click':                     copyobject(object);                     break;                 case 'paste_click':                     pasteobject(object, latlng);                     break;                 case 'delete_click':                     deleteobject(object);                     break;             }         }); }   //end function drawmap(); 

i not sure problem is. when run program, displays first marker on map , right-click nothing , have tried alert("hi"); check problem. stops @

contextmenu = new contextmenu(map, contextmenuoptions); 

i tried put alert inside contextmenu function , stops @ second line

this.setmap(map); 

when comment out, goes beyond point, displays markers in loop right-click nothing. means contextmenu.show(e.latlng); not working. may have loop.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -