1

Also posted at http://drupal.org/node/1984446

My site has a Building content type, each node of which describes a building on my university campus. The content type includes a Geofield, with a point centered on each building. I also have a Construction content type, each node of which describes a construction or renovation item that might occur in a building or buildings. This includes a Node reference field, which can reference unlimited Building nodes.

I want to output a JSON document describing all construction nodes occurring on campus, grouped by building, and with the coordinates of the building in each group. I originally tried Views Datasource to accomplish this, but it doesn't seem to support grouping by field. Views GeoJSON appears to support grouping on fields, but the nodes aren't actually grouping.

My view currently lists all published Construction nodes, and includes the title and body fields of each node. I also have a relationship for the referenced Building nodes, and I'm including the Geofield from the referenced buildings through that relationship.

My output is like:

{
      "type" : "Feature",
      "geometry" : {
        "type" : "Point",
        "coordinates" : [
          -122.48572389942,
          48.73781161338
        ]
      },
      "properties" : {
        "name" : "<a href=\"/content/wilson-becoming-skyscraper\">Wilson Becoming Skyscraper</a>",
        "description" : "<p>Wilson will be the tallest EVAR!!!</p>\n",
        "field_affected_buildings" : 1703, // References same building node as the node below, but the non-rendered output is 1703 here and 1720 below
        "field_affected_buildings_rendered" : "Wilson Library"
      }
    },
    {
      "type" : "Feature",
      "geometry" : {
        "type" : "Point",
        "coordinates" : [
          -122.48572389942,
          48.73781161338
        ]
      },
      "properties" : {
        "name" : "<a href=\"/content/energy-services-performance-contract-esco-wilson-library\">Energy Services Performance Contract (ESCO) - Wilson Library</a>",
        "description" : "<ul><li>This project was initiated In order to advance Western’s sustainability goals and reduce our carbon footprint. The project will implement 38 separate facility improvement measures in various academic and auxiliary buildings identified by an energy audit of Western's campus.</li></ul>",
        "field_affected_buildings" : 1720, // This node references the exact same building as the first node, but this non-rendered output is 1720 instead of 1703. What's up with that? If I render as Node ID, I get the same result in both nodes.
        "field_affected_buildings_rendered" : "Wilson Library"
      }
    }
  ]
}

Note that the two points are identical, because each alert references the same building. What I want is more like:

{
      "type" : "Feature",
      "geometry" : {
        "type" : "Point",
        "coordinates" : [
          -122.48572389942,
          48.73781161338
        ]
      },
      "properties" : {
        "name" : "Wilson Library",
        "description" : 
            "<h3><a href=\"/content/wilson-becoming-skyscraper\">Wilson Becoming Skyscraper</a></h3>\n
            <p>Wilson will be the tallest EVAR!!!</p>\n
            <h3><a href=\"/content/energy-services-performance-contract-esco-wilson-library\">Energy Services Performance Contract (ESCO) - Wilson Library</a></h3>\n
            <ul><li>This project was initiated In order to advance Western’s sustainability goals and reduce our carbon footprint. The project will implement 38 separate facility improvement measures in various academic and auxiliary buildings identified by an energy audit of Western's campus.</li></ul>",
      }
    }
  ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.