first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_argparser_openlayers_behaviors() {
return array(
'title' => t('Argument Parser'),
'description' => t('Parses Permalink-formatted arguments without adding a
Permalink link to the map. Permalink is usually similar to:
?zoom=1&lat=11&lon=11&layers=B0F'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_argparser.inc',
'class' => 'openlayers_behavior_argparser',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_argparser extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'anchor' => FALSE,
);
}
function js_dependency() {
return array('OpenLayers.Control.ArgParser');
}
function options_form($defaults = array()) {
return array(
'anchor' => array(
'#type' => 'checkbox',
'#title' => t('Anchor'),
'#description' => t('Permalink is in the form of an anchor (#) instead of a query (?).'),
'#default_value' => (isset($defaults['anchor'])) ? $defaults['anchor'] : FALSE,
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_argparser.js');
return $this->options;
}
}

View File

@@ -0,0 +1,12 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* ArgParser Behavior. Implements the ArgParser OpenLayers
* Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_argparser', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'ArgParser', options);
});

View File

@@ -0,0 +1,58 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_attribution_openlayers_behaviors() {
return array(
'title' => t('Layer Attribution'),
'description' => t('Allows layers to provide attribution to the map if it exists. Most third-party layer will have some sort of attribution, but this may come with the actual tiles as well.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_attribution.inc',
'class' => 'openlayers_behavior_attribution',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_attribution extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'seperator' => '',
);
}
function js_dependency() {
return array('OpenLayers.Control.Attribution');
}
function options_form($defaults = array()) {
return array(
'seperator' => array(
'#type' => 'textfield',
'#title' => t('Seperator'),
'#description' => t('For multiple layers that need attribution, provide a separation string.'),
'#default_value' => (isset($defaults['seperator'])) ? $defaults['seperator'] : FALSE,
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_attribution.js');
return $this->options;
}
}

View File

@@ -0,0 +1,12 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Attribution Behavior. Implements the Attribution OpenLayers
* Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_attribution', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'Attribution', options);
});

View File

@@ -0,0 +1,57 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_boxselect_openlayers_behaviors() {
return array(
'title' => t('Bounding Box Select'),
'description' => t('Allows the selection and display of a bounding box. Currently hard-coded for the map making interface.'),
'type' => 'map',
'ui_visibility' => FALSE,
'behavior' => array(
'file' => 'openlayers_behavior_boxselect.inc',
'class' => 'openlayers_behavior_boxselect',
'parent' => 'openlayers_behavior',
),
);
}
/**
* BoxSelect Behavior
*/
class openlayers_behavior_boxselect extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'input_fields' => '',
);
}
function js_dependency() {
return array(
'OpenLayers.Control.DrawFeature',
'OpenLayers.Layer.Vector',
'OpenLayers.Handler.RegularPolygon'
);
}
function options_form($defaults = array()) {
return array(
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_boxselect.js');
return $this->options;
}
}

View File

@@ -0,0 +1,61 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
// Not the best, but gets around scoping;
var selections_layer;
(function ($) {
/**
* Box Select Behavior. Allows user to select a bounding box.
*
* TODO: This is currently hard coded for the center UI form.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_boxselect', function (data, options) {
// Callback to set extent into a specific form item.
function setRestrictedExtent(box) {
var bounding_box = box.geometry.getBounds().toBBOX();
$('#edit-center-restrict-restrictedextent').val(bounding_box);
// Check box
if (!($('#restrictextent').attr('checked'))) {
$('#restrictextent')
.attr('checked', 'checked')
.trigger('change');
}
// Remove any other features.
for (var i = 0; i < selections_layer.features.length; i++) {
if (selections_layer.features[i] != box) {
selections_layer.features[i].destroy();
}
}
}
// Create layer to draw with and handle events.
var selections_layer = new OpenLayers.Layer.Vector('Temporary Box Layer');
var control = new OpenLayers.Control.DrawFeature(selections_layer,
OpenLayers.Handler.RegularPolygon, {
featureAdded: setRestrictedExtent
}
);
control.handler.setOptions({
'keyMask': OpenLayers.Handler.MOD_SHIFT,
'sides': 4,
'irregular': true
});
control.events.on({'featureAdded': this.setRestrictedExtent});
data.openlayers.addLayer(selections_layer);
data.openlayers.addControl(control);
// If there already is a value, then update the map appropriately.
if ($('#edit-center-restrict-restrictedextent').val()) {
bounds = $('#edit-center-restrict-restrictedextent').val();
geometry = new OpenLayers.Bounds.fromString(bounds).toGeometry();
feature = new OpenLayers.Feature.Vector(geometry);
selections_layer.addFeatures([feature]);
}
control.activate();
});
}(jQuery));

View File

@@ -0,0 +1,96 @@
<?php
/**
* @file
* Implementation of OpenLayers Cluster behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_cluster_openlayers_behaviors() {
return array(
'title' => t('Cluster Features'),
'description' => t('Provides vector layer features clustering by proximity. This will not always respect the styles that assigned to the layer.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_cluster.inc',
'class' => 'openlayers_behavior_cluster',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Cluster behavior
*/
class openlayers_behavior_cluster extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'clusterlayer' => array(),
'distance' => '20',
'threshold' => NULL,
);
}
/**
* OpenLayers library dependency.
*/
function js_dependency() {
return array('OpenLayers.Strategy.Cluster');
}
/**
* Provide form for configurations per map.
*/
function options_form($defaults = array()) {
// Only prompt for vector layers
$vector_layers = array();
foreach ($this->map['layers'] as $id => $name) {
$layer = openlayers_layer_load($id);
if (isset($layer->data['vector']) && $layer->data['vector'] == TRUE) {
$vector_layers[$id] = $name;
}
}
return array(
'clusterlayer' => array(
'#title' => t('Layers'),
'#type' => 'checkboxes',
'#options' => $vector_layers,
'#description' => t('Select layers to cluster.'),
'#default_value' => isset($defaults['clusterlayer']) ?
$defaults['clusterlayer'] : array(),
),
'distance' => array(
'#type' => 'textfield',
'#default_value' => (isset($defaults['distance'])) ?
$defaults['distance'] : 20,
'#size' => 5,
'#title' => t('Distance'),
'#description' => t('Pixel distance between features that should ' .
'be considered a single cluster'),
),
'threshold' => array(
'#type' => 'textfield',
'#default_value' => (isset($defaults['threshold'])) ?
$defaults['threshold'] : NULL,
'#size' => 5,
'#title' => t('Threshold'),
'#description' => t('Optional threshold below which original ' .
'features will be added to the layer instead of clusters'),
)
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_cluster.js');
return $this->options;
}
}

View File

@@ -0,0 +1,69 @@
/**
* @file
* OpenLayers Behavior implementation for clustering.
*/
/**
* OpenLayers Cluster Behavior.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_cluster', function (data, options) {
var map = data.openlayers;
var distance = parseInt(options.distance, 10);
var threshold = parseInt(options.threshold, 10);
var layers = [];
for (var i in options.clusterlayer) {
var selectedLayer = map.getLayersBy('drupalID', options.clusterlayer[i]);
if (typeof selectedLayer[0] != 'undefined') {
layers.push(selectedLayer[0]);
}
}
// Go through chosen layers
for (var i in layers) {
var layer = layers[i];
// Ensure vector layer
if (layer.CLASS_NAME == 'OpenLayers.Layer.Vector') {
var cluster = new OpenLayers.Strategy.Cluster(options);
layer.addOptions({ 'strategies': [cluster] });
cluster.setLayer(layer);
cluster.features = layer.features.slice();
cluster.activate();
cluster.cluster();
}
}
});
/**
* Override of callback used by 'popup' behaviour to support clusters
*/
Drupal.theme.openlayersPopup = function (feature) {
if (feature.cluster) {
var output = '';
var visited = []; // to keep track of already-visited items
var classes = [];
for (var i = 0; i < feature.cluster.length; i++) {
var pf = feature.cluster[i]; // pseudo-feature
if (typeof pf.drupalFID != 'undefined') {
var mapwide_id = feature.layer.drupalID + pf.drupalFID;
if (mapwide_id in visited) continue;
visited[mapwide_id] = true;
}
classes = ['openlayers-popup', 'openlayers-popup-feature'];
if (i == 0) {
classes.push('first');
}
if (i == (feature.cluster.length - 1)) {
classes.push('last');
}
output += '<div class="'+classes.join(' ')+'">' +
Drupal.theme.prototype.openlayersPopup(pf) + '</div>';
}
return output;
}
else {
return Drupal.theme.prototype.openlayersPopup(feature);
}
};

View File

@@ -0,0 +1,73 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_dragpan_openlayers_behaviors() {
return array(
'title' => t('Mouse Drag Pan'),
'description' => t('Provides the ability to pan in the map interface with the mouse. The Navigation Control includes this control. You should only use this behavior if you want fine control over what interactions you want on your map.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_dragpan.inc',
'class' => 'openlayers_behavior_dragpan',
'parent' => 'openlayers_behavior',
),
);
}
/**
* DragPan Behavior
*/
class openlayers_behavior_dragpan extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'enableKinetic' => FALSE,
'kineticInterval' => 10,
);
}
function js_dependency() {
return array('OpenLayers.Control.DragPan');
}
function options_form($defaults = array()) {
$form = array();
// This options seem to be buggy. Shoudl look into more.
/*
$form = array(
'enableKinetic' => array(
'#title' => t('Enable Kinetic Dragging'),
'#type' => 'checkbox',
'#description' => t('Enables dragging and panning to have acceleration.'),
'#default_value' => isset($defaults['enableKinetic']) ? $defaults['enableKinetic'] : FALSE,
),
'kineticInterval' => array(
'#title' => t('Kinetic Interval'),
'#type' => 'textfield',
'#description' => t('An integer of millseconds of time between steps in "Kinetic Scrolling".'),
'#default_value' => isset($defaults['kineticInterval']) ? $defaults['kineticInterval'] : 10,
),
);
*/
return $form;
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_dragpan.js');
return $this->options;
}
}

View File

@@ -0,0 +1,12 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* DragPan Behavior. Implements the DragPan OpenLayers
* Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_dragpan', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'DragPan', options);
});

View File

@@ -0,0 +1,12 @@
/**
* @file
* CSS for OpenLayers Draw Features Behavior
*/
.olControlEditingToolbar .olControlModifyFeatureItemActive {
background-position: -1px -24px;
}
.olControlEditingToolbar .olControlModifyFeatureItemInactive {
background-position: -1px -1px;
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_drawfeatures_openlayers_behaviors() {
return array(
'title' => t('Draw Features'),
'description' => t('Provides functionality for adding features to a map.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_drawfeatures.inc',
'class' => 'openlayers_behavior_drawfeatures',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Draw Features behavior
*/
class openlayers_behavior_drawfeatures extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'element_id' => '',
'feature_types' => array(),
'feature_limit' => 0,
);
}
function options_form($defaults = array()) {
$features = array(
'point' => t('Point'),
'path' => t('Path'),
'polygon' => t('Polygon'),
);
return array(
'feature_types' => array(
'#title' => t('Available Features'),
'#type' => 'checkboxes',
'#options' => $features,
'#description' => t('Select what features are available to draw.'),
'#default_value' => isset($defaults['feature_types']) ? $defaults['feature_types'] : array(),
),
'feature_limit' => array(
'#title' => t('Number of features'),
'#type' => 'textfield',
'#description' => t('The number of features that are allowed to be
drawn. Leave blank or at 0 for unlimited.'),
'#default_value' => isset($defaults['feature_limit']) ? $defaults['feature_limit'] : 0,
),
'element_id' => array(
'#type' => 'textfield',
'#default_value' => (isset($defaults['element_id'])) ?
$defaults['element_id'] : '',
'#title' => t('Element ID'),
'#description' => t('The DOM element ID that will be passed the value of the features. This will probably be a textfield or textarea.'),
)
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_css(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_drawfeatures.css');
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_drawfeatures.js');
return $this->options;
}
}

View File

@@ -0,0 +1,153 @@
/**
* @file
* DrawFeatures Behavior
*/
(function($) {
/**
* Behavior for Draw Features.
*
* TODO: Update this to use the addBehaviors helper function.
*/
Drupal.behaviors.openlayers_behavior_drawfeatures = {
'attach': function(context, settings) {
// Update function to write to element.
function openlayers_behavior_drawfeatures_update(features) {
WktWriter = new OpenLayers.Format.WKT();
while (features.type == 'featureadded' && (this.feature_limit > 0) &&
(this.feature_limit < features.object.features.length)) {
features.feature.layer.removeFeatures(features.object.features.shift());
}
var features_copy = features.object.clone();
for (var i in features_copy.features) {
features_copy.features[i].geometry.transform(
features.object.map.projection,
new OpenLayers.Projection('EPSG:4326')
);
}
if (this.element != undefined) {
this.element.val(WktWriter.write(features_copy.features));
}
}
// Start behavior process
var data = $(context).data('openlayers');
var behavior = data && data.map.behaviors['openlayers_behavior_drawfeatures'];
if (!$(context).hasClass('openlayers-drawfeatures-processed') && behavior) {
// Create element
var feature_types = data.map.behaviors['openlayers_behavior_drawfeatures'].feature_types;
if (data.map.behaviors['openlayers_behavior_drawfeatures'].element_id != "") {
this.element = $('#' + data.map.behaviors['openlayers_behavior_drawfeatures'].element_id);
}
// Handle vector layer for drawing on
this.feature_limit = data.map.behaviors['openlayers_behavior_drawfeatures'].feature_limit;
var dataLayer = new OpenLayers.Layer.Vector(Drupal.t('Feature Layer'), {
projection: new OpenLayers.Projection('EPSG:4326'),
drupalID: 'openlayers_drawfeatures_layer'
});
dataLayer.styleMap = Drupal.openlayers.getStyleMap(data.map, 'openlayers_drawfeatures_layer');
data.openlayers.addLayer(dataLayer);
if (this.feature_limit == "") {
this.feature_limit = 0;
}
// If there is data in there now, use to populate the layer.
if ((this.element != undefined) && (this.element.text() != '')) {
var wktFormat = new OpenLayers.Format.WKT();
var features = wktFormat.read(this.element.text());
if (features.constructor == Array) {
for (var i in features) {
features[i].geometry = features[i].geometry.transform(
new OpenLayers.Projection('EPSG:4326'),
data.openlayers.projection
);
}
}
else {
features.geometry = features.geometry.transform(
new OpenLayers.Projection('EPSG:4326'),
data.openlayers.projection
);
features = [features];
}
dataLayer.addFeatures(features);
}
// Registering events late, because adding data
// would result in a reprojection loop
dataLayer.events.register('featureadded', this,
openlayers_behavior_drawfeatures_update);
dataLayer.events.register('featureremoved', this,
openlayers_behavior_drawfeatures_update);
dataLayer.events.register('featuremodified', this,
openlayers_behavior_drawfeatures_update);
// Use the Editing Toolbar for creating features.
var control = new OpenLayers.Control.EditingToolbar(dataLayer);
data.openlayers.addControl(control);
control.activate();
// Build an array of the requested feature classes
var feature_classmap = {
'point': 'OpenLayers.Handler.Point',
'path': 'OpenLayers.Handler.Path',
'polygon': 'OpenLayers.Handler.Polygon'
};
var feature_classes = [];
for (var i in feature_types) {
if (feature_types[i] !== 0) {
feature_classes.push(feature_classmap[feature_types[i]]);
}
}
// Reconstruct editing toolbar controls so to only contain
// the tools for the requested feature types / classes
// plus the navigation tool
control.controls = $.map(control.controls,
function(control) {
return (control.CLASS_NAME == 'OpenLayers.Control.Navigation' ||
$.inArray(control.handler.CLASS_NAME, feature_classes) != -1)
? control : null;
}
);
control.activateControl(control.getControlsByClass('OpenLayers.Control.Navigation')[0]);
control.redraw();
if (this.element != undefined) {
this.element.parents('form').bind('submit',
{
control: control,
dataLayer: dataLayer
}, function(evt) {
$.map(evt.data.control.controls, function(c) { c.deactivate(); });
dataLayer.events.triggerEvent('featuremodified');
}
);
}
// Add modify feature tool
control.addControls(new OpenLayers.Control.ModifyFeature(
dataLayer, {
displayClass: 'olControlModifyFeature',
deleteCodes: [46, 68, 100],
handleKeypress: function(evt) {
if (this.feature && $.inArray(evt.keyCode, this.deleteCodes) > -1) {
// We must unselect the feature before we delete it
var feature_to_delete = this.feature;
this.selectControl.unselectAll();
this.layer.removeFeatures([feature_to_delete]);
}
}
}
)
);
$(context).addClass('openlayers-drawfeatures-processed');
}
}
};
})(jQuery);

View File

@@ -0,0 +1,25 @@
.openlayers_map_fullscreen {
position: fixed;
z-index: 9999;
background-color: #fff;
top: 0;
left: 0;
height: 100% !important;
width: 100% !important;
}
.openlayers_behavior_fullscreen_button_panel {
position: absolute;
top: 5px;
right: 5px;
}
.openlayers_behavior_fullscreen_buttonItemInactive {
background:url(openlayers_behavior_fullscreen.png);
width:20px;
height:20px;
}
.openlayers_map_fullscreen .openlayers_behavior_fullscreen_buttonItemInactive {
background-position:20px 0;
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_fullscreen_openlayers_behaviors() {
return array(
'title' => t('Fullscreen'),
'description' => t('Provides a button that expands maps to the size of the page.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_fullscreen.inc',
'class' => 'openlayers_behavior_fullscreen',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Fullscreen Behavior
*/
class openlayers_behavior_fullscreen extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'activated' => FALSE
);
}
/**
* Provide form for configurations per map.
*/
function options_form($defaults = array()) {
return array(
'activated' => array(
'#title' => t('Initially activated'),
'#type' => 'checkbox',
'#description' => t('Select to be in fullscreen by default.'),
'#default_value' => isset($defaults['activated']) ? $defaults['activated'] : FALSE
)
);
}
function js_dependency() {
return array(
'OpenLayers.Control.Button'
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_css(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_fullscreen.css');
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_fullscreen.js');
return $this->options;
}
}

View File

@@ -0,0 +1,46 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Attribution Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_fullscreen', function (data, options) {
// Create new panel control and add.
var fullscreenPanel = new OpenLayers.Control.Panel({
displayClass: 'openlayers_behavior_fullscreen_button_panel'
});
data.openlayers.addControl(fullscreenPanel);
// Create toggleing control and cutton.
var toggler = OpenLayers.Function.bind(
Drupal.openlayers.fullscreenToggle, data);
var button = new OpenLayers.Control.Button({
displayClass: 'openlayers_behavior_fullscreen_button',
title: Drupal.t('Fullscreen'),
trigger: toggler
});
fullscreenPanel.addControls([button]);
// Make fullscreen by default if activited.
if (options.activated == true) {
toggler();
}
});
(function ($) {
/**
* Toggling function for FullScreen control.
*/
Drupal.openlayers.fullscreenToggle = function () {
var map = this.openlayers;
var $map = $(this.openlayers.div);
var extent = map.getExtent();
$map.parent().toggleClass('openlayers_map_fullscreen');
$map.toggleClass('openlayers_map_fullscreen');
$map.data('openlayers').openlayers.updateSize();
$map.data('openlayers').openlayers.zoomToExtent(extent, true);
};
}(jQuery));

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

View File

@@ -0,0 +1,91 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_geolocate_openlayers_behaviors() {
return array(
'title' => t('Geolocate Client'),
'description' => t('Provides the geolcoation control that simply zooms to users location on map load. Based on HTML5 geolocation, so this will not be supported in all browsers.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_geolocate.inc',
'class' => 'openlayers_behavior_geolocate',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Zoom Panel Behavior
* http://dev.openlayers.org/docs/files/OpenLayers/Control/Geolocate-js.html
*/
class openlayers_behavior_geolocate extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'bind' => TRUE,
'watch' => FALSE,
'geolocationOptions' => array(
'enableHighAccuracy' => FALSE,
'maximumAge' => 0,
'timeout' => 7000,
),
'zoom_level' => 12,
);
}
function options_form($defaults = array()) {
$intials = $this->options_init();
return array(
'bind' => array(
'#title' => t('Center when located'),
'#type' => 'select',
'#options' => array(
TRUE => t('Yes'),
FALSE => t('No'),
),
'#description' => t('When enabled, if the geolocation control finds a location, it will set the center of the map at this point.'),
'#default_value' => isset($defaults['bind']) ? $defaults['bind'] : $intials['bind'],
),
'zoom_level' => array(
'#title' => t('Zoom level'),
'#type' => 'textfield',
'#description' => t('An integer zoom level for when a location is found. 0 is the most zoomed out and higher numbers mean more zoomed in (the number of zoom levels depends on your map).'),
'#default_value' => isset($defaults['zoom_level']) ? $defaults['zoom_level'] : $intials['zoom_level'],
),
'watch' => array(
'#title' => t('Watch'),
'#type' => 'select',
'#options' => array(
TRUE => t('Yes'),
FALSE => t('No'),
),
'#description' => t('When enabled, the map will continue to try to update the location of the device.'),
'#default_value' => isset($defaults['watch']) ? $defaults['watch'] : $intials['watch'],
),
);
}
function js_dependency() {
return array(
'OpenLayers.Control.Geolocate'
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_geolocate.js');
return $this->options;
}
}

View File

@@ -0,0 +1,29 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Geolocate Control. Implements the Geolocate OpenLayers
* Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_geolocate', function (data, options) {
// Create Geolocate control
var geolocate = new OpenLayers.Control.Geolocate(options);
data.openlayers.addControl(geolocate);
// Adding the watch options.
// {Boolean} If true, position will be update regularly.
geolocate.watch = (options.watch == 1) ? true : false;
// Add some event handling
geolocate.events.register('locationupdated', this, function(e) {
data.openlayers.setCenter(new OpenLayers.Geometry.Point(e.point.x, e.point.y), options.zoom_level);
});
geolocate.events.register('locationfailed', this, function(e) {
OpenLayers.Console.log(Drupal.t('Location detection failed'));
});
// Activate!
geolocate.activate();
});

View File

@@ -0,0 +1,100 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_graticule_openlayers_behaviors() {
return array(
'title' => t('Graticule'),
'description' => t('Adds a graticule control to the map to display a grid of latitude and longitude.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_graticule.inc',
'class' => 'openlayers_behavior_graticule',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_graticule extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'labelled' => TRUE,
'numPoints' => 50,
'targetSize' => 200,
'displayInLayerSwitcher' => TRUE,
'lineSymbolizer' => array(
'strokeColor' => '#333',
'strokeWidth' => 1,
'strokeOpacity' => 0.5
)
);
}
function options_form($defaults = array()) {
return array(
'displayInLayerSwitcher' => array(
'#type' => 'checkbox',
'#title' => t('Display in layer switcher ?'),
'#description' => t('Allows the Graticule control to be switched on and off by LayerSwitcher control. Default is true.'),
'#default_value' => (isset($defaults['displayInLayerSwitcher'])) ? $defaults['displayInLayerSwitcher'] : TRUE,
),
'labelled' => array(
'#type' => 'checkbox',
'#title' => t('Labelled'),
'#description' => t('Should the graticule lines be labelled ? Default is true.'),
'#default_value' => (isset($defaults['labelled'])) ? $defaults['labelled'] : TRUE,
),
'numPoints' => array(
'#type' => 'textfield',
'#title' => t('Number of points'),
'#description' => t('The number of points to use in each graticule line. Higher numbers result in a smoother curve for projected maps '),
'#default_value' => (isset($defaults['numPoints'])) ? $defaults['numPoints'] : 50,
),
'targetSize' => array(
'#type' => 'textfield',
'#title' => t('Target size'),
'#description' => t('The maximum size of the grid in pixels on the map.'),
'#default_value' => (isset($defaults['targetSize'])) ? $defaults['targetSize'] : 200,
),
'lineSymbolizer' => array(
'strokeColor' => array(
'#type' => 'textfield',
'#title' => t('Stroke color'),
'#description' => t('The color code to use for the lines. Example: #333'),
'#default_value' => (isset($defaults['lineSymbolizer']['strokeColor'])) ? $defaults['lineSymbolizer']['strokeColor'] : '#333',
),
'strokeWidth' => array(
'#type' => 'textfield',
'#title' => t('Stroke width'),
'#description' => t('The width of the lines. Example: 1'),
'#default_value' => (isset($defaults['lineSymbolizer']['strokeWidth'])) ? $defaults['lineSymbolizer']['strokeWidth'] : 1,
),
'strokeOpacity' => array(
'#type' => 'textfield',
'#title' => t('Stroke opacity'),
'#description' => t('The opacity of the line, from 0 to 1. Example: 0.5'),
'#default_value' => (isset($defaults['lineSymbolizer']['strokeOpacity'])) ? $defaults['lineSymbolizer']['strokeOpacity'] : 0.5,
),
)
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_graticule.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Graticule Behavior. Implements the Graticule Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_graticule', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'Graticule', options);
});

View File

@@ -0,0 +1,44 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_keyboarddefaults_openlayers_behaviors() {
return array(
'title' => t('Keyboard Controls'),
'description' => t('Provides keyboard shortcuts to pan and zoom the map, such as the up, down, left, and right arrows. This is included with the Navigation control. This should not be enabled unless you want to have finer control on how the user interacts with the map.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_keyboarddefaults.inc',
'class' => 'openlayers_behavior_keyboarddefaults',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Keyboard Defaults Behavior
*/
class openlayers_behavior_keyboarddefaults extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'keyboarddefaults' => '',
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_keyboarddefaults.js');
return $this->options;
}
}

View File

@@ -0,0 +1,13 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Keyboard Defaults Behavior. Implements the KeyboardDefaults OpenLayers
* Control.
*/
Drupal.openlayers.addBehavior('openlayers_behavior_keyboarddefaults', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'KeyboardDefaults');
});

View File

@@ -0,0 +1,104 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_layerswitcher_openlayers_behaviors() {
return array(
'title' => t('Layer Switcher'),
'description' => t('Provides the ability to switch layers in the map interface. This provides an expandable box on the map to enable and disable layers.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_layerswitcher.inc',
'class' => 'openlayers_behavior_layerswitcher',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Layer Switcher Behavior
*/
class openlayers_behavior_layerswitcher extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layerswitcher' => '',
'ascending' => TRUE,
'sortBaseLayer' => '0',
'roundedCorner' => TRUE,
'roundedCornerColor' => '#222222',
'maximizeDefault' => FALSE,
);
}
function js_dependency() {
return array('OpenLayers.Control.LayerSwitcher');
}
function options_form($defaults = array()) {
return array(
'ascending' => array(
'#type' => 'checkbox',
'#title' => t('Show layers in ascending order'),
'#description' => t('Higher layers shown toward the bottom'),
'#default_value' => isset($defaults['ascending']) ? $defaults['ascending'] : TRUE,
),
'sortBaseLayer' => array(
'#type' => 'select',
'#title' => t('Sort Base Layers by Title'),
'#description' => t('Display the layers in the layer switcher by title'),
'#default_value' => isset($defaults['sortBaseLayer']) ? $defaults['sortBaseLayer'] : 0,
'#options' => array('0' => t('- None -'), 'ASC' => t('ASC'), 'DESC' => 'DESC'),
),
'roundedCorner' => array(
'#type' => 'checkbox',
'#title' => t('Rounded corners'),
'#description' => t('If true the Rico library is used for rounding the corners of the layer switcher box.'),
'#default_value' => isset($defaults['roundedCorner']) ? $defaults['roundedCorner'] : TRUE,
),
'roundedCornerColor' => array(
'#type' => 'textfield',
'#title' => t('Rounded corners color'),
'#description' => t('For rounded corners, this is the CSS color to use for the corners.'),
'#default_value' => isset($defaults['roundedCornerColor']) ? $defaults['roundedCornerColor'] : '#222222',
),
'maximizeDefault' => array(
'#type' => 'checkbox',
'#title' => t('Maximize by Default'),
'#description' => t('Turn on to have the Layer Switcher open by default.'),
'#default_value' => isset($defaults['maximizeDefault']) ? $defaults['maximizeDefault'] : FALSE,
),
);
}
/**
* Render.
*/
function render(&$map) {
// Legacy code for maps not using the default images now
// provided with the code, or for maps that dont have images
// set. We have to set the rounded corner color and add a
// class for CSS to style
if (empty($map['image_path'])) {
$this->options['roundedCornerColor'] = 'darkblue';
$this->options['displayClass'] = 'olControlLayerSwitcher legacy';
}
if ($this->options['sortBaseLayer'] == 'ASC' || $this->options['sortBaseLayer'] == 'DESC') {
uasort($map['layers'], 'drupal_sort_title');
if ($this->options['sortBaseLayer'] == 'ASC') {
$map['layers'] = array_reverse ($map['layers'], TRUE);
}
}
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_layerswitcher.js');
return $this->options;
}
}

View File

@@ -0,0 +1,17 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Layer Switcher Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_layerswitcher', function (data, options) {
options.ascending = !! options.ascending;
Drupal.openlayers.addControl(data.openlayers, 'LayerSwitcher', options);
// Maximize if needed.
if (!! options.maximizeDefault == true) {
data.openlayers.getControlsByClass('OpenLayers.Control.LayerSwitcher')[0].maximizeControl();
}
});

View File

@@ -0,0 +1,67 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_layerzoom_openlayers_behaviors() {
return array(
'title' => t('Zoom restrictions for non-base layers.'),
'description' => t('Enables restriction of layer display based on zoom level.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_layerzoom.inc',
'class' => 'openlayers_behavior_layerzoom',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_layerzoom extends openlayers_behavior {
function options_form($defaults = array()) {
$options = array();
foreach ($this->map['layers'] as $layer) {
if ($layer != $this->map['default_layer']) {
$options[$layer] = array(
'enable' => array(
'#type' => 'checkbox',
'#title' => t('Enable dynamic zoom levels for @layer', array('@layer' => $layer)),
'#default_value' => isset($this->options[$layer]['enable']) ? $this->options[$layer]['enable'] : 0,
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)
),
'#title' => t('Zoom Level Range for @layer', array('@layer' => $layer)),
'#default_value' => isset($this->options[$layer]['resolutions']) ?
$this->options[$layer]['resolutions'] :
array_map('strval', openlayers_get_resolutions('900913')),
'#description' => t('The zoom levels at which this layer will display.'),
),
);
}
}
return $options;
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_layerzoom.js');
return $this->options;
}
}

View File

@@ -0,0 +1,25 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* OpenLayers Zoom to Layer Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_layerzoom', function (data, options) {
var map = data.openlayers;
for (var layerName in options) {
if (options[layerName].enable) {
var layers = map.getLayersBy('drupalID', layerName);
// Go through selected layers to get full extent.
for (var i in layers) {
layer = layers[i];
// Restrict zoom levels.
var keys = Object.keys(options[layerName].resolutions);
layer.alwaysInRange = false;
layer.minResolution = options[layerName].resolutions[keys[keys.length-1]];
layer.maxResolution = options[layerName].resolutions[keys[0]];
}
}
}
});

View File

@@ -0,0 +1,46 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_mapformvalues_openlayers_behaviors() {
return array(
'title' => t('Map Form Values'),
'description' => t('Provides a way of updating form elements with zoom level and centering from a map.'),
'type' => 'map',
'ui_visibility' => FALSE,
'behavior' => array(
'file' => 'openlayers_behavior_mapformvalues.inc',
'class' => 'openlayers_behavior_mapformvalues',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Map Form Values Behavior
*/
class openlayers_behavior_mapformvalues extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'center_form' => '#edit-center-initial-centerpoint',
'zoom_form' => '#edit-center-initial-zoom'
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_mapformvalues.js');
return $this->options;
}
}

View File

@@ -0,0 +1,44 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
(function ($) {
/**
* Map Form Values Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_mapformvalues', function (data, options) {
function updateForm(evt) {
if (evt.object.centerpoint_form) {
center = evt.object.getCenter().transform(
evt.object.projection,
new OpenLayers.Projection('EPSG:4326')).toShortString();
evt.object.centerpoint_form.val(center);
}
if (evt.object.zoom_form) {
zoom = evt.object.getZoom();
evt.object.zoom_form.val(zoom);
}
}
centerpoint_form = $(options.center_form);
zoom_form = $(options.zoom_form);
if (centerpoint_form.length) {
data.openlayers.centerpoint_form = centerpoint_form;
center_point = centerpoint_form.val();
data.openlayers.setCenter(
OpenLayers.LonLat.fromString(center_point).transform(
new OpenLayers.Projection('EPSG:4326'),
data.openlayers.projection)
);
}
if (zoom_form.length) {
data.openlayers.zoom_form = zoom_form;
zoom = zoom_form.val();
data.openlayers.zoomTo(parseInt(zoom));
}
data.openlayers.events.on({'moveend': updateForm});
});
}(jQuery));

View File

@@ -0,0 +1,87 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_mouseposition_openlayers_behaviors() {
return array(
'title' => t('Mouse Position'),
'description' => t('Provides a visual indication of the mouse position to the user.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_mouseposition.inc',
'class' => 'openlayers_behavior_mouseposition',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Mouse Position Behavior
*/
class openlayers_behavior_mouseposition extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'prefix' => '',
'separator' => ', ',
'suffix' => '',
'numDigits' => 4,
'emptyString' => '',
);
}
function js_dependency() {
return array('OpenLayers.Control.MousePosition');
}
function options_form($defaults = array()) {
return array(
'prefix' => array(
'#title' => t('Prefix'),
'#type' => 'textfield',
'#description' => t('A textual prefix to the mouse position.'),
'#default_value' => isset($defaults['prefix']) ? $defaults['prefix'] : '',
),
'separator' => array(
'#title' => t('Separator'),
'#type' => 'textfield',
'#description' => t('A textual separator between the first and second value.'),
'#default_value' => isset($defaults['separator']) ? $defaults['separator'] : ', ',
),
'suffix' => array(
'#title' => t('Suffix'),
'#type' => 'textfield',
'#description' => t('A textual suffix to the mouse position.'),
'#default_value' => isset($defaults['suffix']) ? $defaults['suffix'] : '',
),
'numDigits' => array(
'#title' => t('Number of Decimal Digits'),
'#type' => 'textfield',
'#description' => t('Number of decimal digits to show.'),
'#default_value' => isset($defaults['numDigits']) ? $defaults['numDigits'] : '',
),
'emptyString' => array(
'#title' => t('Empty Value'),
'#type' => 'textfield',
'#description' => t('What will be seen if there is no value for the mouse position.'),
'#default_value' => isset($defaults['emptyString']) ? $defaults['emptyString'] : '',
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_mouseposition.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Mouse Position Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_mouseposition', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'MousePosition', options);
});

View File

@@ -0,0 +1,75 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_navigation_openlayers_behaviors() {
return array(
'title' => t('Navigation'),
'description' => t('Provides the ability to navigate the map interface. This is just for user interactions and does not show any visual controls. This behavior automatically includes the Pan Zoom, Zoom Box, and Pinch Zoom controls.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_navigation.inc',
'class' => 'openlayers_behavior_navigation',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Navigation Behavior
*/
class openlayers_behavior_navigation extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'navigation' => '',
'zoomWheelEnabled' => TRUE,
'zoomBoxEnabled' => TRUE,
'documentDrag' => FALSE,
);
}
function js_dependency() {
return array('OpenLayers.Control.Navigation');
}
function options_form($defaults = array()) {
return array(
'zoomWheelEnabled' => array(
'#type' => 'checkbox',
'#title' => t('Enable Zoom Wheel'),
'#description' => t('Enable zooming via the mouse scroll wheel. This can
interfere with page scrolling.'),
'#default_value' => isset($defaults['zoomWheelEnabled']) ? $defaults['zoomWheelEnabled'] : TRUE
),
'zoomBoxEnabled' => array(
'#type' => 'checkbox',
'#title' => t('Enable Zoom Box'),
'#description' => t('Enable zooming with selecting a box by <em>SHIFT + clicking</em>.'),
'#default_value' => isset($defaults['zoomBoxEnabled']) ? $defaults['zoomBoxEnabled'] : TRUE
),
'documentDrag' => array(
'#type' => 'checkbox',
'#title' => t('Document Drag'),
'#description' => t('Allow panning of the map by dragging outside map viewport.'),
'#default_value' => isset($defaults['documentDrag']) ? $defaults['documentDrag'] : FALSE
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_navigation.js');
return $this->options;
}
}

View File

@@ -0,0 +1,12 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Navigation Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_navigation', function (data, options) {
options.documentDrag = !!options.documentDrag;
Drupal.openlayers.addControl(data.openlayers, 'Navigation', options);
});

View File

@@ -0,0 +1,49 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_panzoom_openlayers_behaviors() {
return array(
'title' => t('Pan and Zoom Control'),
'description' => t('Provides controls with the ability to pan and zoom in the map interface. Do not use with the Pan Zoom Bar Control or the Zoom Panel Control.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_panzoom.inc',
'class' => 'openlayers_behavior_panzoom',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Pan Zoom Bar Behavior
*/
class openlayers_behavior_panzoom extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'panzoom' => '',
);
}
function options_form($defaults = array()) {
return array(
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_panzoom.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Pan Zoom Bar Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_panzoom', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'PanZoom');
});

View File

@@ -0,0 +1,66 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_panzoombar_openlayers_behaviors() {
return array(
'title' => t('Pan and Zoom Bar Controls'),
'description' => t('Gives user ability to pan and zoom, with a full zoom bar in the map interface. Do not use with Pan Zoom Contols or Zoom Panel Controls.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_panzoombar.inc',
'class' => 'openlayers_behavior_panzoombar',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Pan Zoom Bar Behavior
*/
class openlayers_behavior_panzoombar extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'zoomWorldIcon' => FALSE,
'panIcons' => TRUE,
);
}
function js_dependency() {
return array('OpenLayers.Control.PanZoomBar');
}
function options_form($defaults = array()) {
return array(
'zoomWorldIcon' => array(
'#type' => 'checkbox',
'#title' => t('World Icon'),
'#description' => t('This puts the world icon in the pan controls. This button will zoom to the max extent when it is pressed.'),
'#default_value' => isset($defaults['zoomWorldIcon']) ? $defaults['zoomWorldIcon'] : FALSE
),
'panIcons' => array(
'#type' => 'checkbox',
'#title' => t('Pan Icons'),
'#description' => t('Enable the pan controls. Without it, then the user will only see a zoom bar.'),
'#default_value' => isset($defaults['panIcons']) ? $defaults['panIcons'] : TRUE
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_panzoombar.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Pan Zoom Bar Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_panzoombar', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'PanZoomBar', options);
});

View File

@@ -0,0 +1,59 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_permalink_openlayers_behaviors() {
return array(
'title' => t('Permalink'),
'description' => t('Provides a link that will create an URL that will link to a specific map position. Permalink is usually similar to: ?zoom=1&lat=11&lon=11&layers=B0F'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_permalink.inc',
'class' => 'openlayers_behavior_permalink',
'parent' => 'openlayers_behavior',
),
);
}
/**
* PermaLink Behavior
*/
class openlayers_behavior_permalink extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'anchor' => FALSE,
);
}
function js_dependency() {
return array('OpenLayers.Control.Permalink');
}
function options_form($defaults = array()) {
return array(
'anchor' => array(
'#type' => 'checkbox',
'#title' => t('Anchor'),
'#description' => t('Permalink is in the form of an anchor (#) instead of a query (?). Also, this means that the URL location will be constantly updated, and no link will appear.'),
'#default_value' => (isset($defaults['anchor'])) ? $defaults['anchor'] : FALSE,
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_permalink.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Permalink Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_permalink', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'Permalink', options);
});

View File

@@ -0,0 +1,85 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_popup_openlayers_behaviors() {
return array(
'title' => t('Pop Up for Features'),
'description' => t('Adds clickable info boxes to points or shapes on maps. This does not work with the Tooltip behavior due to limitation of event handling in the OpenLayers library.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_popup.inc',
'class' => 'openlayers_behavior_popup',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_popup extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layers' => array(),
'panMapIfOutOfView' => FALSE,
'keepInMap' => TRUE,
);
}
/**
* Form defintion for per map customizations.
*/
function options_form($defaults = array()) {
// Only prompt for vector layers
$vector_layers = array();
foreach ($this->map['layers'] as $id => $name) {
$layer = openlayers_layer_load($id);
if (isset($layer->data['vector']) && $layer->data['vector'] == TRUE) {
$vector_layers[$id] = $name;
}
}
return array(
'layers' => array(
'#title' => t('Layers'),
'#type' => 'checkboxes',
'#options' => $vector_layers,
'#description' => t('Select layer to apply popups to.'),
'#default_value' => isset($defaults['layers']) ?
$defaults['layers'] : array(),
),
'panMapIfOutOfView' => array(
'#type' => 'checkbox',
'#title' => t('Pan map if popup out of view'),
'#description' => t('When drawn, pan map such that the entire popup is visible in the current viewport (if necessary).'),
'#default_value' => isset($defaults['panMapIfOutOfView']) ? $defaults['panMapIfOutOfView'] : FALSE
),
'keepInMap' => array(
'#type' => 'checkbox',
'#title' => t('Keep in map'),
'#description' => t('If panMapIfOutOfView is false, and this property is true, contrain the popup such that it always fits in the available map space.'),
'#default_value' => isset($defaults['keepInMap']) ? $defaults['keepInMap'] : TRUE
),
);
}
/**
* Render.
*/
function render(&$map) {
// Put weight on JS so that we know navigation is included already as this
// will affect touch devices.
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_popup.js', array('weight' => 10));
return $this->options;
}
}

View File

@@ -0,0 +1,95 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Javascript Drupal Theming function for inside of Popups
*
* To override
*
* @param feature
* OpenLayers feature object.
* @return
* Formatted HTML.
*/
Drupal.theme.prototype.openlayersPopup = function(feature) {
var output = '';
if (feature.attributes.name) {
output += '<div class="openlayers-popup openlayers-tooltip-name">' + feature.attributes.name + '</div>';
}
if (feature.attributes.description) {
output += '<div class="openlayers-popup openlayers-tooltip-description">' + feature.attributes.description + '</div>';
}
return output;
};
// Make sure the namespace exists
Drupal.openlayers.popup = Drupal.openlayers.popup || {};
/**
* OpenLayers Popup Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_popup', function (data, options) {
var map = data.openlayers;
var layers = [];
var selectedFeature;
// For backwards compatiability, if layers is not
// defined, then include all vector layers
if (typeof options.layers == 'undefined' || options.layers.length == 0) {
layers = map.getLayersByClass('OpenLayers.Layer.Vector');
}
else {
for (var i in options.layers) {
var selectedLayer = map.getLayersBy('drupalID', options.layers[i]);
if (typeof selectedLayer[0] != 'undefined') {
layers.push(selectedLayer[0]);
}
}
}
// if only 1 layer exists, do not add as an array. Kind of a
// hack, see https://drupal.org/node/1393460
if (layers.length == 1) {
layers = layers[0];
}
var popupSelect = new OpenLayers.Control.SelectFeature(layers,
{
onSelect: function(feature) {
// Create FramedCloud popup.
popup = new OpenLayers.Popup.FramedCloud(
'popup',
feature.geometry.getBounds().getCenterLonLat(),
null,
Drupal.theme('openlayersPopup', feature),
null,
true,
function(evt) {
Drupal.openlayers.popup.popupSelect.unselect(selectedFeature);
}
);
// Assign popup to feature and map.
popup.panMapIfOutOfView = options.panMapIfOutOfView;
popup.keepInMap = options.keepInMap;
selectedFeature = feature;
feature.popup = popup;
Drupal.attachBehaviors();
map.addPopup(popup);
},
onUnselect: function(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
);
map.addControl(popupSelect);
popupSelect.activate();
Drupal.openlayers.popup.popupSelect = popupSelect;
});

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_scaleline_openlayers_behaviors() {
return array(
'title' => t('Scale Line'),
'description' => t('Provides a line of scale in the map interface.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_scaleline.inc',
'class' => 'openlayers_behavior_scaleline',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Scaleline Behavior
*/
class openlayers_behavior_scaleline extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'scaleline' => '',
);
}
function js_dependency() {
return array('OpenLayers.Control.ScaleLine');
}
function options_form($defaults = array()) {
return array();
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_scaleline.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Scale Line Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_scaleline', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'ScaleLine');
});

View File

@@ -0,0 +1,70 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior for tooltips.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_tooltip_openlayers_behaviors() {
return array(
'title' => t('Tooltip for Features'),
'description' => t('Adds info boxes on hover to points or shapes on maps. This does not work with the Popup behavior due to limitation of event handling in the OpenLayers library.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_tooltip.inc',
'class' => 'openlayers_behavior_tooltip',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_tooltip extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'attribution' => '',
'layers' => array(),
);
}
/**
* Form defintion for per map customizations.
*/
function options_form($defaults = array()) {
// Only prompt for vector layers
$vector_layers = array();
foreach ($this->map['layers'] as $id => $name) {
$layer = openlayers_layer_load($id);
if (isset($layer->data['vector']) && $layer->data['vector'] == TRUE) {
$vector_layers[$id] = $name;
}
}
return array(
'layers' => array(
'#title' => t('Layers'),
'#type' => 'checkboxes',
'#options' => $vector_layers,
'#description' => t('Select layer to apply tooltips to.'),
'#default_value' => isset($defaults['layers']) ?
$defaults['layers'] : array(),
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_tooltip.js');
return $this->options;
}
}

View File

@@ -0,0 +1,93 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Javascript Drupal Theming function for inside of Tooltips
*
* To override
*
* @param feature
* OpenLayers feature object.
* @return
* Formatted HTML.
*/
Drupal.theme.prototype.openlayersTooltip = function(feature) {
var output = '';
if (feature.attributes.name) {
output += '<div class="openlayers-popup openlayers-tooltip-name">' + feature.attributes.name + '</div>';
}
if (feature.attributes.description) {
output += '<div class="openlayers-popup openlayers-tooltip-description">' + feature.attributes.description + '</div>';
}
return output;
};
/**
* OpenLayers Tooltip Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_tooltip', function (data, options) {
var map = data.openlayers;
var layers = [];
// For backwards compatiability, if layers is not
// defined, then include all vector layers
if (typeof options.layers == 'undefined' || options.layers.length == 0) {
layers = map.getLayersByClass('OpenLayers.Layer.Vector');
}
else {
for (var i in options.layers) {
var selectedLayer = map.getLayersBy('drupalID', options.layers[i]);
if (typeof selectedLayer[0] != 'undefined') {
layers.push(selectedLayer[0]);
}
}
}
// if only 1 layer exists, do not add as an array. Kind of a
// hack, see https://drupal.org/node/1393460
if (layers.length == 1) {
layers = layers[0];
}
// Define feature select events for selected layers.
var popupSelect = new OpenLayers.Control.SelectFeature(layers,
{
hover: true,
clickout: false,
multiple: false,
onSelect: function(feature) {
// Create FramedCloud popup for tooltip.
var output = Drupal.theme('openlayersTooltip', feature);
if (typeof output != 'undefined') {
popup = new OpenLayers.Popup.FramedCloud(
'tooltip',
feature.geometry.getBounds().getCenterLonLat(),
null,
output,
null,
true
);
feature.popup = popup;
feature.layer.map.addPopup(popup);
Drupal.attachBehaviors();
}
},
onUnselect: function(feature) {
// Remove popup.
if (typeof feature.popup != 'undefined') {
feature.layer.map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
}
);
// Actiate the popups
map.addControl(popupSelect);
popupSelect.activate();
});

View File

@@ -0,0 +1,59 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_touch_navigation_openlayers_behaviors() {
return array(
'title' => t('Touch Navigation'),
'description' => t('Provides specific navigation controls for touch enabled devices only. <strong>This is included with the Navigation behavior</strong>. Only enable this if you are targeting only touch enabled devices.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_touch_navigation.inc',
'class' => 'openlayers_behavior_touch_navigation',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Touch Navigation Behavior
*/
class openlayers_behavior_touch_navigation extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'documentDrag' => FALSE,
);
}
function js_dependency() {
return array('OpenLayers.Control.TouchNavigation');
}
function options_form($defaults = array()) {
return array(
'documentDrag' => array(
'#type' => 'checkbox',
'#title' => t('Document Drag'),
'#description' => t('Allow panning of the map by dragging outside map viewport.'),
'#default_value' => isset($defaults['documentDrag']) ? $defaults['documentDrag'] : FALSE
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_touch_navigation.js');
return $this->options;
}
}

View File

@@ -0,0 +1,12 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Touch Navigation Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_touch_navigation', function (data, options) {
options.documentDrag = !!options.documentDrag;
Drupal.openlayers.addControl(data.openlayers, 'TouchNavigation', options);
});

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_zoombox_openlayers_behaviors() {
return array(
'title' => t('Zoom Box Clicking'),
'description' => t('Provides a zoom box that can be drawn on SHIFT + click. Please note that by default the Navigation control behavior includes this, so there is no need to have both.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_zoombox.inc',
'class' => 'openlayers_behavior_zoombox',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Zoom Box Behavior
*/
class openlayers_behavior_zoombox extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'zoombox' => '',
);
}
function js_dependency() {
return array('OpenLayers.Control.ZoomBox');
}
function options_form($defaults = array()) {
return array();
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_zoombox.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Zoom Box Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_zoombox', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'ZoomBox');
});

View File

@@ -0,0 +1,50 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_zoompanel_openlayers_behaviors() {
return array(
'title' => t('Zoom Control'),
'description' => t('Provides a control that can Zoom In, Zoom Out, and Zoom to Max Extent Button. Do not use with Pan Zoom Bar Control or Pan Zoom Control.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_zoompanel.inc',
'class' => 'openlayers_behavior_zoompanel',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Zoom Panel Behavior
*/
class openlayers_behavior_zoompanel extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'panzoom' => '',
);
}
function js_dependency() {
return array(
'OpenLayers.Control.ZoomPanel'
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_zoompanel.js');
return $this->options;
}
}

View File

@@ -0,0 +1,11 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* ZoomPanel Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_zoompanel', function (data, options) {
Drupal.openlayers.addControl(data.openlayers, 'ZoomPanel');
});

View File

@@ -0,0 +1,70 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_zoomtolayer_openlayers_behaviors() {
return array(
'title' => t('Zoom to Layer'),
'description' => t('Zooms to the extent of a given layer(s) on map loading. If multiple layers are chosen, zooms to the extent that includes all chosen layers.'),
'type' => 'layer',
'behavior' => array(
'file' => 'openlayers_behavior_zoomtolayer.inc',
'class' => 'openlayers_behavior_zoomtolayer',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Attribution Behavior
*/
class openlayers_behavior_zoomtolayer extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'point_zoom_level' => '5',
'zoomtolayer_scale' => 1,
);
}
function options_form($defaults = array()) {
return array(
'zoomtolayer' => array(
'#type' => 'checkboxes',
'#options' => $this->map['layers'],
'#description' => t('Select layer(s) to which to zoom when the map is loaded.'),
'#default_value' => isset($defaults['zoomtolayer']) ? $defaults['zoomtolayer'] : array(),
),
'point_zoom_level' => array(
'#title' => t('Point Zoom Level'),
'#type' => 'textfield',
'#default_value' => (isset($defaults['point_zoom_level'])) ?
$defaults['point_zoom_level'] : 5,
'#size' => 5,
),
'zoomtolayer_scale' => array(
'#title' => t('Zoom to Layer Scale'),
'#type' => 'textfield',
'#size' => 5,
'#description' => t('Additional scaling to apply to the calculated bounds before zooming. See <a href="http://dev.openlayers.org/docs/files/OpenLayers/BaseTypes/Bounds-js.html#OpenLayers.Bounds.scale">OpenLayers docs</a>.'),
'#default_value' => isset($defaults['zoomtolayer_scale']) ? $defaults['zoomtolayer_scale'] : 1
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_zoomtolayer.js');
return $this->options;
}
}

View File

@@ -0,0 +1,62 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* OpenLayers Zoom to Layer Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_zoomtolayer', function (data, options) {
var map = data.openlayers;
var layers = map.getLayersBy('drupalID', {
test: function(id) {
for (var i in options.zoomtolayer) {
if (options.zoomtolayer[i] == id) {
return true;
}
}
return false;
}
});
// Go through selected layers to get full extent.
map.fullExtent = new OpenLayers.Bounds();
for (var i in layers) {
if (layers[i].features !== undefined) {
var zoomtolayer_scale = data.map.behaviors['openlayers_behavior_zoomtolayer'].zoomtolayer_scale;
// For KML layers, we need to wait until layer is loaded. Ideally
// we could check for any layer that is loading from an external
// source, but for now, just check KML
if (layers[i].layer_handler == 'kml') {
layers[i].events.register('loadend', layers[i], function() {
layerextent = layers[i].getDataExtent().scale(zoomtolayer_scale);
map.fullExtent.extend(layerextent);
map.zoomToExtent(map.fullExtent);
// If unable to find width due to single point,
// zoom in with point_zoom_level option.
if (layerextent.getWidth() == 0.0) {
map.zoomTo(options.point_zoom_level);
}
});
}
else {
layerextent = layers[i].getDataExtent();
// Check for valid layer extent
if (layerextent != null) {
map.fullExtent.extend(layerextent);
map.zoomToExtent(map.fullExtent);
}
}
}
}
// If unable to find width due to single point,
// zoom in with point_zoom_level option.
if (map.fullExtent.getWidth() == 0.0) {
map.zoomTo(options.point_zoom_level);
}
else {
map.zoomToExtent(map.fullExtent.scale(zoomtolayer_scale));
}
});

View File

@@ -0,0 +1,44 @@
<?php
/**
* @file
* Implementation of OpenLayers behavior.
*/
/**
* Ctools plugin definition.
*/
function openlayers_openlayers_behavior_zoomtomaxextent_openlayers_behaviors() {
return array(
'title' => t('Zoom to Max Extent'),
'description' => t('Provides button to zoom to the maximum extent of the map.'),
'type' => 'map',
'behavior' => array(
'file' => 'openlayers_behavior_zoomtomaxextent.inc',
'class' => 'openlayers_behavior_zoomtomaxextent',
'parent' => 'openlayers_behavior',
),
);
}
/**
* Zoom to Max Extent Behavior
*/
class openlayers_behavior_zoomtomaxextent extends openlayers_behavior {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'zoomtomaxextent' => '',
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/behaviors/openlayers_behavior_zoomtomaxextent.js');
return $this->options;
}
}

View File

@@ -0,0 +1,15 @@
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
/**
* Zoom Max Extent Behavior
*/
Drupal.openlayers.addBehavior('openlayers_behavior_zoomtomaxextent', function (data, options) {
options.allowSelection = options.allowSelection || true;
var panel = Drupal.openlayers.addControl(data.openlayers, 'Panel', options);
var button = new OpenLayers.Control.ZoomToMaxExtent();
panel.addControls([button]);
});

View File

@@ -0,0 +1,92 @@
<?php
/**
* @file
*
* OpenLayers Bing layer type
*/
/**
* Define the Ctools plugin options.
*/
$plugin = array(
'title' => t('Bing'),
'description' => t('Microsoft Bing'),
'layer_type' => array(
'file' => 'openlayers_layer_type_bing.inc',
'class' => 'openlayers_layer_type_bing',
'parent' => 'openlayers_layer_type',
),
);
/**
* OpenLayers Bing Layer Type class
*/
class openlayers_layer_type_bing extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'bing',
'key' => variable_get('openlayers_layers_bing_api', ''),
'type' => 'Road',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
$warning = (!variable_get('openlayers_layers_bing_api', FALSE)) ?
array('#value' => t('WARNING: Your Bing API key is not set.
Map including Bing layers will break until it is set correctly.')
) : NULL;
$bing_layer_types = array(
'Road' => 'Road',
'AerialWithLabels' => 'Hybrid',
'Aerial' => 'Aerial',
);
return array(
'type' => array(
'#title' => t('Bing Layer Type'),
'#type' => 'select',
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : 'Road',
'#options' => $bing_layer_types
),
$warning
);
}
/**
* Layer-type-wide settings form
*/
function settings_form() {
return array(
'openlayers_layers_bing_api' => array(
'#type' => 'textfield',
'#title' => t('Bing API Key'),
'#default_value' => variable_get('openlayers_layers_bing_api', ''),
'#description' => t('<a href="@microsoft">Get a MS Bing API Key</a>',
array('@microsoft' => 'http://bingmapsportal.com'))
)
);
}
/**
* Render.
*/
function render(&$map) {
static $bing_maps_included;
if (!isset($bing_maps_included)) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_bing.js');
$bing_maps_included = TRUE;
}
}
}

View File

@@ -0,0 +1,22 @@
/**
* Process MS Bing Layers
*
* @param layerOptions
* Object of options.
* @param mapid
* Map ID.
* @return
* Valid OpenLayers layer.
*/
Drupal.openlayers.layer.bing = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
options.sphericalMercator = true;
options.projection = "EPSG:900913";
options.maxExtent = new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34);
var layer = new OpenLayers.Layer.Bing(options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,107 @@
<?php
/**
* @file
*
* OpenLayers CloudMade layer type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_cloudmade_openlayers_layer_types() {
return array(
'title' => t('CloudMade'),
'description' => t('<a href="!url">CloudMade</a> Custom Map',
array('!url' => 'http://cloudmade.com/')),
'layer_type' => array(
'file' => 'openlayers_layer_type_cloudmade.inc',
'class' => 'openlayers_layer_type_cloudmade',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers CloudMade Layer Type class
*/
class openlayers_layer_type_cloudmade extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'cloudmade',
'key' => variable_get('openlayers_layers_cloudmade_api', ''),
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
$warning = (!variable_get('openlayers_layers_cloudmade_js', FALSE) ||
!variable_get('openlayers_layers_cloudmade_api', FALSE)) ?
array(
'#value' => t('WARNING: Your CloudMade API key or
Javascript location is not set. Map including CloudMade layers
will break until they are set correctly.')
)
: NULL;
return array(
'styleId' => array(
'#type' => 'textfield',
'#title' => t('Style ID'),
'#description' => t('Enter the numeric Style ID for a <a href="http://maps.cloudmade.com/editor">Map Style</a> from CloudMade. You can usually find the Style ID in the lower right hand corner of each Map Style box.'),
'#default_value' => isset($this->data['styleId']) ?
$this->data['styleId'] : ''
),
$warning
);
}
/**
* Layer-type-wide settings form
*/
function settings_form() {
return array(
'openlayers_layers_cloudmade_api' => array(
'#type' => 'textfield',
'#title' => t('CloudMade API Key'),
'#default_value' => variable_get('openlayers_layers_cloudmade_api', ''),
'#description' => t('<a href="@cloudmade">Get a CloudMade account and API Key</a>',
array('@cloudmade' => 'http://cloudmade.com/user/show'))
),
'openlayers_layers_cloudmade_js' => array(
'#type' => 'textfield',
'#title' => t('CloudMade Javascript Location'),
'#default_value' => variable_get('openlayers_layers_cloudmade_js', ''),
'#description' => t('The Drupal path or full URL to the location of the ' .
'<a href="@url">Cloudmade OpenLayers Javascript library</a>',
array('@url' => 'http://developers.cloudmade.com/projects/show/openlayers-api')),
),
);
}
/**
* Render.
*/
function render(&$map) {
static $cloudmade_maps_included;
if (!isset($cloudmade_maps_included)) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_cloudmade.js');
$path = variable_get('openlayers_layers_cloudmade_js', '');
if (valid_url($path, TRUE)) {
// TODO: could be collapsed, removing the if-else
drupal_add_js($path, 'external');
}
else {
drupal_add_js($path);
}
$cloudmade_maps_included = TRUE;
}
}
}

View File

@@ -0,0 +1,22 @@
/**
* Process CloudMade Layers
*
* @param layerOptions
* Object of options.
* @param map
* Reference to OpenLayers object.
* @return
* Valid OpenLayers layer.
*/
Drupal.openlayers.layer.cloudmade = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
// options.sphericalMercator = true;
options.maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
options.projection = 'EPSG:' + options.projection;
var layer = new OpenLayers.Layer.CloudMade(title, options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,101 @@
<?php
/**
* @file
* GeoJSON Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_geojson_openlayers_layer_types() {
return array(
'title' => t('GeoJSON'),
'description' => t('Provides a vector layer based on <a href="!url">GeoJSON</a>.',
array('!url' => 'http://geojson.org/')),
'layer_type' => array(
'file' => 'openlayers_layer_type_geojson.inc',
'class' => 'openlayers_layer_type_geojson',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers GeoJSON Layer Type class
*/
class openlayers_layer_type_geojson extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'geojson',
'projection' => array('4326'),
'serverResolutions' => openlayers_get_resolutions('4326'),
'isBaseLayer' => FALSE,
'vector' => TRUE,
'geojson_data' => '',
'useBBOX' => FALSE,
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'url' => array(
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('The URL of the GeoJSON file. This can be a Drupal path as well, as it will get run through the Drupal <a href="!url">url()</a> function.',
array('!url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url')),
'#maxlength' => 1024,
'#default_value' => isset($this->data['url']) ? $this->data['url'] : '',
),
'useBBOX' => array(
'#type' => 'checkbox',
'#title' => t('Use Bounding Box Strategy'),
'#description' => t('Bounding Box strategy will add a query string onto the GeoJSON URL, which means that only data in the viewport of the map will be loaded. This can be helpful if you have lots of data coming from the feed.'),
'#default_value' => isset($this->data['useBBOX']) ? $this->data['useBBOX'] : FALSE,
),
//see http://dev.openlayers.org/docs/files/OpenLayers/Strategy/BBOX-js.html#OpenLayers.Strategy.BBOX.resFactor
'resFactor' => array(
'#type' => 'textfield',
'#title' => t('Bounding Box resFactor'),
'#description' => t('Used to determine when previously requested features are invalid (set to 1 if unsure).
The resFactor will be compared to the resolution of the previous request to the current map resolution.<br />
If resFactor > (old / new) and 1/resFactor < (old / new).
<ul>
<li>If you set a resFactor of 1, data will be requested every time the resolution changes.</li>
<li>If you set a resFactor of 3, data will be requested if the old resolution is 3 times the new, or if the new is 3 times the old.</li>
<li>If the old bounds do not contain the new bounds new data will always be requested (with or without considering resFactor).</li>
</ul>
'),
'#default_value' => isset($this->data['resFactor']) ? $this->data['resFactor'] : 1
),
'geojson_data' => array(
'#type' => 'textarea',
'#title' => t('GeoJSON Data'),
'#description' => t('Paste raw GeoJSON data here. It is better to use a URL. This is provided for very simple use cases like one or two features. If there is data here, it will override the URL above.'),
'#default_value' => isset($this->data['geojson_data']) ? $this->data['geojson_data'] : '',
),
);
}
/**
* Render.
*/
function render(&$map) {
if (isset($map['views_arguments'])) {
foreach ((array) $map['views_arguments'] as $name => $value) {
$this->data['url'] = str_replace("[{$name}]", $value, $this->data['url']);
}
}
$this->data['url'] = !empty($this->data['url']) ? url($this->data['url']) : '';
drupal_add_js(drupal_get_path('module', 'openlayers')
. '/plugins/layer_types/openlayers_layer_type_geojson.js');
}
}

View File

@@ -0,0 +1,66 @@
/**
* @file
* Layer handler for GeoJSON layers
*/
/**
* Openlayer layer handler for KML layer
*/
(function($) {
Drupal.openlayers.layer.geojson = function(title, map, options) {
var features = null;
options.projection = 'EPSG:' + options.projection;
options.styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
// GeoJSON Projection handling
var geojson_options = {
'internalProjection': new OpenLayers.Projection('EPSG:' + map.projection),
'externalProjection': new OpenLayers.Projection(options.projection)
};
// If GeoJSON data is provided with the layer, use that. Otherwise
// check if BBOX, then finally use AJAX method.
if (options.geojson_data) {
var layer = new OpenLayers.Layer.Vector(title, options);
// Read data in.
features = new OpenLayers.Format.GeoJSON(geojson_options).read(options.geojson_data);
if (features) {
// If not array (ie only one feature)
if (features.constructor != Array) {
features = [features];
}
}
// Add features, if needed
if (features) {
layer.addFeatures(features);
layer.events.triggerEvent('loadend');
}
}
else {
// @todo Add more strategies. Paging strategy would be really interesting
// to use with views_geojson.
// @see http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Strategy/Paging-js.html
if (options.useBBOX) {
// BBOX strategy.
// @see http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Strategy/BBOX-js.html
options.strategies = [ new OpenLayers.Strategy.BBOX(options.resFactor) ];
}
else {
// Fixed strategy.
// @see http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Strategy/Fixed-js.html
options.strategies = [new OpenLayers.Strategy.Fixed()];
}
options.protocol = new OpenLayers.Protocol.HTTP({
url: options.url,
format: new OpenLayers.Format.GeoJSON()
});
var layer = new OpenLayers.Layer.Vector(title, options);
}
return layer;
};
})(jQuery);

View File

@@ -0,0 +1,157 @@
<?php
/**
* @file
* Google Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_google_openlayers_layer_types() {
return array(
'title' => t('Google'),
'description' => t('Google Maps API Map'),
'layer_type' => array(
'file' => 'openlayers_layer_type_google.inc',
'class' => 'openlayers_layer_type_google',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers Google Layer Type class
*/
class openlayers_layer_type_google extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'google',
'animationEnabled' => TRUE,
'sphericalMercator' => TRUE,
'numZoomLevels' => 21
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
$google_layer_types = array(
'hybrid' => 'Hybrid',
'normal' => 'Normal',
'satellite' => 'Satellite',
'physical' => 'Physical',
);
return array(
'type' => array(
'#title' => t('Google Layer Type'),
'#type' => 'select',
'#default_value' => isset($this->data['type']) ? $this->data['type'] : 'normal',
'#options' => $google_layer_types
),
'numZoomLevels' => array(
'#type' => 'textfield',
'#title' => t('Number of Zoom Levels'),
'#description' => t('Satellite and hybrid maps are occasionally
unavailable at higher zoom levels.'),
'#default_value' => isset($this->data['numZoomLevels']) ?
$this->data['numZoomLevels'] : '21'
),
'animationEnabled' => array(
'#type' => 'checkbox',
'#title' => t('Animation Enabled'),
'#description' => t('This enables the Google Maps API zooming animation.
If you are having issues with your Google layer, it may be helpful
to turn this off.'),
'#default_value' => isset($this->data['animationEnabled']) ?
$this->data['animationEnabled'] : TRUE
),
);
}
/**
* Layer-type-wide settings form
*/
function settings_form() {
return array(
'openlayers_google_version' => array(
'#type' => 'select',
'#title' => t('Google Maps API version'),
'#description' => t('If you use Google Maps v3, an API key is not necessary.'),
'#options' => array(
'2' => t('v2'),
'3.5' => t('v3.5'),
),
'#default_value' => variable_get('openlayers_google_version', '3.5'),
),
'openlayers_layers_google_mapdomain' => array(
'#type' => 'select',
'#options' => array(
'maps.google.com' => 'maps.google.com',
'maps.googleapis.com' => 'maps.googleapis.com',
),
'#title' => t('Google map default domain'),
'#default_value' => variable_get('openlayers_layers_google_mapdomain', 'maps.google.com'),
'#description' => t('Select the Google Map default domain. maps.googleapis.com is cookie-free.')
),
'openlayers_layers_google_api' => array(
'#type' => 'textfield',
'#title' => t('Google API Key'),
'#default_value' => variable_get('openlayers_layers_google_api', ''),
'#description' => t('<a href="@google">Obtain an API key from Google for your domain</a>',
array('@google' => 'http://code.google.com/apis/maps/signup.html'))
),
'openlayers_layers_google_language' => array(
'#type' => 'textfield',
'#title' => t('Language'),
'#description' => t('This will set the language used
for the interface (like attribution) as well as tiles,
as supported by Google. By default, Google Map API will
determine the language automatically. Only use this is you
want to force a specific language. Please see
<a href="!url">this list of languages</a>.',
array('!url' => 'http://sites.google.com/site/tomihasa/google-language-codes')
),
'#default_value' => variable_get('openlayers_layers_google_language', ''),
),
);
}
/**
* Render.
*/
function render(&$map) {
static $google_maps_included;
if (!isset($google_maps_included)) {
// Include files.
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_google.js');
$mapdomain = variable_get('openlayers_layers_google_mapdomain', 'maps.google.com');
$version = variable_get('openlayers_google_version', '3.5');
if ($version == '2') {
// Create URL for google include
$url = '//' . $mapdomain . '/maps?file=api&sensor=false&v=' . $version;
$key = variable_get('openlayers_layers_google_api', variable_get('googlemap_api_key', ''));
$url .= !empty($key) ? '&key=' . $key : '';
}
else {
// Create URL for google include
$url = '//' . $mapdomain . '/maps/api/js?sensor=false&v=' . $version;
}
$lang = variable_get('openlayers_layers_google_language', '');
// Google v2 uses hl and v3 uses language
$url .= !empty($lang) ? '&hl=' . $lang : '';
$url .= !empty($lang) ? '&language=' . $lang : '';
drupal_add_js($url, 'external');
$google_maps_included = TRUE;
}
}
}

View File

@@ -0,0 +1,30 @@
/**
* Process Google Layers
*
* @param layerOptions
* Object of options.
* @param map
* Reference to OpenLayers object.
* @return
* Valid OpenLayers layer.
*/
Drupal.openlayers.layer.google = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
// if G_ vars exists we're using gmap v2
var google_type_map = {
'normal': window['G_NORMAL_MAP'] || null,
'satellite': window['G_SATELLITE_MAP'] || google.maps.MapTypeId.SATELLITE,
'hybrid': window['G_HYBRID_MAP'] || google.maps.MapTypeId.HYBRID,
'physical': window['G_PHYSICAL_MAP'] || google.maps.MapTypeId.TERRAIN
};
options.maxExtent = new OpenLayers.Bounds(options.maxExtent);
options.type = google_type_map[options.type];
options.projection = "EPSG:900913";
var layer = new OpenLayers.Layer.Google(title, options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,175 @@
<?php
/**
* @file
* KML Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_kml_openlayers_layer_types() {
return array(
'title' => t('KML'),
'description' => t('<a href="!url">KML</a> overlay.',
array('!url' => 'http://en.wikipedia.org/wiki/Keyhole_Markup_Language')),
'layer_type' => array(
'file' => 'openlayers_layer_type_kml.inc',
'class' => 'openlayers_layer_type_kml',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers KML Layer Type class
*/
class openlayers_layer_type_kml extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'kml',
'projection' => array('4326'),
'resolutions' => openlayers_get_resolutions('4326'),
'serverResolutions' => openlayers_get_resolutions('4326'),
'maxExtent' => openlayers_get_extent('4326'),
'isBaseLayer' => FALSE,
'vector' => TRUE,
'formatOptions' => array(
'extractStyles' => TRUE,
'extractAttributes' => TRUE,
'extractTracks' => FALSE,
),
'file' =>'',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'method' => array(
'#type' => 'select',
'#options' => array(
'' => 'Choose the method',
'url' => 'Provides an URL',
'file' => 'Upload a file',
'raw' => 'Write KML'
),
'#default_value' => isset($this->data['method']) ?
$this->data['method'] : '',
),
'url' => array(
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('The URL of the KML file.'),
'#maxlength' => 2083,
'#default_value' => isset($this->data['url']) ?
$this->data['url'] : '',
'#states' => array(
'visible' => array(
':input[name="openlayers_layer_type_kml[method]"]' => array('value' => 'url'),
)
)
),
'file' => array(
'#name' => 'files[imagelayer]',
'#type' => 'managed_file',
'#title' => t('KML file'),
'#default_value' => isset($this->data['file']) ? $this->data['file'] : '',
'#upload_location' => 'public://',
'#upload_validators' => array(
'file_validate_extensions' => array('kml')
),
'#states' => array(
'visible' => array(
':input[name="openlayers_layer_type_kml[method]"]' => array('value' => 'file'),
)
)
),
'raw' => array(
'#type' => 'textarea',
'#title' => t('Raw KML'),
'#description' => t('Copy your KML in this textarea. Don\'t forget that this is not intented to have a big length.'),
'#default_value' => isset($this->data['raw']) ?
$this->data['raw'] : '',
'#states' => array(
'visible' => array(
':input[name="openlayers_layer_type_kml[method]"]' => array('value' => 'raw'),
)
)
),
'formatOptions' => array(
'extractStyles' => array(
'#type' => 'checkbox',
'#title' => t('Extract Styles'),
'#description' => t('Extract styles from KML.'),
'#default_value' => isset(
$this->data['formatOptions']['extractStyles']) ?
$this->data['formatOptions']['extractStyles'] : TRUE,
),
'extractTracks' => array(
'#type' => 'checkbox',
'#title' => t('Extract Tracks'),
'#description' => t('Extract tracks from KML.'),
'#default_value' => isset(
$this->data['formatOptions']['extractTracks']) ?
$this->data['formatOptions']['extractTracks'] : TRUE,
),
'extractAttributes' => array(
'#type' => 'checkbox',
'#title' => t('Extract Attributes'),
'#description' => t('Extract attributes from KML.'),
'#default_value' => isset(
$this->data['formatOptions']['extractAttributes']) ?
$this->data['formatOptions']['extractAttributes'] : TRUE,
),
),
);
}
/*
* The file is mandatory.
*/
function options_form_validate($form, &$form_state) {
$method = $form_state['data']['method'];
if (empty($form_state['data'][$method])) {
form_set_error($form_state['data']['layer_type'].']['.$method, 'The field cannot be empty');
}
if ($method == 'file') {
if ($file = file_load($form_state['data']['file'])) {
$form_state['data']['url'] = file_create_url($file->uri);
} else {
form_set_error($form_state['data']['layer_type'].']['.$method, 'Cannot access the file.');
}
}
$form_state['data']['projection'] = array_values($form_state['data']['projection']);
$form_state['data']['formatOptions']['extractStyles'] = $form_state['data']['formatOptions']['extractStyles']!=0?TRUE:FALSE;
$form_state['data']['formatOptions']['extractAttributes'] = $form_state['data']['formatOptions']['extractAttributes']!=0?TRUE:FALSE;
$form_state['data']['formatOptions']['extractTracks'] = $form_state['data']['formatOptions']['extractTracks']!=0?TRUE:FALSE;
}
/*
* What to do when we delete the layer: delete the file.
*/
function delete($item) {
if (is_numeric($item->data['file']) && $item->data['file'] > 0) {
$file = file_load($item->data['file']);
file_delete($file);
}
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers')
. '/plugins/layer_types/openlayers_layer_type_kml.js');
}
}

View File

@@ -0,0 +1,49 @@
/**
* @file
* Layer handler for KML layers
*/
/**
* Openlayer layer handler for KML layer
*/
Drupal.openlayers.layer.kml = function(title, map, options) {
var layer = new OpenLayers.Layer.Vector(title, {
name: options.name,
drupalID: options.drupalID,
layer_handler: options.layer_handler,
styleMap: Drupal.openlayers.getStyleMap(map, options.drupalID)
});
// KML Projection handling and formating options
var kml_options = options.formatOptions;
kml_options.internalProjection = new OpenLayers.Projection('EPSG:' + map.projection);
kml_options.externalProjection = new OpenLayers.Projection('EPSG:' + options.projection);
if (options.method == 'file' || options.method == 'url') {
var uri = options.url;
// Use an AJAX like call to get data from URL
OpenLayers.Request.GET({
url: uri,
callback: function (response) {
addFeatures(response.responseText, kml_options);
}
});
}
if (options.method == 'raw') {
addFeatures(options.raw, kml_options);
}
function addFeatures(kml, options) {
var format = new OpenLayers.Format.KML(options);
var features = format.read(kml);
// Add features, if needed
if (features) {
layer.addFeatures(features);
layer.events.triggerEvent('loadend');
}
}
return layer;
};

View File

@@ -0,0 +1,98 @@
<?php
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_mapbox_openlayers_layer_types() {
return array(
'title' => t('MapBox'),
'description' => t('<a href="!url">MapBox</a> Custom Map',
array('!url' => 'http://mapbox.com/')),
'layer_type' => array(
'file' => 'openlayers_layer_type_mapbox.inc',
'class' => 'openlayers_layer_type_mapbox',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* @file MapBox layer type definition for OpenLayers
*/
class openlayers_layer_type_mapbox extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'url' => array(
'http://a.tiles.mapbox.com/mapbox/',
'http://b.tiles.mapbox.com/mapbox/',
'http://c.tiles.mapbox.com/mapbox/',
'http://d.tiles.mapbox.com/mapbox/',
),
'osm' => FALSE,
'layername' => '',
'layer_handler' => 'MapBox',
'type' => 'png',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'url' => array(
'#type' => 'textarea',
'#title' => t('Base URLs'),
'#description' => t('The list of base URLs specified on !tiles (with trailing "/"). For details, visit the !support site.', array(
'!tiles' => l(t('TileStream'), 'http://tiles.mapbox.com/'),
'!support' => l(t('MapBox Support'), 'http://support.mapbox.com/kb/tilestream/using-tilestream-with-drupal'),
)),
'#default_value' => !empty($this->data['url']) ? implode("\n", $this->data['url']) : '',
),
'layername' => array(
'#type' => 'textfield',
'#title' => t('MapBox Layer Name'),
'#description' => t('The layer name specified on !tiles.', array(
'!tiles' => l(t('TileStream'), 'http://tiles.mapbox.com/'),
)),
'#default_value' => $this->data['layername']
),
'osm' => array(
'#type' => 'checkbox',
'#default_value' => $this->data['osm'],
'#title' => t('OSM Attribution'),
'#description' => t('Required if OpenStreetMap data is used.'),
),
'type' => array(
'#title' => t('File extension'),
'#type' => 'select',
'#default_value' => $this->data['type'],
'#options' => drupal_map_assoc(array('png', 'jpg')),
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array_combine(array_map('strval', openlayers_get_resolutions('900913')), range(0, 21)),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['resolutions']) ? array_map('strval', $this->data['resolutions']) : array(),
),
);
}
function options_form_validate($form, &$form_state) {
$form_state['data']['url'] = explode("\n", $form_state['data']['url']);
$form_state['data']['resolutions'] = array_map('floatval', array_values($form_state['data']['resolutions']));
$form_state['data']['projection'] = array_values($form_state['data']['projection']);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') . '/plugins/layer_types/openlayers_layer_type_mapbox.js');
}
}

View File

@@ -0,0 +1,62 @@
if (Drupal.openlayers === undefined) {
Drupal.openlayers = {};
}
Drupal.openlayers.layer = Drupal.openlayers.layer || {};
OpenLayers.Layer.MapBox = OpenLayers.Class(OpenLayers.Layer.TMS, {
/*
* Do not remove the MapBox or OpenLayers attribution from this code,
* doing so is in violation of the terms of both licenses.
*/
initialize: function (name, options) {
var newArguments, // Arguments which will be automatically
// sent to the Layer.TMS constructor
url; // Multiple server URLs with the same contents
// but distributed for performance
mapbox_logo = "<a class='mapbox-branding' href='http://mapbox.com'></a> | <a href='http://mapbox.com/tos'>Terms of Service</a>";
options = OpenLayers.Util.extend({
attribution: mapbox_logo,
maxExtent: new OpenLayers.Bounds(
-20037508, -20037508, 20037508, 20037508),
maxResolution: 156543.0339,
units: "m",
type: "png",
projection: "EPSG:900913",
isBaseLayer: true,
numZoomLevels: 19,
displayOutsideMaxExtent: false,
wrapDateLine: true,
buffer: 0
}, options);
url = (options.url) ? options.url : [
"http://a.tiles.mapbox.com/",
"http://b.tiles.mapbox.com/",
"http://c.tiles.mapbox.com/",
"http://d.tiles.mapbox.com/"
];
if (options.osm) {
options.attribution = "<a class='mapbox-branding' href='http://mapbox.com'></a> | <a href='http://mapbox.com/tos'>Terms of Service</a> | Data CCBYSA OSM"
}
newArguments = [name, url, options];
OpenLayers.Layer.TMS.prototype.initialize.apply(this, newArguments);
},
CLASS_NAME: "OpenLayers.Layer.MapBox"
});
/**
* For OpenLayers 0.x and 2.x
*/
Drupal.openlayers.layer.MapBox = function (name, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.name);
if (options.maxExtent !== undefined) {
options.maxExtent = new OpenLayers.Bounds.fromArray(options.maxExtent);
}
if (options.type === undefined){
options.type = "png";
}
options.projection = new OpenLayers.Projection('EPSG:'+options.projection);
var layer = new OpenLayers.Layer.MapBox(name, options);
layer.styleMap = styleMap;
return layer;
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @file
* TileWarper Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_maptiler_openlayers_layer_types() {
return array(
'title' => t('MapTiler'),
'description' => t('<a href="!url">MapTiler</a> or GDAL2Tiles',
array('!url' => 'http://www.maptiler.org/')),
'layer_type' => array(
'file' => 'openlayers_layer_type_maptiler.inc',
'class' => 'openlayers_layer_type_maptiler',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers MapTiler Layer Type class
*/
class openlayers_layer_type_maptiler extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'type' => 'png',
'layer_handler' => 'maptiler',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'base_url' => array(
'#type' => 'textfield',
'#title' => t('Base URL'),
'#default_value' => isset($this->data['base_url']) ?
$this->data['base_url'] : ''
),
'type' => array(
'#type' => 'select',
'#options' => array(
'jpg' => 'JPG',
'png' => 'PNG'
),
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : 'png'
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)
),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['resolutions']) ?
$this->data['resolutions'] :
array_map('strval', openlayers_get_resolutions('900913'))
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_maptiler.js');
}
}

View File

@@ -0,0 +1,24 @@
/**
* @file
* Layer handler for TMS layers
*/
/**
* Openlayer layer handler for TMS layer
*/
Drupal.openlayers.layer.maptiler = function(title, map, options) {
if (options.maxExtent !== undefined) {
options.maxExtent = new OpenLayers.Bounds.fromArray(options.maxExtent);
}
options.getURL = function(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
var z = this.map.getZoom();
return this.url + z + '/' + x + '/' + y + '.' + this.type;
}
options.projection = 'EPSG:' + options.projection;
var layer = new OpenLayers.Layer.TMS(title, options.base_url, options);
return layer;
};

View File

@@ -0,0 +1,79 @@
<?php
/**
* @file
* OSM Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_osm_openlayers_layer_types() {
return array(
'title' => t('OSM'),
'description' => t('OpenStreetMap Standard'),
'layer_type' => array(
'file' => 'openlayers_layer_type_osm.inc',
'class' => 'openlayers_layer_type_osm',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers OSM Layer Type class
*/
class openlayers_layer_type_osm extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'xyz',
'type' => 'png',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'base_url' => array(
'#type' => 'textfield',
'#title' => t('Base URL'),
'#default_value' => isset($this->data['base_url']) ?
$this->data['base_url'] : ''
),
'type' => array(
'#type' => 'select',
'#title' => t('File Format'),
'#options' => array(
'png' => 'png',
'jpg' => 'jpg'),
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : 'png'
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['resolutions']) ?
$this->data['resolutions'] :
array_map('strval', openlayers_get_resolutions('900913'))
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_osm.js');
}
}

View File

@@ -0,0 +1,19 @@
/**
* @file
* Layer handler for OSM layers
*/
/**
* Openlayer layer handler for OSM layer
*/
Drupal.openlayers.layer.osm = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
if (options.maxExtent !== undefined) {
options.maxExtent = new OpenLayers.Bounds.fromArray(options.maxExtent);
}
options.projection = 'EPSG:' + options.projection;
var layer = new OpenLayers.Layer.OSM(title, options.base_url, options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,57 @@
<?php
/**
* @file
* Raw Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_raw_openlayers_layer_types() {
return array(
'title' => t('Raw'),
'description' => t('Layer type for raw data input -
not meant to be added with the UI.'
),
'layer_type' => array(
'file' => 'openlayers_layer_type_raw.inc',
'class' => 'openlayers_layer_type_raw',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* @file
* OpenLayers Raw Layer Type
*/
class openlayers_layer_type_raw extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'openlayers_raw',
'vector' => TRUE,
'isBaseLayer' => FALSE,
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array();
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_raw.js');
// $features = ;
// $this->data['features'] = $features;
}
}

View File

@@ -0,0 +1,21 @@
/**
* OpenLayers Raw Layer Handler
*/
Drupal.openlayers.layer.openlayers_raw = function(title, map, options) {
options.options = options.options || {};
// Note, so that we do not pass all the features along to the Layer
// options, we use the options.options to give to Layer
options.options.drupalID = options.drupalID;
options.options.styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
var layer = new OpenLayers.Layer.Vector(title, options.options);
if (options.features) {
Drupal.openlayers.addFeatures(map, layer, options.features);
}
return layer;
};

View File

@@ -0,0 +1,97 @@
<?php
/**
* @file
* TMS Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_tms_openlayers_layer_types() {
return array(
'title' => t('TMS'),
'description' => t('<a href="!url">Tile Map Service</a>',
array('!url' => 'http://en.wikipedia.org/wiki/Tile_Map_Service')),
'layer_type' => array(
'file' => 'openlayers_layer_type_tms.inc',
'class' => 'openlayers_layer_type_tms',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers TMS Layer Type class
*/
class openlayers_layer_type_tms extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'tms',
'type' => 'png',
'wrapDateLine' => false,
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'base_url' => array(
'#type' => 'textfield',
'#title' => t('Base URL'),
'#default_value' => isset($this->data['base_url']) ?
$this->data['base_url'] : '',
'#description' => t('This is the base URL of the TMS service. For example, if this was your tile scheme URL: http://example.com/tms/1.0.0/layer_name/{z}/{y}/{x}.png, then <em>http://example.com/tms/</em> would be the Base URL.'),
),
'layername' => array(
'#type' => 'textfield',
'#title' => t('Layer Name'),
'#default_value' => isset($this->data['layername']) ?
$this->data['layername'] : '',
'#description' => t('This is the base URL of the TMS service. For example, if this was your tile scheme URL: http://example.com/tms/1.0.0/layer_name/{z}/{y}/{x}.png, then <em>layer_name</em> would be the Layer Name.'),
),
'type' => array(
'#type' => 'select',
'#title' => t('File Format'),
'#options' => array(
'png' => 'png',
'jpg' => 'jpg'),
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : 'png'
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)
),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['resolutions']) ?
$this->data['resolutions'] :
array_map('strval', openlayers_get_resolutions('900913')),
'#description' => t('The available zoom levels for the tiles.'),
),
'wrapDateLine' => array(
'#type' => 'checkbox',
'#title' => t('Wrap Dateline'),
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : False,
'#description' => t('Wrapping the dateline will cause the map to appear to repeat itself when going east or west. This may not be supported by all tilesets.'),
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_tms.js');
}
}

View File

@@ -0,0 +1,19 @@
/**
* @file
* Layer handler for TMS layers
*/
/**
* Openlayer layer handler for TMS layer
*/
Drupal.openlayers.layer.tms = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
if (options.maxExtent !== undefined) {
options.maxExtent = new OpenLayers.Bounds.fromArray(options.maxExtent);
}
options.projection = 'EPSG:' + options.projection;
var layer = new OpenLayers.Layer.TMS(title, options.base_url, options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,138 @@
<?php
/**
* @file
* WMS Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_wms_openlayers_layer_types() {
return array(
'title' => t('WMS'),
'description' => t('<a href="!url">Web Map Service</a>',
array('!url' => 'http://en.wikipedia.org/wiki/Web_Map_Service')),
'layer_type' => array(
'file' => 'openlayers_layer_type_wms.inc',
'class' => 'openlayers_layer_type_wms',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers WMS Layer Type class
*/
class openlayers_layer_type_wms extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'wms',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'base_url' => array(
'#type' => 'textfield',
'#title' => t('Base URL'),
'#maxlength' => 2083,
'#default_value' => isset($this->data['base_url']) ?
$this->data['base_url'] : ''
),
// TODO: swap terms
'params' => array(
// TODO: validate the field, only positive integers shall be allowed
'buffer' => array(
'#type' => 'textfield',
'#default_value' => isset($this->data['params']['buffer']) ?
$this->data['params']['buffer'] : 2,
'#title' => t('Buffer'),
'#description' => t('Used only when not in single-tile mode, this specifies umber of extra rows and colums of tiles on each side which will surround the minimum grid tiles to cover the map')
),
// TODO: validate the field, only positive numbers shall be allowed
// numbers below 1 might also not make much sense
'ratio' => array(
'#type' => 'textfield',
'#default_value' => isset($this->data['params']['ratio']) ?
$this->data['params']['ratio'] : 1.5,
'#title' => t('Ratio'),
'#description' => t('Used only when in single-tile mode, this specifies the ratio of the size of the single tile to the size of the map')
),
'singleTile' => array(
'#type' => 'checkbox',
'#default_value' => isset($this->data['params']['singleTile']) ?
$this->data['params']['singleTile'] : FALSE,
'#title' => t('Single tile'),
'#description' => t('Check to make this layer untiled')
)
),
'options' => array(
'srs' => array(
'#type' => 'select',
'#title' => t('Projection'),
'#options' => array(
'EPSG:900913' => '900913',
'EPSG:4326' => '4326'),
'#default_value' => isset($this->data['options']['srs']) ?
$this->data['options']['srs'] : '900913'
),
'TRANSPARENT' => array(
'#type' => 'checkbox',
'#default_value' => isset($this->data['options']['TRANSPARENT']) ?
$this->data['options']['TRANSPARENT'] : FALSE,
'#return_value' => 'true',
'#title' => t('Transparent'),
'#description' => t('When a PNG, make the background color transparent')
),
'exceptions' => array(
'#type' => 'select',
'#title' => t('Exceptions'),
'#options' => array(
'application/vnd.ogc.se_xml' => 'application/vnd.ogc.se_xml',
'application/vnd.ogc.se_inimage' => 'application/vnd.ogc.se_inimage'),
'#default_value' => isset($this->data['options']['exceptions']) ?
$this->data['options']['exceptions'] : 'application/vnd.ogc.se_inimage',
'#description' => t('Select the exception handler')
),
'format' => array(
'#type' => 'select',
'#title' => t('File Format'),
'#options' => array(
'image/png' => 'image/png',
'image/gif' => 'image/gif',
'image/jpeg' => 'image/jpeg'),
'#default_value' => isset($this->data['options']['format']) ?
$this->data['options']['format'] : 'image/png'
),
'layers' => array(
'#type' => 'textfield',
'#title' => t('Layers'),
'#default_value' => isset($this->data['options']['layers']) ?
$this->data['options']['layers'] : ''
),
'styles' => array(
'#type' => 'textfield',
'#title' => t('Styles'),
'#default_value' => isset($this->data['options']['styles']) ?
$this->data['options']['styles'] : ''
),
),
);
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_wms.js');
}
}

View File

@@ -0,0 +1,26 @@
/**
* @file
* Layer handler for WMS layers
*/
/**
* Openlayer layer handler for WMS layer
*/
Drupal.openlayers.layer.wms = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
/* TODO: have PHP take care of the casts here, not JS! */
if (options.params.buffer) {
options.params.buffer = parseInt(options.params.buffer, 10);
}
if (options.params.ratio) {
options.params.ratio = parseFloat(options.params.ratio);
}
options.params.drupalID = options.drupalID;
var layer = new OpenLayers.Layer.WMS(title,
options.base_url, options.options, options.params);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,109 @@
<?php
/**
* @file
* XYZ Layer Type
* http://dev.openlayers.org/docs/files/OpenLayers/Layer/XYZ-js.html
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_xyz_openlayers_layer_types() {
return array(
'title' => t('XYZ'),
'description' => t('XYZ layer type. These are tiles sets usually in the form of {z}/{x}/{y}.png.'),
'layer_type' => array(
'file' => 'openlayers_layer_type_xyz.inc',
'class' => 'openlayers_layer_type_xyz',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers XYZ Layer Type class
*/
class openlayers_layer_type_xyz extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'xyz',
'sphericalMercator' => TRUE,
'wrapDateLine' => FALSE,
'zoomOffset' => 0,
'resolutions' => array_slice(openlayers_get_resolutions('900913'), 0, 18)
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
return array(
'url' => array(
'#type' => 'textarea',
'#title' => t('Base URL (template)'),
'#default_value' => !empty($this->data['url']) ? implode("\n", (array) $this->data['url']) : '',
'#maxlength' => 2083,
'#description' => t('This is the base URL template for the XYZ layer. It should be something similar to <em>http://example.com/tiles/1.0.0/layer_name/${z}/${x}/${y}.png</em>.'),
),
'serverResolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#description' => t('Only set this if you need a very specific resolution.'),
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['serverResolutions']) ?
array_map('strval', $this->data['serverResolutions']) : array(),
),
'resolutions' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#description' => t('Only set this if you need a very specific resolution.'),
'#options' => array_combine(
array_map('strval', openlayers_get_resolutions('900913')),
range(0, 21)),
'#title' => t('Zoom Level Range'),
'#default_value' => isset($this->data['resolutions']) ?
array_map('strval', $this->data['resolutions']) : array(),
),
'zoomOffset' => array(
'#type' => 'select',
'#description' => t('Zoom offset.'),
'#options' => array_combine(
range(0, 21),
range(0, 21)),
'#title' => t('Zoom offset'),
'#default_value' => isset($this->data['zoomOffset']) ?
$this->data['zoomOffset'] : array(),
),
'wrapDateLine' => array(
'#type' => 'checkbox',
'#title' => t('Wrap Date Line'),
'#default_value' => isset($this->data['wrapDateLine']) ? $this->data['wrapDateLine'] : FALSE,
'#description' => t('This allows the user to continually pan left and right as the tiles will repeat themselves. Note that this option is known to not work well with the 2.10 OL library.'),
),
);
}
function options_form_validate($form, &$form_state) {
$form_state['data']['url'] = explode("\n", $form_state['data']['url']);
$form_state['data']['serverResolutions'] = array_map('floatval', array_values($form_state['data']['serverResolutions']));
$form_state['data']['projection'] = array_values($form_state['data']['projection']);
$form_state['data']['resolutions'] = array_map('floatval', array_values($form_state['data']['resolutions']));
$form_state['data']['zoomOffset'] = (int) $form_state['data']['zoomOffset'];
}
/**
* Render.
*/
function render(&$map) {
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_xyz.js');
}
}

View File

@@ -0,0 +1,37 @@
/**
* @file
* Layer handler for XYZ layers
*/
/**
* Openlayer layer handler for XYZ layer
*/
Drupal.openlayers.layer.xyz = function(title, map, options) {
var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
if (options.maxExtent !== undefined) {
options.maxExtent = new OpenLayers.Bounds.fromArray(options.maxExtent) || new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34);
}
options.projection = 'EPSG:' + options.projection;
// Legacy goodnes
if (typeof options.base_url == 'string' && typeof options.url == 'undefined') {
options.url = options.base_url;
}
// Server resolutions are very particular in OL 2.11
var r = options.serverResolutions;
if (r == null || typeof r == 'undefined' || r.length == 0) {
options.serverResolutions = null;
}
// Wrap Date Line does not seem to work for 2.10. This may
// have something to do with our extent definitions.
if (OpenLayers.VERSION_NUMBER.indexOf('2.10') >= 0) {
options.wrapDateLine = null;
}
var layer = new OpenLayers.Layer.XYZ(title, options.url, options);
layer.styleMap = styleMap;
return layer;
};

View File

@@ -0,0 +1,89 @@
<?php
/**
* @file
* Yahoo Layer Type
*/
/**
* Define the Ctools plugin options.
*/
function openlayers_openlayers_layer_type_yahoo_openlayers_layer_types() {
return array(
'title' => t('Yahoo'),
'description' => t('Yahoo Maps API Map'),
'layer_type' => array(
'file' => 'openlayers_layer_type_yahoo.inc',
'class' => 'openlayers_layer_type_yahoo',
'parent' => 'openlayers_layer_type',
),
);
}
/**
* OpenLayers Yahoo Layer Type class
*/
class openlayers_layer_type_yahoo extends openlayers_layer_type {
/**
* Provide initial values for options.
*/
function options_init() {
return array(
'layer_handler' => 'yahoo',
) + parent::options_init();
}
/**
* Options form which generates layers
*/
function options_form($defaults = array()) {
$warning = (!variable_get('openlayers_layers_yahoo_api', FALSE)) ?
array('#value' => t('WARNING: Your Yahoo API key is not set.
Map including Yahoo layers will break until it is set correctly.')
) : NULL;
$yahoo_layer_types = array(
'hybrid' => 'Hybrid',
'street' => 'Street',
'satellite' => 'Satellite',
);
return array(
'type' => array(
'#title' => t('Yahoo Layer Type'),
'#type' => 'select',
'#default_value' => isset($this->data['type']) ?
$this->data['type'] : 'normal',
'#options' => $yahoo_layer_types
),
$warning
);
}
function settings_form() {
return array(
'openlayers_layers_yahoo_api' => array(
'#type' => 'textfield',
'#title' => t('Yahoo API Key'),
'#default_value' => variable_get('openlayers_layers_yahoo_api', ''),
)
);
}
/**
* Render.
*/
function render(&$map) {
static $yahoo_maps_included;
if (!isset($yahoo_maps_included)) {
drupal_add_js("//api.maps.yahoo.com/ajaxymap?v=3.0&appid=" .
variable_get('openlayers_layers_yahoo_api', ''),
'external');
drupal_add_js(drupal_get_path('module', 'openlayers') .
'/plugins/layer_types/openlayers_layer_type_yahoo.js');
$yahoo_maps_included = TRUE;
}
}
}

View File

@@ -0,0 +1,15 @@
/**
* Process Yahoo Layers
*
* @param layerOptions
* Object of options.
* @param mapid
* Map ID.
* @return
* Valid OpenLayers layer.
*/
Drupal.openlayers.layer.yahoo = function(title, map, options) {
var layer = new OpenLayers.Layer.Yahoo("Yahoo");
return layer;
};