dbpedia Example

http://openlayers.org/dev/examples/click.html

by Chombito

HTML

<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css">
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css">
<script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ"></script>
<script src="http://openlayers.org/dev/OpenLayers.js"></script>
<h1 id="title">click for Infos</h1>
<div id="map"></div>
<div id="docs"><p>Bla</p> </div>

CSS

.olControlAttribution {
                bottom: 5px;
            }
            #map {
                width: 500px;
                height: 300px;
            }

JavaScript

(function($) {

    var apiKey = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
    var map;
    
    var query = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\
    PREFIX dcterms: <http://purl.org/dc/terms/>\
    PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>\
    PREFIX dbprop: <http://dbpedia.org/property/>\
    PREFIX dbcat: <http://dbpedia.org/resource/Category:>\
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#> \
    SELECT DISTINCT ?poet ?poet_name ?surname ?poet_wiki_link ?abstract \
    WHERE \
    {  ?poet dcterms:subject dbcat:American_poets ;\
        foaf:name ?poet_name ;\
        foaf:surname ?surname ;\
        dbpedia-owl:abstract ?abstract ;\
        foaf:isPrimaryTopicOf ?poet_wiki_link .\
      FILTER ( lang(?abstract) = \"en\" )\
    } ORDER BY ?surname \
      LIMIT 20";

    var parseResults = function(data){
        alert(data);
    };
    
    function getGeoData(lat, lon) { 
      var url = "http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + escape(query) + "&format=json";  
      $.getJSON(url, parseResults);
    }
    
    OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
        defaultHandlerOptions: {'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false},
        initialize: function(options) {
            this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);
            OpenLayers.Control.prototype.initialize.apply(
            this, arguments);
            this.handler = new OpenLayers.Handler.Click(
            this, { 'click': this.trigger }, this.handlerOptions);
        },
        trigger: function(e) {
            var lonlat = map.getLonLatFromViewPortPx(e.xy);
            getGeoData(lonlat.lat,lonlat.lon);
        }
    });
    
    function init() {   
        var hybrid = new OpenLayers.Layer.Bing({key: apiKey, type:...