Also posted at http://drupal.stackexchange.com/questions/71833/how-to-group-by-referenc...
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>",
}
}
]
}
Comments
Comment #0.0
dericke commentedFixed formatting for readability.
Comment #1
jeffschuler#1990344: Group By option does nothing
Comment #1.0
jeffschulerAdded link to cross-post at drupal.stackexchange
Comment #2
andileco commentedI'm using this module to supply the data for a (Openlayers 3.x) map where clicking on a country opens a popup with a listing of multiple nodes tagged with that country term. I have done this in Openlayers 2.x and have basically done the same thing with this module, except I can only get one node to show up per country. If I were able to group my views_geojson feed by country (in the Format settings), I think my problem would go away and I would be able to show all the nodes tagged with that country within the popup.
I don't like the idea of a BBox for this, as each node shares the same geographic data (the boundary data for the country). My ideal output would look like the code above, just I'm using polygons instead of points.
Please help! Happy to clarify if anything I've said is unclear. But I do think this needs to be addressed if this module will be the go-to module for people using OpenLayers 3.x together with Views.
Comment #3
dericke commentedandile2012, I wound up making a patch on Views Datasource instead of Views GeoJSON, since I didn't need valid GeoJSON for my purposes. Check it out at https://www.drupal.org/node/1373280 and see if it will work for your purposes or can be adapted to Views GeoJSON.
Comment #4
andileco commentedThanks for the link, @dericke, though I do think this is actually a major issue for this module (I'm changing the status for that reason). There are tons of use cases where people would want to group at the state/country/district level. I actually had to do major work on my site to revert to the previous version of the OpenLayers module because of this issue.
I don't think this should be too hard, as grouping is a normal part of Feed displays, but when I edited the places where I would expect that to be handled (there's a line where you can change "grouping" to "true", for example), nothing changed.
Would love to see this move forward, although I am enjoying the familiarity of OpenLayers v2 for now.
Comment #5
abelassI am working on an leaflet map where projects are listed, one project can have different locations.
I am using views-geojson for the geojson data and while there are three points created, all have the same geofield data. Would be great if this could be achieved with this module