Comments (11)
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.
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.
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.
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.
@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.
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.
@vmx @probins - see 609e5f7 (included in #341)
@vmx - do you have an example using Fusion Tables?
from ol2.
@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:
You try with square brackets, to see that it won't work.
from ol2.
from ol2.
@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.
@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)
- Maps do not pan in Chrome 55 or Microsoft Edge HOT 2
- implement openlayers with bing offline server
- Featureclick eventListeners randomly not work on chrome 51 HOT 1
- Get OpenLayers from packagist
- Clojure Compiler Link is dead
- Scroll bar does not show in Popup.FramedCloud in mobile devices (OL 2.13.1) HOT 3
- Need to add set style feature to Google Layer HOT 1
- OpenStreetMap newly redirecting tile URLs. Problem on safari HOT 1
- Incorrect Web Mercator transforms with newest versions of proj4js
- Map extent is increased after setting base layer
- How to Convert Circle Polygon Geometry to Line in openlayers 2 HOT 1
- Snapping another layer point with Create Circle Polygon in Openlayers 2
- how to show a arrow feature by some longitude
- Ping (ICMP) send during Layer/Map request
- Image getting stretched in Image layer
- How to Change style of point feature to polygon?
- Open source License obligations of openlayers-2.13.1 HOT 3
- Responsible disclosure policy
- Dev.openlayers.org is gone HOT 10
- Google Map Layers not rendering anymore HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ol2.