3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Add geometry field.

This commit is contained in:
Michael Stenta 2020-06-11 10:54:21 -04:00
parent 588796769b
commit be0fa3b336
3 changed files with 44 additions and 0 deletions

View file

@ -34,6 +34,28 @@ function farm_livestock_move_form($form, &$form_state) {
'#required' => TRUE,
);
// Geometry
// Add a farmOS map instance with the WKT and drawing controls.
$wkt = '';
$form['move']['area']['geometry'] = array(
'#type' => 'fieldset',
'#title' => t('Geometry'),
'#description' => t('This field allows you to optionally specify a more precise geometry for the new location of assets. If you leave it blank, the geometry will be copied from the areas that assets are moving to (if available).'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['move']['area']['geometry']['map'] = array(
'#type' => 'farm_map',
'#map_name' => 'farm_movement',
'#wkt' => $wkt,
'#edit' => TRUE,
);
$form['move']['area']['geometry']['data'] = array(
'#type' => 'textarea',
'#title' => t('Data'),
'#default_value' => $wkt,
);
// Submit button.
$form['move']['submit'] = array(
'#type' => 'submit',

View file

@ -15,6 +15,9 @@ function farm_movement_farm_map_behaviors() {
'assets_cluster' => array(
'js' => 'js/farmOS.map.behaviors.assets_cluster.js',
),
'move' => array(
'js' => 'js/farmOS.map.behaviors.move.js',
),
);
}
@ -74,4 +77,9 @@ function farm_movement_farm_map_view($name, $element) {
farm_map_add_behavior('assets_cluster');
farm_map_add_behavior('popup');
}
// Add move behavior to movement maps.
if ($name == 'farm_movement') {
farm_map_add_behavior('move');
}
}

View file

@ -0,0 +1,14 @@
(function ($) {
farmOS.map.behaviors.move = {
attach: function (instance) {
// When features are changed in the map, drop the WKT into the data field.
instance.edit.wktOn('featurechange', function(wkt) {
$('#' + instance.target).parent().find('textarea').val(wkt);
});
},
// Make sure this runs after farmOS.map.behaviors.wkt.
weight: 101,
};
}(jQuery));