From bc425eee8b53a03a222be639e9f453dca3968423 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 9 Feb 2010 17:06:25 +0000 Subject: [PATCH] 2010-02-09 Miguel de Dios * include/functions_gis.php: clean source code, and extract the javascript code to openlayers.pandora.js. * include/javascript/openlayers.pandora.js: new file, have a source code of gis in javascript. * operation/gis_maps/render_view.php, operation/gis_maps/index.php, operation/agentes/gis_view.php, godmode/agentes/agent_manager.php, godmode/setup/gis.php, godmode/gis_maps/configure_gis_map.php, godmode/gis_maps/index.php: add the require javascript to "openlayers.pandora.js". * godmode/setup/gis_step_2.php: add the source code to improve usability, now can set with the mouse points of center and default position for agents without gis data. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2335 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 18 + .../godmode/agentes/agent_manager.php | 2 + .../godmode/gis_maps/configure_gis_map.php | 2 + pandora_console/godmode/gis_maps/index.php | 47 ++- pandora_console/godmode/setup/gis.php | 2 + pandora_console/godmode/setup/gis_step_2.php | 155 ++++++-- pandora_console/include/functions_gis.php | 81 +--- .../include/javascript/openlayers.pandora.js | 360 ++++++++++++++++++ .../operation/agentes/gis_view.php | 2 + pandora_console/operation/gis_maps/index.php | 2 + .../operation/gis_maps/render_view.php | 2 + 11 files changed, 561 insertions(+), 112 deletions(-) create mode 100755 pandora_console/include/javascript/openlayers.pandora.js diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f41b51eaa8..72fb14e399 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,21 @@ +2010-02-09 Miguel de Dios + + * include/functions_gis.php: clean source code, and extract the javascript + code to openlayers.pandora.js. + + * include/javascript/openlayers.pandora.js: new file, have a source code of + gis in javascript. + + * operation/gis_maps/render_view.php, operation/gis_maps/index.php, + operation/agentes/gis_view.php, godmode/agentes/agent_manager.php, + godmode/setup/gis.php, godmode/gis_maps/configure_gis_map.php, + godmode/gis_maps/index.php: add the require javascript to + "openlayers.pandora.js". + + * godmode/setup/gis_step_2.php: add the source code to improve usability, + now can set with the mouse points of center and default position for agents + without gis data. + 2010-02-08 Pablo de la ConcepciĆ³n * general/header.php, extensions/module_groups.php: Applied patch from diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index eb20bf2c17..8ec38745b0 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -45,6 +45,8 @@ enterprise_include ('godmode/agentes/agent_manager.php'); require_once ('include/functions_servers.php'); require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + $new_agent = (bool) get_parameter ('new_agent'); if (! isset ($id_agente) && ! $new_agent) { diff --git a/pandora_console/godmode/gis_maps/configure_gis_map.php b/pandora_console/godmode/gis_maps/configure_gis_map.php index 9b3b9c6f45..1979454045 100644 --- a/pandora_console/godmode/gis_maps/configure_gis_map.php +++ b/pandora_console/godmode/gis_maps/configure_gis_map.php @@ -19,6 +19,8 @@ check_login (); require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + if (! give_acl ($config['id_user'], 0, "IW")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access map builder"); require ("general/noaccess.php"); diff --git a/pandora_console/godmode/gis_maps/index.php b/pandora_console/godmode/gis_maps/index.php index 77a01b4495..43f3da931a 100644 --- a/pandora_console/godmode/gis_maps/index.php +++ b/pandora_console/godmode/gis_maps/index.php @@ -19,12 +19,31 @@ check_login (); require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + if (! give_acl ($config['id_user'], 0, "IW")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access map builder"); require ("general/noaccess.php"); return; } +if (is_ajax ()) { + $action = get_parameter('action'); + $id_map = get_parameter('id_map'); + + $returnOperationDB = process_sql_update('tgis_map', array('default_map' => 1), array('id_tgis_map' => $id_map)); + + if ($returnOperationDB === false) + $data['correct'] = false; + else + $data['correct'] = true; + + echo json_encode($data); + + return; +} + + $action = get_parameter('action'); switch ($action) { @@ -40,11 +59,13 @@ $table->width = '500px'; $table->head[0] = __('Map name'); $table->head[1] = __('Group'); $table->head[2] = __('View'); -$table->head[3] = __('Delete'); +$table->head[3] = __('Default'); +$table->head[4] = __('Delete'); $table->align[1] = 'center'; $table->align[2] = 'center'; $table->align[3] = 'center'; +$table->align[4] = 'center'; $maps = get_db_all_rows_in_table ('tgis_map','map_name'); @@ -52,9 +73,15 @@ $table->data = array(); if ($maps !== false) { foreach ($maps as $map) { + + $checked = false; + if ($map['default_map']) + $checked = true; + $table->data[] = array('' . $map['map_name'] . '', print_group_icon ($map['group_id'], true), '' . print_image ("images/eye.png", true).'', + print_radio_button_extended('default_map', $map['id_tgis_map'], '', $checked, false, "setDefault(" . $map['id_tgis_map'] . ");", '', true), '' . print_image ("images/cross.png", true).''); } } @@ -67,4 +94,20 @@ print_input_hidden ('action','new_map'); print_submit_button (__('Create'), '', false, 'class="sub next"'); echo ''; echo ''; -?> \ No newline at end of file +?> + \ No newline at end of file diff --git a/pandora_console/godmode/setup/gis.php b/pandora_console/godmode/setup/gis.php index 2c9007afcd..a9adbc88de 100755 --- a/pandora_console/godmode/setup/gis.php +++ b/pandora_console/godmode/setup/gis.php @@ -26,6 +26,8 @@ if (! give_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_use require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + echo "

".__('Pandora Setup')." » "; echo __('Map conections GIS')."

"; diff --git a/pandora_console/godmode/setup/gis_step_2.php b/pandora_console/godmode/setup/gis_step_2.php index 7428ac8e57..10aab79466 100755 --- a/pandora_console/godmode/setup/gis_step_2.php +++ b/pandora_console/godmode/setup/gis_step_2.php @@ -115,29 +115,19 @@ switch ($action) { $table->width = '90%'; -//$table->colspan[0][1] = 3; -//$table->colspan[1][2] = 2; - $table->data = array(); $table->data[0][0] = __('Name') . ":"; $table->data[0][1] = print_input_text ('name', $mapConnection_name, '', 30, 60, true); -$table->data[0][2] = __("Default position for not GIS data element"); $table->data[1][0] = __("Group") . ":"; $table->data[1][1] = print_select_from_sql('SELECT id_grupo, nombre FROM tgrupo', 'group', $mapConnection_group, '', '', '0', true); -$table->data[1][2] = __('Latitude') . ":"; -$table->data[1][3] = print_input_text ('default_latitude', $mapConnection_defaultLatitude, '', 4, 10, true); $table->data[2][0] = __('Num levels zoom') . ":"; $table->data[2][1] = print_input_text ('num_levels_zoom', $mapConnection_numLevelsZoom, '', 4, 10, true); -$table->data[2][2] = __('Longitude') . ":"; -$table->data[2][3] = print_input_text ('default_longitude', $mapConnection_defaultLongitude, '', 4, 10, true); $table->data[3][0] = __('Default zoom level') . ":"; $table->data[3][1] = print_input_text ('initial_zoom', $mapConnection_defaultZoom, '', 4, 10, true); -$table->data[3][2] = __('Altitude') . ":"; -$table->data[3][3] = print_input_text ('default_altitude', $mapConnection_defaultAltitude, '', 4, 10, true); echo "

" . __('Basic configuration') . "

"; print_table($table); @@ -180,42 +170,147 @@ if ($mapConnectionData != null) { echo "
" . $optionsConnectionTypeTable . "
"; -echo "

" . __('Preview and Select the center') . "

"; -echo "

" . __("For test the conf and set the center of map.") . "

"; -echo "" . __("Refresh the map view") . ""; -echo "
"; +echo "

" . __('Preview and Select the center of the map and the default position of an agent without gis data') . "

"; +echo "" . __("Load the map view") . ""; +echo "
"; -$table->width = '30%'; +$table->width = '60%'; $table->data = array(); -$table->colspan[0][0] = 2; -$table->data[0][0] = __('Center map connection'); +//$table->colspan[0][3] = 3; +$table->data[0][0] = ''; +$table->data[0][1] = __('Center map connection'); +$table->data[0][2] = __("Default position for agents without GIS data"); -$table->data[1][2] = __('Latitude') . ":"; -$table->data[1][3] = print_input_text ('center_latitude', $mapConnection_centerLatitude, '', 4, 10, true); +$table->data[1][0] = __('Modify in map'); +$table->data[1][1] = print_radio_button_extended('radio_button', 1, '', 1, false, "changeSetManualPosition(true, false)", '', true); +$table->data[1][2] = print_radio_button_extended('radio_button', 2, '', 0, false, "changeSetManualPosition(false, true)", '', true); -$table->data[2][2] = __('Longitude') . ":"; -$table->data[2][3] = print_input_text ('center_longitude', $mapConnection_centerLongitude, '', 4, 10, true); +$table->data[2][0] = __('Latitude') . ":"; +$table->data[2][1] = print_input_text ('center_latitude', $mapConnection_centerLatitude, '', 10, 10, true); +$table->data[2][2] = print_input_text ('default_latitude', $mapConnection_defaultLatitude, '', 10, 10, true); -$table->data[3][2] = __('Altitude') . ":"; -$table->data[3][3] = print_input_text ('center_altitude', $mapConnection_centerAltitude, '', 4, 10, true); +$table->data[3][0] = __('Longitude') . ":"; +$table->data[3][1] = print_input_text ('center_longitude', $mapConnection_centerLongitude, '', 10, 10, true); +$table->data[3][2] = print_input_text ('default_longitude', $mapConnection_defaultLongitude, '', 10, 10, true); + +$table->data[4][0] = __('Altitude') . ":"; +$table->data[4][1] = print_input_text ('center_altitude', $mapConnection_centerAltitude, '', 10, 10, true); +$table->data[4][2] = print_input_text ('default_altitude', $mapConnection_defaultAltitude, '', 10, 10, true); print_table($table); -echo '
'; +echo '
'; print_submit_button (__('Save'), '', false, 'class="sub save"'); echo '
'; echo ""; ?> + +
', +// null, +// true, +// function () { popup.destroy(); }); +// feature.popup = popup; +// map.addPopup(popup); +// +// jQuery.ajax ({ +// data: "page=operation/gis_maps/ajax&opt="+featureData.type+"&id=" + featureData.id, +// type: "GET", +// dataType: 'json', +// url: "ajax.php", +// timeout: 10000, +// success: function (data) { +// if (data.correct) { +// $('.cloudContent' + featureData.id).css('text-align', 'left'); +// $('.cloudContent' + featureData.id).html(data.content); +// popup.updateSize(); +// } +// } +// }); +// } +// } +// }); + + return layer; +} + +/** + * Active and set callbacks of events. + * + * @param callbackFunClick Function to call when the user make single click in the map. + * + * @return None + */ +function js_activateEvents(callbackFunClick) { + /** + * Pandora click openlayers object. + */ + OpenLayers.Control.PandoraClick = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false + }, + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions); + OpenLayers.Control.prototype.initialize.apply(this, arguments); + this.handler = new OpenLayers.Handler.Click(this, {'click': options.callbackFunctionClick}, this.handlerOptions); + } + }); + + var click = new OpenLayers.Control.PandoraClick({callbackFunctionClick: callbackFunClick}); + + map.addControl(click); + click.activate(); +} + +/** + * Test the value is a int. + * + * @param mixed X The val that test to if is int. + * + * @return Boolean True if it's int. + */ +function isInt(x) { + var y=parseInt(x); + if (isNaN(y)) return false; + return x==y && x.toString()==y.toString(); +} + +/** + * Set the visibility of a layer + * + * @param string name The name of layer. + * @param boolean action True or false + */ +function showHideLayer(name, action) { + var layer = map.getLayersByName(name); + + layer[0].setVisibility(action); +} + +/** + * Add a point with the default icon in the map. + * + * @param string layerName The name of layer to put the point. + * @param string pointName The name to show in the point. + * @param float lon The coord of latitude for point. + * @param float lat The coord of longitude for point. + * @param string id The id of point. + * @param string type_string The type of point, it's use for ajax request. + * + * @return Object The point. + */ +function js_addPoint(layerName, pointName, lon, lat, id, type_string) { + var point = new OpenLayers.Geometry.Point(lon, lat) + .transform(map.displayProjection, map.getProjectionObject()); + + var layer = map.getLayersByName(layerName); + layer = layer[0]; + + feature = new OpenLayers.Feature.Vector(point,{nombre: pointName, id: id, type: type_string, long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject()) }); + + layer.addFeatures(feature); + + return feature; +} + +/** + * Add a point and set the icon in the map. + * + * @param string layerName The name of layer to put the point. + * @param string pointName The name to show in the point. + * @param float lon The coord of latitude for point. + * @param float lat The coord of longitude for point. + * @param string icon Url of icon image. + * @param integer width The width of icon. + * @param integer height The height of icon. + * @param string id The id of point. + * @param string type_string The type of point, it's use for ajax request. + * + * @return Object The point. + */ +function js_addPointExtent(layerName, pointName, lon, lat, icon, width, height, id, type_string) { + var point = new OpenLayers.Geometry.Point(lon, lat) + .transform(map.displayProjection, map.getProjectionObject()); + + var layer = map.getLayersByName(layerName); + layer = layer[0]; + + feature = new OpenLayers.Feature.Vector(point,{id: id, type: type_string, long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject()) }, {fontWeight: "bolder", fontColor: "#00014F", labelYOffset: -height, graphicHeight: width, graphicWidth: height, externalGraphic: icon, label: pointName}); + + layer.addFeatures(feature); + + return feature; +} + +/** + * + * @param string layerName The name of layer to put the point path. + * @param float lon The coord of latitude for point path. + * @param float lat The coord of longitude for point path. + * @param string color The color of point path in rrggbb format. + * @param boolean manual The type of point path, if it's manual, the point is same a donut. + * @param string id The id of point path. + * + * @return None + */ +function js_addPointPath(layerName, lon, lat, color, manual, id) { + var point = new OpenLayers.Geometry.Point(lon, lat) + .transform(map.displayProjection, map.getProjectionObject()); + + var layer = map.getLayersByName(layerName); + layer = layer[0]; + + var pointRadiusNormal = 4; + var strokeWidth = 2; + var pointRadiusManual = pointRadiusNormal - (strokeWidth / 2); + + if (manual) { + point = new OpenLayers.Feature.Vector(point,{estado: "ok", id: id, type: "point_path_info", + long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject())}, + {fillColor: "#ffffff", pointRadius: pointRadiusManual, stroke: 1, strokeColor: color, strokeWidth: strokeWidth, cursor: "pointer"} + ); + } + else { + point = new OpenLayers.Feature.Vector(point,{estado: "ok", id: id, type: "point_path_info", + long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject())}, + {fillColor: color, pointRadius: pointRadiusNormal, cursor: "pointer"} + ); + } + + layer.addFeatures(point); +} + +/** + * Draw the lineString. + * + * @param string layerName The name of layer to put the point path. + * @param Array points The array have content the points, but the point as lonlat openlayers object without transformation. + * @param string color The color of point path in rrggbb format. + * + * @return None + */ +function js_addLineString(layerName, points, color) { + var mapPoints = new Array(points.length); + var layer = map.getLayersByName(layerName); + + layer = layer[0]; + + for (var i = 0; i < points.length; i++) { + mapPoints[i] = points[i].transform(map.displayProjection, map.getProjectionObject()); + } + + var lineString = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.LineString(mapPoints), + null, + { strokeWidth: 2, fillOpacity: 0.2, fillColor: color, strokeColor: color} + ); + + layer.addFeatures(lineString); +} \ No newline at end of file diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php index 1e1ad59d94..aee18500b6 100644 --- a/pandora_console/operation/agentes/gis_view.php +++ b/pandora_console/operation/agentes/gis_view.php @@ -27,6 +27,8 @@ if (! give_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_use require_once ('include/functions_gis.php'); require_once ('include/functions_html.php'); +require_javascript_file('openlayers.pandora'); + /* Get the parameters */ $period = get_parameter ("period", 86400); $agentId = get_parameter('id_agente'); diff --git a/pandora_console/operation/gis_maps/index.php b/pandora_console/operation/gis_maps/index.php index ba83027c20..6b4c1bd9c7 100644 --- a/pandora_console/operation/gis_maps/index.php +++ b/pandora_console/operation/gis_maps/index.php @@ -21,6 +21,8 @@ check_login (); require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + echo "

".__('GIS Maps')." » ".__('Summary')."

"; $maps = getMaps(); diff --git a/pandora_console/operation/gis_maps/render_view.php b/pandora_console/operation/gis_maps/render_view.php index 090ddf9750..770bba6a78 100644 --- a/pandora_console/operation/gis_maps/render_view.php +++ b/pandora_console/operation/gis_maps/render_view.php @@ -20,6 +20,8 @@ check_login (); require_once ('include/functions_gis.php'); +require_javascript_file('openlayers.pandora'); + $idMap = (int) get_parameter ('map_id'); $show_history = get_parameter ('show_history', 'n');