diff --git a/modules/openlayers_examples/includes/openlayers_examples.default_openlayers_components.inc b/modules/openlayers_examples/includes/openlayers_examples.default_openlayers_components.inc index f5dd071..a7d505a 100644 --- a/modules/openlayers_examples/includes/openlayers_examples.default_openlayers_components.inc +++ b/modules/openlayers_examples/includes/openlayers_examples.default_openlayers_components.inc @@ -66,13 +66,9 @@ function openlayers_examples_default_openlayers_components() { $ol_component->factory_service = 'openlayers.Component:ZoomToSource'; $ol_component->options = array( 'source' => array('views_geojson_openlayers_examples_geojson_feed_2'), - 'animations' => array( - 'pan' => '500', - 'zoom' => '500', - ), + 'duration' => '500', 'zoom' => 'auto', 'max_zoom' => 15, - 'enableAnimations' => 1, 'process_once' => 1, ); $export['openlayers_examples_component_zoom_to_source'] = $ol_component; @@ -88,12 +84,8 @@ function openlayers_examples_default_openlayers_components() { 'source' => array( 'openlayers_examples_source_geojson_london_tube_lines', ), - 'animations' => array( - 'pan' => 500, - 'zoom' => 500, - ), + 'duration' => '500', 'zoom' => 'auto', - 'enableAnimations' => 1, 'max_zoom' => 15, 'process_once' => 1, ); @@ -535,12 +527,8 @@ osm.on(\'postcompose\', function(event) { 'source' => array( 'openlayers_examples_source_geojson_london_tube_lines' => 'openlayers_examples_source_geojson_london_tube_lines', ), - 'animations' => array( - 'pan' => 500, - 'zoom' => 500, - ), + 'duration' => '500', 'zoom' => 'auto', - 'enableAnimations' => 1, 'max_zoom' => 15, 'process_once' => 1, ); diff --git a/modules/openlayers_geofield/includes/openlayers_geofield.default_openlayers_components.inc b/modules/openlayers_geofield/includes/openlayers_geofield.default_openlayers_components.inc index 0ec7b43..987295b 100644 --- a/modules/openlayers_geofield/includes/openlayers_geofield.default_openlayers_components.inc +++ b/modules/openlayers_geofield/includes/openlayers_geofield.default_openlayers_components.inc @@ -40,12 +40,8 @@ function openlayers_geofield_default_openlayers_components() { 'source' => array( 'openlayers_geofield_source_vector' => 'openlayers_geofield_source_vector', ), - 'animations' => array( - 'pan' => 500, - 'zoom' => 500, - ), + 'duration' => '500', 'zoom' => 'auto', - 'enableAnimations' => 1, 'process_once' => 1, 'max_zoom' => 5, ); diff --git a/src/Plugin/Component/ZoomToSource/ZoomToSource.php b/src/Plugin/Component/ZoomToSource/ZoomToSource.php index cc2de22..06b2082 100644 --- a/src/Plugin/Component/ZoomToSource/ZoomToSource.php +++ b/src/Plugin/Component/ZoomToSource/ZoomToSource.php @@ -57,35 +57,11 @@ class ZoomToSource extends Component { '#description' => t('If enabled the zoom to source only will fire once at map build. And ignore change events on the source.'), ); - $form['options']['enableAnimations'] = array( - '#type' => 'checkbox', - '#title' => t('Enable animations'), - '#default_value' => isset($form_state['item']->options['enableAnimations']) ? $form_state['item']->options['enableAnimations'] : FALSE, - '#description' => t('Enable pan and zoom animation.'), - ); - - $form['options']['animations'] = array( - '#type' => 'fieldset', - '#title' => 'Animations options', - '#states' => array( - 'visible' => array( - 'input[name="options[enableAnimations]"' => array('checked' => TRUE), - ), - ), - ); - - $form['options']['animations']['pan'] = array( - '#type' => 'textfield', - '#title' => t('Pan animation duration'), - '#default_value' => isset($form_state['item']->options['animations']['pan']) ? $form_state['item']->options['animations']['pan'] : '500', - '#description' => t('Duration of the pan animation.'), - ); - - $form['options']['animations']['zoom'] = array( + $form['options']['duration'] = array( '#type' => 'textfield', - '#title' => t('Zoom animation duration'), - '#default_value' => isset($form_state['item']->options['animations']['zoom']) ? $form_state['item']->options['animations']['zoom'] : '500', - '#description' => t('Duration of the zoom animation.'), + '#title' => t('Animation duration'), + '#default_value' => isset($form_state['item']->options['duration']) ? $form_state['item']->options['duration'] : '500', + '#description' => t('Duration of the animation.'), ); } } diff --git a/src/Plugin/Component/ZoomToSource/js/zoomtosource.js b/src/Plugin/Component/ZoomToSource/js/zoomtosource.js index a8a943d..0161066 100644 --- a/src/Plugin/Component/ZoomToSource/js/zoomtosource.js +++ b/src/Plugin/Component/ZoomToSource/js/zoomtosource.js @@ -40,16 +40,8 @@ Drupal.openlayers.pluginManager.register({ if (!data.opt.process_once || !data.opt.processed_once) { data.opt.processed_once = true; - if (data.opt.enableAnimations === 1) { - var animationPan = ol.animation.pan({ - duration: data.opt.animations.pan, - source: map.getView().getCenter() - }); - var animationZoom = ol.animation.zoom({ - duration: data.opt.animations.zoom, - resolution: map.getView().getResolution() - }); - map.beforeRender(animationPan, animationZoom); + var animate_options = { + duration: data.opt.duration, } var maxExtent = calculateMaxExtent(); @@ -59,15 +51,16 @@ Drupal.openlayers.pluginManager.register({ if (data.opt.zoom !== 'disabled') { if (data.opt.zoom !== 'auto') { - map.getView().setZoom(data.opt.zoom); + animate_options.zoom = data.opt.zoom } else { - var zoom = map.getView().getZoom(); - if (data.opt.max_zoom !== undefined && data.opt.max_zoom > 0 && zoom > data.opt.max_zoom) { - zoom = data.opt.max_zoom; + animate_options.zoom = map.getView().getZoom(); + if (data.opt.max_zoom !== undefined && data.opt.max_zoom > 0 && animate_options.zoom > data.opt.max_zoom) { + animate_options.zoom = data.opt.max_zoom; } - map.getView().setZoom(zoom); } } + + map.getView().animate(animate_options); } };