If WKT was provided in the element, show it in the map.
This commit is contained in:
parent
7ea8f923ce
commit
cd800b73f4
|
@ -12,5 +12,22 @@ function farm_map_farm_map_behaviors() {
|
|||
'popup' => array(
|
||||
'js' => 'js/farmOS.map.behaviors.popup.js',
|
||||
),
|
||||
'wkt' => array(
|
||||
'js' => 'js/farmOS.map.behaviors.wkt.js',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_farm_map_view().
|
||||
*/
|
||||
function farm_map_farm_map_view($name, $element) {
|
||||
|
||||
// If WKT was provided in the element, show it in the map.
|
||||
if (isset($element['#wkt'])) {
|
||||
$settings = array(
|
||||
'zoom' => TRUE,
|
||||
);
|
||||
farm_map_add_behavior('wkt', $settings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,6 +149,11 @@ function theme_farm_map(&$vars) {
|
|||
// Add the map ID to the Drupal.settings.farm_map.maps JavaScript array.
|
||||
$settings['farm_map']['maps'] = array($id);
|
||||
|
||||
// If WKT is set, add it to the settings associated with the element ID.
|
||||
if (isset($element['#wkt'])) {
|
||||
$settings['farm_map']['wkt'][$id] = $element['#wkt'];
|
||||
}
|
||||
|
||||
// Add the JavaScript settings.
|
||||
drupal_add_js($settings, 'setting');
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
(function () {
|
||||
farmOS.map.behaviors.wkt = {
|
||||
attach: function (instance) {
|
||||
|
||||
// If WKT was set, create a layer.
|
||||
if (Drupal.settings.farm_map.wkt[instance.target] !== undefined) {
|
||||
var wkt = Drupal.settings.farm_map.wkt[instance.target];
|
||||
var type = 'vector';
|
||||
var opts = {
|
||||
title: 'Geometry',
|
||||
color: 'orange',
|
||||
};
|
||||
if (wkt !== '' && wkt !== 'GEOMETRYCOLLECTION EMPTY') {
|
||||
type = 'wkt';
|
||||
opts.wkt = wkt;
|
||||
}
|
||||
var layer = instance.addLayer(type, opts);
|
||||
}
|
||||
|
||||
// If zoom is true and the layer has features, zoom to them.
|
||||
// Otherwise, zoom to all vectors.
|
||||
if (Drupal.settings.farm_map.behaviors.wkt.zoom) {
|
||||
if (layer !== undefined) {
|
||||
instance.zoomToLayer(layer);
|
||||
}
|
||||
else {
|
||||
instance.zoomToVectors();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}());
|
Loading…
Reference in New Issue