summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLev Tsypin2013-01-02 18:39:32 (GMT)
committer Lev Tsypin2013-01-02 18:39:32 (GMT)
commitc5b1277b9ba9f1e060ce3dfcfdd4f46a172c146e (patch)
treeb7e783cd0e0234cc906cc9ad0d47800d151d08f5
parent1110c84fa6af7143485d27376578fca3e537ebba (diff)
Change settings into a serialized array rather than individual properties.
-rw-r--r--includes/mapboxjs.admin.inc46
-rw-r--r--includes/mapboxjs.entity.inc13
-rw-r--r--mapboxjs.install66
-rw-r--r--mapboxjs.module24
4 files changed, 43 insertions, 106 deletions
diff --git a/includes/mapboxjs.admin.inc b/includes/mapboxjs.admin.inc
index c0e86d6..42821d7 100644
--- a/includes/mapboxjs.admin.inc
+++ b/includes/mapboxjs.admin.inc
@@ -41,72 +41,80 @@ function mapboxjs_preset_form($form, &$form_state, MapboxjsPreset $preset = NULL
),
'#weight' => -10,
);
+
+ $form['settings'] = array(
+ '#title' => t('Settings'),
+ '#type' => 'container',
+ '#description' => t(''),
+ '#tree' => TRUE
+ );
+
// Enable/disable layer toggle control for optional layers.
- $form['layer_toggle'] = array(
+ $form['settings']['layer_toggle'] = array(
'#type' => 'checkbox',
'#title' => t('Provide layer toggle controls for optional layers'),
'#description' => t('Select this option to present controls to toggle on/off the optional tileset layers provided above.'),
- '#default_value' => isset($preset->layer_toggle) ? $preset->layer_toggle : FALSE,
+ '#default_value' => isset($preset) ? $preset->settings['layer_toggle'] : FALSE,
);
// Provide preset administrator with control over the map container height.
- $form['height'] = array(
+ $form['settings']['height'] = array(
'#type' => 'textfield',
'#title' => t('Mabox map height'),
'#description' => t('Enter the height in pixels for this map.'),
- '#default_value' => isset($preset->height) ? $preset->height : '500',
+ '#default_value' => isset($preset) ? $preset->settings['height'] : '500',
'#size' => '5',
'#field_suffix' => t('px'),
'#element_validate' => array('element_validate_integer_positive'),
);
// Set the lat/lon center points.
- $form['center'] = array(
+ $form['settings']['center'] = array(
'#type' => 'fieldset',
'#title' => t('Center point'),
'#description' => t('Enter the lat/long center point of this map in decimal degrees.'),
'#collapsible' => TRUE,
);
- $form['center']['lat'] = array(
+ $form['settings']['center']['lat'] = array(
'#type' => 'textfield',
'#title' => t('Latitude'),
- '#default_value' => isset($preset->lat) ? $preset->lat : 0,
+ '#default_value' => isset($preset) ? $preset->settings['center']['lat'] : 0,
);
- $form['center']['lon'] = array(
+ $form['settings']['center']['lon'] = array(
'#type' => 'textfield',
'#title' => t('Longitude'),
- '#default_value' => isset($preset->lon) ? $preset->lon : 0,
+ '#default_value' => isset($preset) ? $preset->settings['center']['lon'] : 0,
);
// Set default zoom level.
- $form['zoom'] = array(
+ $form['settings']['zoom'] = array(
'#type' => 'select',
'#title' => t('Zoom level'),
'#description' => t('Select the default zoom level for this map.'),
'#options' => drupal_map_assoc(array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)),
- '#default_value' => isset($preset->zoom) ? $preset->zoom : 8,
+ '#default_value' => isset($preset) ? $preset->settings['zoom'] : 8,
);
// Enable/disable zoom controls.
- $form['zoomer'] = array(
+ $form['settings']['zoomer'] = array(
'#type' => 'checkbox',
'#title' => t('Provide zoom controls'),
- '#default_value' => isset($preset->zoomer) ? $preset->zoomer : TRUE,
+ '#default_value' => isset($preset) ? $preset->settings['zoomer'] : TRUE,
);
// Enable/disable fullscreen control.
- $form['fullscreen'] = array(
+ $form['settings']['fullscreen'] = array(
'#type' => 'checkbox',
'#title' => t('Provide fullscreen map option'),
- '#default_value' => isset($preset->fullscreen) ? $preset->fullscreen : FALSE,
+ '#default_value' => isset($preset) ? $preset->settings['fullscreen'] : FALSE,
);
// Enable/disable map legend.
- $form['legend'] = array(
+ $form['settings']['legend'] = array(
'#type' => 'checkbox',
'#title' => t('Provide a map legend, if included with MapBox tileset(s).'),
- '#default_value' => isset($preset->legend) ? $preset->legend : FALSE,
+ '#default_value' => isset($preset) ? $preset->settings['legend'] : FALSE,
);
// Enable/disable tileset compositing.
- $form['composite'] = array(
+ $form['settings']['composite'] = array(
'#type' => 'checkbox',
'#title' => t('Enable tileset compositing'),
'#description' => t('By default, multiple tilesets will be returned by the MapBox API as a single, composited tileset. This improves performance and reduces the number of tile requests to the MapBox API. In certain cases, however, it is helpful to disable compositing for smoother transitions when toggling on/off one or more tilesets.'),
- '#default_value' => isset($preset->composite) ? $preset->composite : TRUE,
+ '#default_value' => isset($preset) ? $preset->settings['composite'] : TRUE,
);
// Attach our locked link fields.
diff --git a/includes/mapboxjs.entity.inc b/includes/mapboxjs.entity.inc
index 9f880d4..f4f5ec2 100644
--- a/includes/mapboxjs.entity.inc
+++ b/includes/mapboxjs.entity.inc
@@ -9,16 +9,7 @@ class MapboxjsPreset extends Entity {
$mapboxjs_preset_id,
$name,
$label,
- $height,
- $lat,
- $lon,
- $zoom,
- $zoomer,
- $fullscreen,
- $legend,
- $layer_toggle,
- $composite,
- $type = 'mapboxjs_preset', // only one bundle type for now
+ $settings,
$created,
$updated;
@@ -35,7 +26,7 @@ class MapboxjsPreset extends Entity {
}
protected function defaultUri() {
- return array('path' => 'mapboxjs/' . $this->identifier());
+ return array('path' => 'admin/structure/mapboxjs/presets/manage/' . $this->identifier());
}
}
diff --git a/mapboxjs.install b/mapboxjs.install
index d17485d..caf297a 100644
--- a/mapboxjs.install
+++ b/mapboxjs.install
@@ -26,65 +26,13 @@ function mapboxjs_schema() {
'length' => 128,
'not null' => TRUE,
),
- 'height' => array(
- 'description' => 'The default height of a map rendered by MapBox.js.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 500,
- ),
- 'lat' => array(
- 'description' => 'Latitude value of MapBox.js map center point.',
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'lon' => array(
- 'description' => 'Longitude value of MapBox.js map center point.',
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'zoom' => array(
- 'description' => 'The default zoom level of a map rendered by MapBox.js.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 8,
- ),
- 'zoomer' => array(
- 'description' => 'Boolean determining if zoom controls should be displayed.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- ),
- 'layer_toggle' => array(
- 'description' => 'Boolean determining if toggle controls for optional tilesets should be displayed.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- ),
- 'fullscreen' => array(
- 'description' => 'Boolean determining if the fullscreen control should be displayed.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- ),
- 'legend' => array(
- 'description' => 'Boolean determining if the map legend should be displayed.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- ),
- 'composite' => array(
- 'description' => 'Boolean determining if tile compositing should be used.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- ),
+ 'settings' => array(
+ 'description' => 'MapBox JS map settings as a serialized array.',
+ 'type' => 'text',
+ 'not null' => FALSE,
+ 'size' => 'big',
+ 'serialize' => TRUE,
+ ),
'created' => array(
'description' => 'The Unix timestamp when the mapboxjs_preset was created.',
'type' => 'int',
diff --git a/mapboxjs.module b/mapboxjs.module
index 633e3ed..28e077a 100644
--- a/mapboxjs.module
+++ b/mapboxjs.module
@@ -154,11 +154,11 @@ function mapboxjs_get_presets($name = NULL) {
/**
* Render a preset as a map.
*
- * @param array $preset
+ * @param MapboxjsPreset $preset
*
* @return MapBox.js map as a renderable array
*/
-function mapboxjs_render_preset($preset) {
+function mapboxjs_render_preset(MapboxjsPreset $preset) {
$map_id = 'map-' . $preset->name;
// @TODO - Provide unique ID for each MapBox map so that we can act on multiple maps on a single page.
@@ -180,21 +180,11 @@ function mapboxjs_render_preset($preset) {
}
}
- $settings = array(
- 'mapID' => $map_id,
- 'configuration' => array(
- 'lat' => $preset->lat,
- 'lon' => $preset->lon,
- 'zoom' => $preset->zoom,
- 'zoomer' => $preset->zoomer,
- 'fullscreen' => $preset->fullscreen,
- 'legend' => $preset->legend,
- 'layer_toggle' => $preset->layer_toggle,
- 'composite' => $preset->composite,
- 'base_tilesets' => $base_tilesets,
- 'optional_tilesets' => $base_tilesets,
- )
- );
+ $settings = array('mapID' => $map_id);
+ foreach ($preset->settings as $key => $value) {
+ $settings['configuration'][$key] = $value;
+ }
+
// Pass our settings to Drupal's global js variable.
drupal_add_js(array('mapboxjs' => $settings), 'setting');