0

I set up an openlayers permalink function. I set the code and it shows up. But the URL does not work. Where is I get a link like this: http://babkart.no/?zoom=9&lat=7016094.01622&lon=121216.28057&layers=BFFFTTTTTF

The only thing that works is the chosen layers. It does not show the correct zoom or boundingbox. What do I need in the code to get this to work? I can not see I have any variables like "lat", "lon" or "zoom". Any examples as how to get this to work? I also would like to put the permalink in the toolbar so that one can copy the URL. I am using ExtJS 2.2. But this is another issue and I have to get the permalink to work first.

I add the permalink like this:

controls: [new OpenLayers.Control.KeyboardDefaults(),new OpenLayers.Control.PanZoomBar(),new OpenLayers.Control.ScaleLine(),
                new OpenLayers.Control.Navigation(),new OpenLayers.Control.Permalink()]

My app.js is here if anyone wants to take a look: http://pastebin.com/AstbpBWV The site is running here: http://babkart.no/

~asle

I got this to work this way. Don't know if it was good or bad but it seems to work: I use a function to zoom in to a location and added functionality to just zoom in to the view. I use the OpenLayers.Permalink() function.

        // If URL contains ref. to a location:
        var args = OpenLayers.Util.getParameters();
        if (args.x && args.y) {
            var position = new OpenLayers.LonLat(parseFloat(args.x), parseFloat(args.y));
            map.setCenter(position, 14);
            var xy = map.getViewPortPxFromLonLat(position);
            xy.x = Math.round(xy.x);
            xy.y = Math.round(xy.y);
            info.getInfoForClick({xy: xy});
        } // read the permalink URL
        else if (args.lat && args.lon && args.zoom) {
            var position = new OpenLayers.LonLat(parseFloat(args.lon), parseFloat(args.lat));
            map.setCenter(position, parseFloat(args.zoom));
        }
        else {
                map.setCenter(new OpenLayers.LonLat(528277, 7188837), 3);
        }

1 Answer 1

1

It looks like you use GeoExt. There is own permalink mechanism for using within GeoExt. See docs and example.

2
  • Thanks. I am using Mapfish and Extjs and there are GeoExt components but when I use the GeoExt sample I get errors. Sorry I did not make this solution all by myself so I am a bit confused. When I use the code from the GeoExt docs or example I get error. It does not understand: var permalinkProvider = new GeoExt.state.PermalinkProvider(); Where do I start to look? It seems that the OpenLayers.permalink is accepted but it does not understand the params for zoom,lat,lon.
    – asle
    Commented May 24, 2012 at 8:25
  • I see the code in the javascript for "Ext.extend(Ext.state.CookieProvider,Ext.state.Provider....." so it seems I could use that but maybe where exactly to put it in my app.js is the problem?
    – asle
    Commented May 24, 2012 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.