Archive for the 'AJAX' Category

New version of ‘getlibraries’ multi-library google map

Thursday, July 13th, 2006

Announcing a new version of the getlibraries script! This follows a similar pattern to the last version, and can be seen inaction here on the Herefordshire Libraries website.

On the info windows, you will now see a little blowup map of the library location, and an [edit] link which will take you directly into the silkworm directory and show you a page for that location.  Assuming you have a user login with the directory, you can edit anything that is wrong and it will be reflected in the map within moments.
Installation

  1. Download getlibraries version 2
  2. The text file simply contains the query, and you will need to pop your library’s identifier in there.
  3. The js file will need your Talis API key, and the path to getlibraries-v2-sparql.txt
  4. upload these to your server.
  5. Add a script tag in your html page with the getlibraries-v2.js as the src attribute.
  6. Remember that you need to have a google maps API key and a script tag pointing there as well - see http://www.google.com/apis/maps/.
  7. Add a div to your page with attribute id=”map”.  You will probably want to add a style attribute too with the width and height defined.

Most changes are behind the scenes, i.e. handling of single locations and handling of locations that have no geodata.

I’m indebted to Sam Tunnicliffe of Talis who informed me, after I posted about the last version, that they had just enabled a new JSON ouput option for the SPARQL endpoint, and also added a query_uri parameter so that long queries (like one of mine!) can be passed without bumping up against the maximum length restrictions of GET requests (see the docs..).  He has also troubleshooted a few teething troubles: mostly because of my unfamiliarity with the SPARQL language.

Technorati Tags: , , , , , ,

A Multi-library Google Map - getlibraries

Wednesday, July 5th, 2006

It’s been quiet here at ITO while I get on with little things like a dissertation. As a reward for days spent reading schema documents, I have been having a fiddle with Google maps and the Silkworm directory from Talis.

Here’s wot I got… getlibraries LibMap - sounds better!
A multi-library google map - the map in action on a real page!

Firstly, there’s one javascript file which when called from a web page using an xhtml script tag will form a query with your parameters and send it to the TPA SPARQL endpoint. the result is fired and recieved at the same time using Dynode style cross-domain scripting method (I didn’t use the dynode script, just the essense of the technique). The Parameters that you can set within the .js file are as follows:

  • key = Talis Api Key
  • identifier = identifier of a libraries collection (with more than one library*) from the Silkworm directory.
  • xsl = the URL to the XSL stylesheet explained next.

*At the moment the script will not cope with a single location, but I’m working on that.

Secondly, there’s one XSLT file which is submitted along with a SPARQL request to the Talis Platform Api (TPA) SPARQL endpoint. This reformats the RDF output into a javascript file that encapsulates the data as a JSON object, invokes a new map container and iterates through the JSON object, showing details for all libraries found by the SPARQL query.

Thirdly - and lastly, there is a small amount of code to go IN your web page, whatever your webpage may be. first is a script tag, which points to getlibraries.js. the second is a DIV tag with an id=”map” attribute. You can also set the height and width attributes to define the size of container that Google Maps will use. More instructions are in the .js file.
And that is it!

the getlibraries.js script writes another script tag that calls the data from the TPA. The javascript file can be edited to include your TPA key, the silkworm identifier for your library and the location of your copy of the XSLT file.

  1. Put the code in your page
  2. Edit the js file
  3. Put the js and xsl files on your server
  4. Job done!

I don’t for a moment think it worthy of the Mashuing Up The Library competition, but give it a go and let me know!

A note on browsers - I have tested this in Firefox 1.5.0.4 and in IE 6. It would be interesting to know if there are any problems with other browsers?

Download here… getlibraries.zip

Technorati Tags: , , , , , ,