Skip to content

Commit

Permalink
#10 fix spatial_extent
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Sep 5, 2019
1 parent e092262 commit 6861acc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
28 changes: 16 additions & 12 deletions csis_helpers.module
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function csis_helpers_node_entity_info_datapackage(\Drupal\Core\Entity\EntityInt
'name' => $entity->get('title')->value
);

$spatialExtent = extractSpatialExtend($entity);
$spatialExtent = extractSpatialExtent($entity);
if ($spatialExtent != null) {
return array_merge($datapackageEntityInfo, $spatialExtent);
}
Expand All @@ -190,7 +190,7 @@ function csis_helpers_node_entity_info_resource(\Drupal\Core\Entity\EntityInterf
'name' => $entity->get('title')->value
);

$spatialExtent = extractSpatialExtend($entity);
$spatialExtent = extractSpatialExtent($entity);
if ($spatialExtent != null) {
return array_merge($resourcEntityInfo, $spatialExtent);
}
Expand Down Expand Up @@ -416,17 +416,21 @@ function csis_helpers_jsonapi_entity_filter_access(\Drupal\Core\Entity\EntityTyp
* @param \Drupal\Core\Entity\EntityInterface $entity
* @return Array
*/
function extractSpatialExtend($entity)
function extractSpatialExtent($entity)
{
$spatial_extends = $entity->get('field_spatial_extent')->referencedEntities(); // referencedEntities() returns an array of entities
if (!empty($spatial_extends) && is_array($spatial_extends) && sizeof($spatial_extends) > 0 && $spatial_extends[0] != null) {
//console_log($spatial_extends[0]->get('field_bounding_box')->value);
$spatialExtent = array(
'minx' => $spatial_extends[0]->get('field_xmin')->value,
'miny' => $spatial_extends[0]->get('field_ymin')->value,
'maxx' => $spatial_extends[0]->get('field_xmax')->value,
'maxy' => $spatial_extends[0]->get('field_ymax')->value,
);
$spatial_extents = $entity->get('field_spatial_extent')->referencedEntities(); // referencedEntities() returns an array of entities
if (!empty($spatial_extents) && is_array($spatial_extents) && sizeof($spatial_extents) > 0
&& $spatial_extents[0] != null && $spatial_extents[0]->get('field_bounding_box') != null) {
//console_log($spatial_extents[0]->get('field_bounding_box')->value);
$spatialExtent = array('spatial_extent' => $spatial_extents[0]->get('field_bounding_box')->value);

// @deprecated See https://github.com/clarity-h2020/map-component/issues/53
/*$spatialExtent = array(
'minx' => $spatial_extents[0]->get('field_xmin')->value,
'miny' => $spatial_extents[0]->get('field_ymin')->value,
'maxx' => $spatial_extents[0]->get('field_xmax')->value,
'maxy' => $spatial_extents[0]->get('field_ymax')->value,
);*/

return $spatialExtent;
} else {
Expand Down
18 changes: 10 additions & 8 deletions js/csis_iframe_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

if(undefined == iFrameMapComponent || null == iFrameMapComponent) {
console.warn('initMapComponent(): no iFrameMapComponent available');
return;
}

// window.location.origin instead of window.location.host: we need the protocol, too!
Expand All @@ -39,19 +40,20 @@
if (undefined !== csisHelpers.resourceInfo && mapType == 'ResourcePreviewMap') {
console.info(`showing ${mapType} for resource ${csisHelpers.resourceInfo.name}`);
resource_uuid = csisHelpers.resourceInfo.uuid;
minx = csisHelpers.resourceInfo.minx;
miny = csisHelpers.resourceInfo.miny;
maxx = csisHelpers.resourceInfo.maxx;
maxy = csisHelpers.resourceInfo.maxy;
// Yeah, 'study_area' is not correct, but we reuse this query param since we don't want to re-implement
// handling of initial bbox just because the data model contains rubbish. :-/
// See https://github.com/clarity-h2020/map-component/issues/53
study_area = csisHelpers.resourceInfo.spatial_extent;
//minx = csisHelpers.resourceInfo.minx;
//miny = csisHelpers.resourceInfo.miny;
//maxx = csisHelpers.resourceInfo.maxx;
//maxy = csisHelpers.resourceInfo.maxy;
write_permissions = csisHelpers.resourceInfo.write_permissions;
}
else if (undefined !== csisHelpers.datapackageInfo && mapType == 'DataPackagePreviewMap' ) {
console.info(`showing ${mapType} for datapackage ${csisHelpers.datapackageInfo.name}`);
datapackage_uuid = csisHelpers.datapackageInfo.uuid;
minx = csisHelpers.datapackageInfo.minx;
miny = csisHelpers.datapackageInfo.miny;
maxx = csisHelpers.datapackageInfo.maxx;
maxy = csisHelpers.datapackageInfo.maxy;
study_area = csisHelpers.datapackageInfo.spatial_extent;
write_permissions = csisHelpers.datapackageInfo.write_permissions;
} else if (undefined !== csisHelpers.studyInfo) { // implicitly use for study preview map
console.info(`showing ${mapType} for study ${csisHelpers.studyInfo.name}`);
Expand Down

0 comments on commit 6861acc

Please sign in to comment.