[OpenLayers-Users] customizing permalink

Puneet Kishor punk.kish at gmail.com
Sat Jan 21 17:06:13 EST 2012


an update below --

On Jan 21, 2012, at 3:48 PM, Puneet Kishor wrote:

> 
> On Jan 19, 2012, at 7:23 PM, Stephen Woodbridge wrote:
> 
>> On 1/19/2012 6:54 PM, Puneet Kishor wrote:
>>> I want to add the permalink control to the map, but I don't want to display it as is out of the box. Or, to be more precise, I want to build my own permalink link so that I can add a few more custom params to the link that the control builds, and then do something with that link, for example, store it in the db, or pop it in a window, etc.
>>> 
>>> How can I do that?
>> 
>> Here is an example where are add additional parameters:
>> 
>> http://gis.imaptools.com/routing/leaddog/?zoom=14&lat=33.85749&lon=35.51971&layers=B0TTTF&start=35.493583%2033.826664&stop=35.565174%2033.864285&method=STS&lang=arb
>> 
>> Feel free to look at the page source to see how I did it.
> 
> 
> Great help, thanks. That got me started, but I don't have a working solution yet. Here is what is going on... I am trying to customize the permalink control using the following function
> 
>    var state = {};
> 
>    new OpenLayers.Control.Permalink(
>        "permalink", 
>        uri, 
>        {
>            "createParams": function() {
>                var args = OpenLayers.Control.Permalink.prototype.createParams.apply(
>                    this, arguments
>                );
> 
>                // add my args here
>                if (state) {
>                    for (var s in state) {
>                        args[s] = encodeURI(state[s]);
>                    }
>                }
> 
>                return args;
>            }
>        }
>    );
> 
> and then, in my map I have buttons that invoke different functionality. For example, one functionality is like so
> 
>    "doThat": function(a, b, c) {
> 
>        // update state
>        state = {
>            action: "doFoo",
>            params: {
>                a: a,
>                b: b,
>                c: c
>            }
>        };
> 
>        .. do something ..
>    };
> 
> My intent is to generate a permalink that looks like so
> 
>    http://server/app?zoom=6&lat=-1.35&lon=-38.14&layers=TB000TTTTT&action=doThat&a="foo"&b=43&c="bar"
> 
> The problem is, by the time doThat() is called and it updates state, the permalink has already been formed, so it doesn't yet have the updated values from "state". If I now move the map or do something else, that is when the permalink gets updated with the values from "state" but it is always one action behind … how do I get around this phase lag? In other words, I want to update the permalink *after* the "state" has been updated so that when "createParams" is called, it creates the correct permalink.
> 


one additional note: I don't want the actual link that the user would click to get the permalink to have the updated link. Instead, I want to actually fire off a function to do something with that link. Right now I am using something like so, which actually does work. Just want to confirm if there is a better way

	<a href="" id="permalink">permalink</a>

	$("#permalink").click(function() {
		doSomethingWithPermalink($(this).attr("href"));
	   	return false;
	});

For example, I might want to replace the href with '<div id="permalink"></div>'. In which case, how would I get the current value of permalink?

--
Puneet Kishor


More information about the Users mailing list