You are not logged in.

#1 2009-02-22 21:11:04

xintao
Member
Registered: 2009-02-19
Posts: 46

How to make 0penLayers right-click support?

Dear all,

Hi, I have looked through the develop document and tried and tried, but I still can't make a right click menu in OpenStreetMap. Any of your suggetion is highly appreciated.

Thank you.

Sincerely,
Xintao

Offline

#2 2009-02-23 15:34:19

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: How to make 0penLayers right-click support?

I would ask on the OpenLayers mailinglist.

Offline

#3 2009-02-24 03:08:45

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: How to make 0penLayers right-click support?

Thanks emj, thank you. I have figured it out. The code works on my web mashup.

function init() {
            map = new OpenLayers.Map ("map", {
                controls:[
                    new OpenLayers.Control.Navigation(),
                    new OpenLayers.Control.PanZoomBar(),
                    new OpenLayers.Control.Attribution()],
                maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                maxResolution: 156543.0399,
                numZoomLevels: 19,
                units: 'm',
                projection: new OpenLayers.Projection("EPSG:900913"),
                displayProjection: new OpenLayers.Projection("EPSG:4326")
            } );
         
            layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender");           
            map.addLayers(layerTilesAtHome);           
                   
             map.div.oncontextmenu = function noContextMenu(e) {
             if (OpenLayers.Event.isRightClick(e)){
                 alert("Right button click"); // Add the right click menu here
              }
        return false; //cancel the right click of brower
       };
            
            var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);               
    }

Last edited by xintao (2009-02-24 03:09:46)

Offline

#4 2009-02-24 08:07:05

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: How to make 0penLayers right-click support?

thank you for the solution..

Offline

Board footer

Powered by FluxBB