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

Refactor javascript, make geoJson include a pid #62

Open
wants to merge 5 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sudo: required
dist: trusty
language: php
php:
- 5.4
Expand All @@ -7,6 +8,9 @@ php:
- 7.0
- 7.1

services:
- mysql

branches:
only:
- /^7.x/
Expand All @@ -18,6 +22,9 @@ matrix:
include:
- php: 5.3.3
dist: precise
allow_failures:
- php: 5.3.3
dist: precise

before_install:
- cd $HOME
Expand All @@ -34,7 +41,5 @@ before_script:
- mysql -e 'SET @@GLOBAL.wait_timeout=1200'

script:
- $ISLANDORA_DIR/tests/scripts/line_endings.sh sites/all/modules/islandora_simple_map
- drush coder-review --reviews=production,security,style,i18n,potx,sniffer islandora_simple_map
- phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora_simple_map
- php scripts/run-tests.sh --php `phpenv which php` --url http://localhost:8081 --verbose "Islandora Simple Map"
- $ISLANDORA_DIR/tests/scripts/travis_scripts.sh
- $ISLANDORA_DIR/tests/scripts/run_tests.sh "Islandora Simple Map"
7 changes: 3 additions & 4 deletions includes/admin_form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ function islandora_simple_map_admin_settings_form($form, &$form_state) {
foreach ($os_providers as $key => $data) {
$os_options[$key] = $data['title'];
}
// Now store all the API keys under one variable.

// Simple get from array or return blank string.
$get_or_blank = function($key, $array) {
$get_or_blank = function ($key, $array) {
return array_key_exists($key, $array) ?
$array[$key] : '';
};
Expand Down Expand Up @@ -486,8 +485,8 @@ function _islandora_simple_map_islandora_collection_delete_confirm(&$form_state)
if ($to_disable) {
array_walk($to_disable,
function (&$item) {
$pid = $item;
$object = islandora_object_load($pid);
$pid = $item;
$object = islandora_object_load($pid);
if ($object) {
$item = $object->label;
}
Expand Down
60 changes: 38 additions & 22 deletions includes/utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ function islandora_simple_map_get_coordinates(AbstractObject $object) {
function islandora_simple_map_parse_coordinates(array $coordinates) {
$hooks = (array) module_invoke_all(ISLANDORA_SIMPLE_MAP_PARSE_HOOK);
uasort($hooks, function ($a, $b) {
if (!isset($a['weight'])) {
$a['weight'] = 100;
}
if (!isset($b['weight'])) {
$b['weight'] = 100;
}
if (!isset($a['weight'])) {
$a['weight'] = 100;
}
if (!isset($b['weight'])) {
$b['weight'] = 100;
}
return (abs($a['weight']) <= abs($b['weight']) ? -1 : 1);
});

Expand Down Expand Up @@ -221,10 +221,8 @@ function _islandora_simple_map_get_coordinates_solr(AbstractObject $object) {
*
* @param \AbstractObject $object
* The Islandora object.
*
* @param string $datastream
* The datastream - e.g. 'MODS' or 'DDI'.
*
* @param string $xpaths
* Text containing xpath selectors, one per line.
*
Expand Down Expand Up @@ -264,10 +262,9 @@ function islandora_simple_map_get_datastream_results(AbstractObject $object, $da
*
* @param \AbstractObject $object
* The Islandora object.
*
* @param string $xpaths
* Text containing xpath selectors, one per line.

*
* @return array
* The unaltered node values.
*/
Expand Down Expand Up @@ -305,7 +302,7 @@ function islandora_simple_map_is_valid_coordinates($coordinates) {
* @param string $keywords
* Keywords to search by.
*
* @return array|NULL
* @return array|null
* Coordinates if found, else NULL.
*/
function islandora_simple_map_search_google_places($keywords) {
Expand Down Expand Up @@ -537,7 +534,7 @@ function _islandora_simple_map_get_collection_points_solr(AbstractObject $object
);
}
}
$points = array_filter($points, function($o) {
$points = array_filter($points, function ($o) {
return count($o['coordinates'] > 0);
});
return $points;
Expand Down Expand Up @@ -581,19 +578,35 @@ function _islandora_simple_map_generate_js_code(array $settings, $map_div_id) {
'features' => array(),
);

// Flatten possible array of marker coordinates.
$coordinates = isset($temp_settings['map_markers']['coordinates'])
? $temp_settings['map_markers']['coordinates']
: array_unique(call_user_func_array('array_merge', array_column($temp_settings['map_markers'], 'coordinates')));

// Add features from coordinate data.
$geojson_features = _islandora_simple_map_coords_to_geojson_features($coordinates);
$geojson_features = array();
if (isset($temp_settings['map_markers']['pid'])) {
$geojson_features = _islandora_simple_map_coords_to_geojson_features(
$temp_settings['map_markers']['coordinates'],
$temp_settings['map_markers']['pid']
);
}
else {
foreach ($temp_settings['map_markers'] as $coords) {
$geojson_features = array_merge($geojson_features,
_islandora_simple_map_coords_to_geojson_features(
$coords['coordinates'],
$coords['pid']
)
);
}
}

$temp_settings['map_geojson']['features'] = array_merge($temp_settings['map_geojson']['features'], $geojson_features);

// Remove coordinate data.
$temp_settings['map_markers'] = array('coordinates' => array());
}

$code['js'][] = array(
'type' => 'file',
'data' => "{$module_path}/js/islandora_simple_map.js",
);
// Google maps.
if ($map_type == ISLANDORA_SIMPLE_MAP_GOOGLE_MAPS) {
$code['js'][] = array(
Expand Down Expand Up @@ -648,7 +661,7 @@ function _islandora_simple_map_generate_js_code(array $settings, $map_div_id) {
* Remove search alters that stop us from getting any data from Solr.
*
* @param array $params
* The islandoraSolrQueryProcessor params
* The islandoraSolrQueryProcessor params.
*/
function _islandora_simple_map_remove_search_restrictions(array &$params) {
if (module_exists('islandora_compound_object') &&
Expand Down Expand Up @@ -810,7 +823,7 @@ function islandora_simple_map_openstreet_map_providers($provider_id = NULL, $fin
* @param AbstractObject $object
* The object for which to gather GeoJSON features.
*
* @return array|NULL
* @return array|null
* If any features were returned, an associative array wrapping them up in a
* "FeatureCollection"; otherwise, NULL.
*/
Expand All @@ -835,10 +848,13 @@ function islandora_simple_map_get_geojson(AbstractObject $object) {
* @return array
* Array of GeoJSON features.
*/
function _islandora_simple_map_coords_to_geojson_features($coordinates) {
return array_map(function ($coord) {
function _islandora_simple_map_coords_to_geojson_features(array $coordinates, $pid) {
return array_map(function ($coord) use ($pid) {
return array(
'type' => 'Feature',
'properties' => array(
'pid' => $pid,
),
'geometry' => array(
'type' => 'Point',
'coordinates' => array_reverse(array_map('doubleval', array_map('trim', explode(',', $coord)))),
Expand Down
10 changes: 4 additions & 6 deletions islandora_simple_map.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ function hook_islandora_simple_map_get_coordinates(AbstractObject $object) {
* Register a function to parse a type of coordinate.
*
* @return array
* Associative array with the format below.
* array(
* 'function_name' => 'name of function to call',
* 'file' => 'path to file to include for accessing above function.',
* 'weight' => 'positive integer for setting an order',
* );
* Associative array with the below keys.
* - function_name => name of function to call
* - file => path to file to include for accessing above function.
* - weight => positive integer for setting an order
*
* The callable 'function_name' takes an array of coordinates and returns an
* associative array where the key is the original coordinate and the value is
Expand Down
9 changes: 3 additions & 6 deletions islandora_simple_map.module
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ function islandora_simple_map_islandora_view_object_alter(&$object, &$rendered)
$collapsed = variable_get('islandora_simple_map_collapsed', 'collapsed');
$markup = theme('islandora_simple_map', array(
// We use the first set of coords if our XPaths found more than one.
'coords' => !empty($found_coords['coordinates'])
? urlencode($found_coords['coordinates'][0])
: NULL,
'coords' => (!empty($found_coords['coordinates']) ?
urlencode($found_coords['coordinates'][0])
: NULL),
'iframe_width' => $width,
'iframe_height' => $height,
'zoom' => $zoom,
Expand Down Expand Up @@ -355,9 +355,6 @@ function islandora_simple_map_collection_map_view(AbstractObject $object) {
*
* @param \AbstractObject $object
* The object being asked about.
*
* @return string
* Json encoded information.
*/
function _islandora_simple_map_marker_info(AbstractObject $object) {
$pid = $object->id;
Expand Down
Loading