Giter Club home page Giter Club logo

Comments (11)

ahocevar avatar ahocevar commented on July 2, 2024

Looks like every application likes or dislikes different callback function names - see 541b3dc. Potential fix: the patch below (untested), and set the callbackTemplate to e.g. "OpenLayers.Protocol.Script.registry_${id}".

diff --git a/lib/OpenLayers/Protocol/Script.js b/lib/OpenLayers/Protocol/Script.js
index 49e332b..2e42c55 100644
--- a/lib/OpenLayers/Protocol/Script.js
+++ b/lib/OpenLayers/Protocol/Script.js
@@ -52,6 +52,13 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
      * {Object} Function to be called when the <read> operation completes.
      */
     callback: null,
+    
+    /**
+     * APIProperty: callbackTemplate
+     * {String} Template for creating a unique callback function name. Should
+     * include ${id}. Default is "OpenLayers.Protocol.Script.registry[${id}]".
+     */
+    callbackTemplate: "OpenLayers.Protocol.Script.registry[${id}]",

     /**
      * APIProperty: scope
@@ -212,7 +219,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
      */
     createRequest: function(url, params, callback) {
         var id = OpenLayers.Protocol.Script.register(callback);
-        var name = "OpenLayers.Protocol.Script.registry[" + id + "]";
+        var name = OpenLayers.String.format(this.callbackTemplate, {id: id});
         params = OpenLayers.Util.extend({}, params);
         params[this.callbackKey] = this.callbackPrefix + name;
         url = OpenLayers.Util.urlAppend(

from ol2.

probins avatar probins commented on July 2, 2024

thanks for the prompt reply. That won't work in itself: it works fine with Google, but when the data comes back it expects to find a function called ...registry_1 which doesn't exist. If I redefine registry as an object (looks like it was originally an object but changed to an array with the commit you refer to) and use something like

var id = 'r'+(++counter);
o.registry[id] = function() {

with

var name = "OpenLayers.Protocol.Script.registry." + id;

then it works.

If people are ok with this change, I'll issue a pull request, but there is an additional complication in that the documented server one is supposed to send to returns a 302 Temporarily Moved, and it looks like this response triggers unregister() so when the redirected response comes back the function isn't there any more :-( Ho hum. For the moment, I have commented out unregister(), but I suppose there should be a check in there for non-200 responses - or just get rid of unregister() altogether, as it doesn't really harm much keeping the entries in there..

from ol2.

vmx avatar vmx commented on July 2, 2024

I suggest to change the default template to the one without brackets.

It will change the URL OpenLayers does the requests, but I don't see any problems with it. I don't think anyone should depend on the callback name of OpenLayers.

If we have a callback without braces or brackets, but just characters and dots, I think it should work well across all JSONP server implementations.

from ol2.

probins avatar probins commented on July 2, 2024

Fixed with #207

@vmx I don't know that there are that many servers which don't accept [], so I've no problems myself with having that as the default. If we find this causes problems, we can always change it later.

from ol2.

vmx avatar vmx commented on July 2, 2024

@probins I would expect OpenLayers' JSONP to work with all major services work. And I'd call a Google service major :)
To as the reverse question, why shouldn't we make it the default?

from ol2.

probins avatar probins commented on July 2, 2024

good question! If you feel strongly about this, submit a pull request. I would also point out that when Fusion Tables was first released, it wouldn't even accept dots in the callback name. :-)

from ol2.

tschaub avatar tschaub commented on July 2, 2024

@vmx @probins - see 609e5f7 (included in #341)

@vmx - do you have an example using Fusion Tables?

from ol2.

vmx avatar vmx commented on July 2, 2024

@tschaub I don't use Google Fusion tables. But when I take this URL from Google's example page, extract the URL for the JSONP request and replace the callback name with an OpenLayers style callback it seems to work:

https://apis.google.com//apps-static//js/gapi/gcm_ppb,googleapis_client,plusone/rt=j/ver=LcJa8SIK_wY.en./sv=1/am=!brN6X75-Zu-IDRYPeA/d=1/cb=OpenLayers.Protocol.Script.registry.c2

You try with square brackets, to see that it won't work.

from ol2.

probins avatar probins commented on July 2, 2024

https://www.google.com/fusiontables/api/query?sql=select%20*%20from%20187777&jsonCallback=OpenLayers.Protocol.Script.registry["c1"]

from ol2.

tschaub avatar tschaub commented on July 2, 2024

@vmx @probins - Thanks. I believed that the brackets were an issue. Was thinking it would be nice to have an example using Fusion Tables in the examples dir. Ideally (if we can rely on the service being accessible) we could have a test case too.

from ol2.

probins avatar probins commented on July 2, 2024

@tschaub I do have an example of using OL to display features from a Fusion Tables table, that I wrote as a demo a couple of years ago. This does not use Protocol/Script but, now that Script will work with GFT, I could quite easily adapt it to do so and also standardise it to the OL example pattern.
Longer-term I think GFT is potentially a good publicly available place for feature storage (it runs on Google's servers, so I don't think there's any problems of accessibility), so have written some functions to do the full CRUD. This still needs some tweaking, and there are still some issues on Google's side which would simplify things if fixed, but I should have something ready for people to look at in a month or two.

from ol2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.