Friday, 4 November 2016

Problems getting openlayers permalink working


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);
}


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...