Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for service-based geospatial filtering + minor changes #201

Merged
merged 4 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/OpenGrid API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<br>
<h1 align="center">OpenGrid REST Service <br> Application Programming Interface (API)</h1>
<h4 align="center">Version 1.0</h4>
<h4 align="center">Version 1.1.0</h4>

<!--
## Table of Contents
Expand Down Expand Up @@ -216,11 +216,8 @@ Create a new user. Returns object for newly created user, if successful.

## 1.1.4 /users/{user_id}
**Methods**
<<<<<<< HEAD

<p><b>GET</b></p>
=======
<p><b>GET</b>
>>>>>>> df7c549d50d1400ec04f15d3c747fc5f50c7951c
<br>
Return a single user object given the user’s internal id.
</p>
Expand Down
13 changes: 5 additions & 8 deletions src/js/custom/data/ChicagoCityShapeMap.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/js/data/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ ogrid.Search._getParams = function(filter) {
return 'q=' + encodeURI(JSON.stringify(filter));
};


ogrid.Search._getOpts = function(geoFilter) {
if (geoFilter) {
var f = {"geoFilter": geoFilter};
return '&opts=' + encodeURI(JSON.stringify(f));
} else
return '';
};

ogrid.Search._preProcess = function(data, renditionOptions) {
if (renditionOptions)
//apply rendition options to returning json
Expand Down Expand Up @@ -56,13 +65,14 @@ ogrid.Search._onAjaxError = function (opName, err, options, passThroughData, jqX
/* renditionOptions override default rendition options on the response json
*/
ogrid.Search.exec = function(options, passThroughData) {
//options {dataSetId, filter, renditionOptions, success, error}
//options {dataSetId, filter, geoFilter, renditionOptions, success, error}
//passThroughData is additional info from the caller that is passed to success and error callbacks
var me = this;
var q = this._getParams(options.filter);
var opts = this._getOpts(options.geoFilter);

var url = ogrid.Config.service.endpoint + '/datasets/' + options.dataSetId + '/query?' + q +
'&n=' + (!ogrid.isNull(options.maxResults) ? options.maxResults : ogrid.Config.service.maxresults);
'&n=' + (!ogrid.isNull(options.maxResults) ? options.maxResults : ogrid.Config.service.maxresults) + opts;
if (!ogrid.isNull(options.sort)) {
url +='&s=' + encodeURI(options.sort);
}
Expand Down
15 changes: 12 additions & 3 deletions src/js/ux/AdvancedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@ ogrid.AdvancedSearch = ogrid.Class.extend({
//not blank condition and in error state
throw ogrid.error('Search Error', 'Search criteria is invalid.');
}

//if geoSpatial filtering is supported by service, send geoSpatial filters
if ( ogrid.App.serviceCapabilities().geoSpatialFiltering && me._geoFilter.getSettings().boundary) {
search.geoFilter = me._geoFilter.getGeoFilter();
}

//immediate execution
ogrid.Search.exec(search, {origin: 'advancedSearch', search: search});
});
Expand Down Expand Up @@ -675,9 +681,12 @@ ogrid.AdvancedSearch = ogrid.Class.extend({

_onSubmitSuccess: function(data, passThroughData) {
try {
//apply additional geo-spatial filter, if any is specified
if (this._geoFilter.getSettings().boundary)
data = this._geoFilter.filterData(data);
//if geoSpatial filtering is not supported by service, implement filtering locally
if ( !ogrid.App.serviceCapabilities().geoSpatialFiltering ) {
//apply additional geo-spatial filter, if any is specified
if (this._geoFilter.getSettings().boundary)
data = this._geoFilter.filterData(data);
}

var rsId = ogrid.guid();

Expand Down
25 changes: 24 additions & 1 deletion src/js/ux/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ogrid.Main = ogrid.Class.extend({
_session: null,
_timedOut: false,
_mobileMode: false,
_serviceCaps: {},

//make this common now, so we don't have to retrieve multiple times
_datasets: null,
Expand Down Expand Up @@ -90,7 +91,7 @@ ogrid.Main = ogrid.Class.extend({
//retrieve available datasets first ahead of initializing other dataset-dependent UI elements
// and pass datasets to save retrieval time
ogrid.ajax(this, function(data) {
me._datasets = data;
me._datasets = data.sort(me._sortDs);

//init commandbar
me._cb = new ogrid.CommandBar(me._options.commandbar, {datasets: me._datasets});
Expand Down Expand Up @@ -120,9 +121,27 @@ ogrid.Main = ogrid.Class.extend({

//broadcast that we're finished logged in, passing user profile
ogrid.Event.raise(ogrid.Event.types.LOGGED_IN, me._session.getCurrentUser());

//retrieve service capabilities
ogrid.ajax(me, function(data) {
me._serviceCaps = data;
}, {url: '/capabilities'});

}, {url: '/datasets'});
},


//performs an alphasort on the dataset based on the display name
_sortDs: function(a, b) {
if (!a || !b)
return 0;

if (a.displayName > b.displayName) return 1;
if (a.displayName < b.displayName) return -1;

return 0;
},

_initMapRelatedUx: function(data) {
if (data) {
if (ogrid.Config.map.overlayLayers && Array.isArray(ogrid.Config.map.overlayLayers)) {
Expand Down Expand Up @@ -297,6 +316,10 @@ ogrid.Main = ogrid.Class.extend({
return this._datasets;
},

serviceCapabilities: function() {
return this._serviceCaps;
},

//common global error handler
handleError: function (opName, err, rawErrorData) {
if (err && !$.isEmptyObject(err)) {
Expand Down
45 changes: 45 additions & 0 deletions src/js/ux/geofilter/BaseGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,56 @@ ogrid.BaseGeoFilter = ogrid.Class.extend({
},

//private methods
_getEmptyMultiPolygon: function() {
return {
"type":"FeatureCollection",
"features":[{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates":[
]
}
}]
};
},

_getEmptyPolygon: function() {
return {
"type":"FeatureCollection",
"features":[{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates":[
]
}
}]
};
},

//returns array of coordinates from latLngBounds
_getCoordinatesFromLatLngBounds: function(latLngBounds) {
return [
[
[latLngBounds.getWest(), latLngBounds.getNorth()],
[latLngBounds.getEast(), latLngBounds.getNorth()],
[latLngBounds.getEast(), latLngBounds.getSouth()],
[latLngBounds.getWest(), latLngBounds.getSouth()],
[latLngBounds.getWest(), latLngBounds.getNorth()]
]
];
},

//public methods
filter: function(data) {

},

getGeometry: function() {

}

});
Expand Down
15 changes: 15 additions & 0 deletions src/js/ux/geofilter/DrawnGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ ogrid.DrawnGeoFilter = ogrid.BaseGeoFilter.extend({
var o = $.extend(true, {}, data);
o.features = filtered;
return o;
},

//returns multipolygon for use with service-side geo-spatial filtering
getGeometry: function() {
if (!this._options.shapeMap) {
throw ogrid.error('Advanced Search (ogrid.DrawnGeoFilter)','Shape object is not initialized');
}
//shapeMap is of class L.featureGroup
var me = this;
var geoJSON = me._options.shapeMap.toGeoJSON();
var multiGeo = me._getEmptyMultiPolygon();
$.each(geoJSON.features, function( i, v ) {
multiGeo.features[0].geometry.coordinates.push(v.geometry.coordinates);
});
return multiGeo.features[0].geometry;
}
});

Expand Down
15 changes: 15 additions & 0 deletions src/js/ux/geofilter/GeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@ ogrid.GeoFilter = ogrid.Class.extend({
},


//returns geometry objects for sending to service
getGeoFilter: function() {
var settings = this.getSettings();
var f = ogrid.geoFilterFactory({
map: this._options.map,
shapeMap: this._getShapeMap(settings)
}).getFilter(settings);
console.log(f.getGeometry());
return f.getGeometry();
},


setBoundaryType: function(boundaryType) {
$('.adv-search-geofilter input[name="boundaryOption"][value="' + boundaryType + '"]').prop('checked', true);
},
Expand All @@ -486,6 +498,9 @@ ogrid.GeoFilter = ogrid.Class.extend({
throw ogrid.error('Advanced Search (ogrid.GeoFilter)', 'Unknown boundary type \'' + settings.boundary + '\'');
},




//can be used to get an object that represents the state of geoFilters that can be saved
getSettings: function() {
var o = {};
Expand Down
18 changes: 18 additions & 0 deletions src/js/ux/geofilter/GeoLocationGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ ogrid.GeoLocationGeoFilter = ogrid.BaseGeoFilter.extend({
var o = $.extend(true, {}, data);
o.features = filtered;
return o;
},

getGeometry: function() {
if (!this._settings.maxRadius || !this._settings.maxRadiusUnit) {
throw ogrid.error('Advanced Search (ogrid.GeoLocationGeoFilter)', 'Radius data is not initialized');
}

if (!this._options.shapeMap) {
throw ogrid.error('Advanced Search (ogrid.GeoLocationGeoFilter)', 'No Geo-location coordinates were detected. Please allow geo-location detection in your browser.');
}

//shapeMap for Near Me will contain the LatLng of the last location found
var c = L.circle(this._options.shapeMap, this._getRadius());

var coordinates = this._getCoordinatesFromLatLngBounds(c.getBounds());
var polyGeo = this._getEmptyPolygon();
polyGeo.features[0].geometry.coordinates = coordinates;
return polyGeo.features[0].geometry;
}
});

Expand Down
11 changes: 11 additions & 0 deletions src/js/ux/geofilter/MapExtentGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ ogrid.MapExtentGeoFilter = ogrid.BaseGeoFilter.extend({
var o = $.extend(true, {}, data);
o.features = filtered;
return o;
},

getGeometry: function() {
//filter is dynamic and extent is calculated in real-time
if (!this._options.map) {
throw ogrid.error('Advanced Search (ogrid.MapExtentGeoFilter)','Map object is not initialized');
}
var coordinates = this._getCoordinatesFromLatLngBounds(this._options.map.getBounds());
var multiGeo = this._getEmptyMultiPolygon();
multiGeo.features[0].geometry.coordinates.push(coordinates);
return multiGeo.features[0].geometry;
}
});

Expand Down
15 changes: 15 additions & 0 deletions src/js/ux/geofilter/PointGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ ogrid.PointGeoFilter = ogrid.BaseGeoFilter.extend({
var o = $.extend(true, {}, data);
o.features = filtered;
return o;
},

getGeometry: function() {
if (!this._options.shapeMap) {
throw ogrid.error('Advanced Search (ogrid.PointGeoFilter)','Shape object is not initialized');
}
var me = this;
var multiGeo = me._getEmptyMultiPolygon();
$.each(me._options.shapeMap.getLayers(), function(i, v) {
var c = L.circle(v.getLatLng(), me._getRadius());

var coordinates = me._getCoordinatesFromLatLngBounds(c.getBounds());
multiGeo.features[0].geometry.coordinates.push(coordinates);
});
return multiGeo.features[0].geometry;
}
});

Expand Down
17 changes: 17 additions & 0 deletions src/js/ux/geofilter/ShapeGeoFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ ogrid.ShapeGeoFilter = ogrid.BaseGeoFilter.extend({
var o = $.extend(true, {}, data);
o.features = filtered;
return o;
},

getGeometry: function() {
if (!this._options.shapeMap) {
throw ogrid.error('Advanced Search (ogrid.ShapeGeoFilter)','Shape object is not initialized');
}
if (this._options.shapeMap[this._settings.value]) {
var me = this;
var geoJSON = me._options.shapeMap[this._settings.value];
var multiGeo = me._getEmptyMultiPolygon();
$.each(geoJSON.features, function( i, v ) {
multiGeo.features[0].geometry.coordinates.push(v.geometry.coordinates);
});
return multiGeo.features[0].geometry;
} else
throw ogrid.error('Advanced Search (ogrid.ShapeGeoFilter)','Shape object is not initialized');

}

});
Expand Down