User:Skinkie/XAPISQL

From OpenStreetMap Wiki
Jump to navigation Jump to search
 OpenLayers.Format.DBSlayerJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
  initialize: function(options) {
   OpenLayers.Format.JSON.prototype.initialize.apply(this, [options]);
  },
  read: function(json, type, filter) {
   var results = [];
   obj = OpenLayers.Format.JSON.prototype.read.apply(this,  [json, filter]);
   rows = obj["RESULT"]["ROWS"];
   for(var i=0, len=rows.length; i<len; ++i) {
    var point = new OpenLayers.Geometry.Point(rows[i][0], rows[i][1]);
    var wgs84 = new OpenLayers.Projection("EPSG:4326");
    var sm = new OpenLayers.Projection("EPSG:900913");
    point.transform(wgs84, sm);
    results.push(new OpenLayers.Feature.Vector(point));
   }
   return results;
  },
  CLASS_NAME: "OpenLayers.Format.DBSlayerJSON"
 });
 var styleATM = new OpenLayers.StyleMap({
  "default": new OpenLayers.Style(null, {
   rules: [
    new OpenLayers.Rule({
     symbolizer: {
      "Point": {
       pointRadius: 6,
	externalGraphic: '/icons/atm.png',
	fillColor: "white",
	fillOpacity: 1.0
       }
      }
     })
   ]
  })
 });
 var layerATM = new OpenLayers.Layer.Vector("ATM", {
  strategies: [new OpenLayers.Strategy.Fixed()],
  protocol: new OpenLayers.Protocol.HTTP({
   url: "/xapi/json/SELECT long, lat FROM nodes_legacy, node_tags WHERE id = node AND ((k = 'amenity' AND v = 'atm') OR (k = 'atm')) LIMIT 100000;",
   format: new OpenLayers.Format.DBSlayerJSON()
  }),
  styleMap: styleATM
 });

more info: