2010-01-18 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_gis.php, operation/gis_maps/ajax.php: code for GIS maps,
	now show correctly the path points and start to show the popup for this
	points.
	* include/javascript/OpenLayers/lib/Gears/gears_init.js,
	include/javascript/OpenLayers/lib/OpenLayers/Format/ArcXML/Features.js:
	some files of OpenLayers that I erased in the previous clean.
	* images/spinner.gif: image for ajax loading.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2287 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2010-01-19 15:49:34 +00:00
parent 827344056a
commit c712d75a15
6 changed files with 560 additions and 0 deletions

View File

@ -1,3 +1,13 @@
2010-01-18 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_gis.php, operation/gis_maps/ajax.php: code for GIS maps,
now show correctly the path points and start to show the popup for this
points.
* include/javascript/OpenLayers/lib/Gears/gears_init.js,
include/javascript/OpenLayers/lib/OpenLayers/Format/ArcXML/Features.js:
some files of OpenLayers that I erased in the previous clean.
* images/spinner.gif: image for ajax loading.
2010-01-18 Miguel de Dios <miguel.dedios@artica.es>
* operation/visual_console/render_view.php: fix style, add a white space.

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

View File

@ -0,0 +1,349 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
function printMap($idDiv, $iniZoom, $numLevelZooms, $latCenter, $lonCenter, $urlMap, $controls = null) {
$controls = (array)$controls;
//require_javascript_file('OpenLayers/OpenLayers');
?>
<script type="text/javascript" src="http://dev.openlayers.org/nightly/OpenLayers.js"></script>
<script type="text/javascript">
var map;
$(document).ready (
function () {
map = new OpenLayers.Map ("<?php echo $idDiv; ?>", {
<?php
echo "controls: [";
$first = true;
foreach ($controls as $control) {
if (!$first) echo ",";
$first = false;
switch ($control) {
case 'Navigation':
echo "new OpenLayers.Control.Navigation()";
break;
case 'PanZoomBar':
echo "new OpenLayers.Control.PanZoomBar()";
break;
case 'ScaleLine':
echo "new OpenLayers.Control.ScaleLine()";
break;
}
}
echo "],";
?>
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: <?php echo $numLevelZooms; ?>,
units: 'm', //metros
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
//Define the map layer
var baseLayer = new OpenLayers.Layer.OSM("BaseLayer OSM", "<?php echo $urlMap['OSM']; ?>", {numZoomLevels: <?php echo $numLevelZooms; ?>});
map.addLayer(baseLayer);
if( ! map.getCenter() ){
var lonLat = new OpenLayers.LonLat(<?php echo $lonCenter; ?>, <?php echo $latCenter; ?>)
.transform(map.displayProjection, map.getProjectionObject());
map.setCenter (lonLat, <?php echo $iniZoom; ?>);
}
}
);
function showHideLayer(name, action) {
var layer = map.getLayersByName(name);
layer[0].setVisibility(action);
}
function addPoint(layerName, pointName, lon, lat) {
var point = new OpenLayers.Geometry.Point(lon, lat)
.transform(map.displayProjection, map.getProjectionObject());
var layer = map.getLayersByName(layerName);
layer = layer[0];
layer.addFeatures(new OpenLayers.Feature.Vector(point,{nombre: pointName, estado: "ok"}));
}
function addPointExtent(layerName, pointName, lon, lat, icon, width, height) {
var point = new OpenLayers.Geometry.Point(lon, lat)
.transform(map.displayProjection, map.getProjectionObject());
var layer = map.getLayersByName(layerName);
layer = layer[0];
layer.addFeatures(new OpenLayers.Feature.Vector(point,{estado: "ok"}, {fontWeight: "bolder", fontColor: "#00014F", labelYOffset: -height, graphicHeight: width, graphicWidth: height, externalGraphic: icon, label: pointName}));
}
function 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,
lanlot: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject())},
{fillColor: "#ffffff", pointRadius: pointRadiusManual, stroke: 1, strokeColor: color, strokeWidth: strokeWidth}
);
}
else {
point = new OpenLayers.Feature.Vector(point,{estado: "ok", id: id,
lanlot: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject())},
{fillColor: color, pointRadius: pointRadiusNormal}
);
}
layer.addFeatures(point);
}
function 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);
}
</script>
<?php
}
function makeLayer($name, $visible = true, $dot = null) {
if ($dot == null) {
$dot['url'] = 'images/dot_green.png';
$dot['width'] = 20; //11;
$dot['height'] = 20; //11;
}
$visible = (bool)$visible;
?>
<script type="text/javascript">
$(document).ready (
function () {
//Creamos el estilo
var style = new OpenLayers.StyleMap(
{fontColor: "#ff0000",
labelYOffset: -<?php echo $dot['height']; ?>,
graphicHeight: <?php echo $dot['height']; ?>,
graphicWidth: <?php echo $dot['width']; ?>,
externalGraphic: "<?php echo $dot['url']; ?>", label:"${nombre}"
}
);
//Creamos la capa de tipo vector
var layer = new OpenLayers.Layer.Vector(
'<?php echo $name; ?>', {styleMap: style}
);
layer.setVisibility(<?php echo $visible; ?>);
map.addLayer(layer);
var select = new OpenLayers.Control.SelectFeature(layer);
map.addControl(select);
select.activate();
layer.events.on({
"featureselected": function(e) {
if (e.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
var feature = e.feature;
var featureData = feature.data;
var lanlot = featureData.lanlot;
var popup;
popup = new OpenLayers.Popup.FramedCloud('cloud00',
lanlot,
null,
'<div class="cloudContent' + featureData.id + '" style="text-align: center;"><img src="images/spinner.gif" /></div>',
null,
true,
function () { popup.destroy(); });
feature.popup = popup;
map.addPopup(popup);
jQuery.ajax ({
data: "page=operation/gis_maps/ajax&opt=point_info&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();
}
}
});
}
}
});
}
);
</script>
<?php
}
function addPoint($layerName, $pointName, $lat, $lon, $icon = null, $width = 20, $height = 20) {
?>
<script type="text/javascript">
$(document).ready (
function () {
<?php
if ($icon != null) {
?>
addPointExtent('<?php echo $layerName; ?>',
'<?php echo $pointName; ?>', <?php echo $lon; ?>,
<?php echo $lat; ?>, '<?php echo $icon; ?>', <?php echo $width; ?>, <?php echo $height?>);
<?php
}
else {
?>
addPoint('<?php echo $layerName; ?>',
'<?php echo $pointName; ?>', <?php echo $lon; ?>, <?php echo $lat; ?>);
<?php
}
?>
}
);
</script>
<?php
}
function addPointPath($layerName, $lat, $lon, $color, $manual = 1, $id) {
?>
<script type="text/javascript">
$(document).ready (
function () {
addPointPath('<?php echo $layerName; ?>', <?php echo $lon; ?>, <?php echo $lat; ?>, '<?php echo $color; ?>', <?php echo $manual; ?>, <?php echo $id; ?>);
}
);
</script>
<?php
}
function getMaps() {
return get_db_all_rows_in_table ('tgis_map', 'map_name');
}
function getMapConf($idMap) {
$confsEncode = get_db_all_rows_sql('SELECT * FROM tgis_map_connection WHERE tgis_map_id_tgis_map = ' . $idMap);
$confsDecode = array();
if ($confsEncode !== false) {
foreach ($confsEncode as $confEncode) {
$temp = json_decode($confEncode['conection_data'], true);
$confsDecode[$temp['type']][] = $temp['content'];
}
}
return $confsDecode;
}
function getLayers($idMap) {
$layers = get_db_all_rows_sql('SELECT * FROM tgis_map_layer WHERE tgis_map_id_tgis_map = ' . $idMap);
return $layers;
}
function get_agent_last_coords($idAgent) {
$coords = get_db_row_sql("SELECT last_latitude, last_longitude, last_altitude FROM tagente WHERE id_agente = " . $idAgent);
return $coords;
}
function get_agent_icon_map($idAgent, $state = false) {
$row = get_db_row_sql('SELECT id_grupo, icon_path FROM tagente WHERE id_agente = ' . $idAgent);
if ($row['icon_path'] === null) {
$iconGroup = "images/" . get_group_icon($row['id_grupo']) . ".png";
return $iconGroup;
}
else {
$icon = "images/gis_map/icons/" . $row['icon_path'];
if (!$state)
return $icon . ".png";
else
return $icon . "_" . $state . ".png";
}
}
function addPath($layerName, $idAgent) {
$listPoints = get_db_all_rows_sql('SELECT * FROM tgis_data WHERE tagente_id_agente = ' . $idAgent . ' ORDER BY end_timestamp ASC');
$listPoints = array(
array('id_tgis_data' => 0, 'longitude' => -3.709, 'latitude' => 40.422, 'altitude' => 0, 'manual_placemen' => 1),
array('id_tgis_data' => 1, 'longitude' => -3.710, 'latitude' => 40.420, 'altitude' => 0, 'manual_placemen' => 0),
array('id_tgis_data' => 2, 'longitude' => -3.711, 'latitude' => 40.420, 'altitude' => 0, 'manual_placemen' => 1),
array('id_tgis_data' => 3, 'longitude' => -3.712, 'latitude' => 40.422, 'altitude' => 0, 'manual_placemen' => 0),
array('id_tgis_data' => 4, 'longitude' => -3.708187, 'latitude' => 40.42056, 'altitude' => 0, 'manual_placemen' => 0)
);
$avaliableColors = array("#ff0000", "#00ff00", "#0000ff", "#000000");
$color = $avaliableColors[array_rand($avaliableColors)];
?>
<script type="text/javascript">
$(document).ready (
function () {
<?php
if ($listPoints != false) {
$listPoints = (array)$listPoints;
$first = true;
echo "var points = [";
foreach($listPoints as $point) {
if (!$first) echo ",";
$first =false;
echo "new OpenLayers.Geometry.Point(" . $point['longitude'] . ", " . $point['latitude'] . ")";
}
echo "];";
}
?>
addLineString('<?php echo $layerName; ?>', points, '<?php echo $color; ?>');
}
);
</script>
<?php
if ($listPoints != false) {
foreach($listPoints as $point) {
if (end($listPoints) != $point)
addPointPath($layerName, $point['latitude'], $point['longitude'], $color, (int)$point['manual_placemen'], $point['id_tgis_data']);
}
}
}
?>

View File

@ -0,0 +1,88 @@
/*
* Copyright 2007, Google Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Google Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Sets up google.gears.*, which is *the only* supported way to access Gears.
*
* Circumvent this file at your own risk!
*
* In the future, Gears may automatically define google.gears.* without this
* file. Gears may use these objects to transparently fix bugs and compatibility
* issues. Applications that use the code below will continue to work seamlessly
* when that happens.
*/
(function() {
// We are already defined. Hooray!
if (window.google && google.gears) {
return;
}
var factory = null;
// Firefox
if (typeof GearsFactory != 'undefined') {
factory = new GearsFactory();
} else {
// IE
try {
factory = new ActiveXObject('Gears.Factory');
// privateSetGlobalObject is only required and supported on WinCE.
if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
factory.privateSetGlobalObject(this);
}
} catch (e) {
// Safari
if ((typeof navigator.mimeTypes != 'undefined')
&& navigator.mimeTypes["application/x-googlegears"]) {
factory = document.createElement("object");
factory.style.display = "none";
factory.width = 0;
factory.height = 0;
factory.type = "application/x-googlegears";
document.documentElement.appendChild(factory);
}
}
}
// *Do not* define any objects if Gears is not installed. This mimics the
// behavior of Gears defining the objects in the future.
if (!factory) {
return;
}
// Now set up the objects, being careful not to overwrite anything.
//
// Note: In Internet Explorer for Windows Mobile, you can't add properties to
// the window object. However, global objects are automatically added as
// properties of the window object in all browsers.
if (!window.google) {
google = {};
}
if (!google.gears) {
google.gears = {factory: factory};
}
})();

View File

@ -0,0 +1,48 @@
/* Copyright (c) 2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/ArcXML.js
*/
/**
* Class: OpenLayers.Format.ArcXML.Features
* Read/Wite ArcXML features. Create a new instance with the
* <OpenLayers.Format.ArcXML.Features> constructor.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.ArcXML.Features = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Constructor: OpenLayers.Format.ArcXML.Features
* Create a new parser/writer for ArcXML Features. Create an instance of this class
* to get a set of features from an ArcXML response.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: read
* Read data from a string of ArcXML, and return a set of OpenLayers features.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Array(<OpenLayers.Feature.Vector>)} A collection of features.
*/
read: function(data) {
var axl = new OpenLayers.Format.ArcXML();
var parsed = axl.read(data);
return parsed.features.feature;
}
});

View File

@ -0,0 +1,65 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
require_once ("include/config.php");
check_login ();
require_once ('include/functions_gis.php');
$opt = get_parameter('opt');
switch ($opt) {
case 'point_info':
$id = get_parameter('id');
$row = get_db_row_sql('SELECT * FROM tgis_data WHERE id_tgis_data = ' . $id);
$row = array('id_tgis_data' => 0, 'longitude' => -3.709,
'latitude' => 40.422, 'altitude' => 0, 'end_timestamp' => '2010-01-14 17:19:45', 'start_timestamp' => '2010-01-12 17:19:45', 'manual_placemen' => 1, 'tagente_id_agente' => 1);
$returnJSON = array();
$returnJSON['correct'] = 1;
$returnJSON['content'] = __('Agent') . ': <a style="font-weight: bolder;" href="?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $row['tagente_id_agente'] . '">pepito</a><br />';
$returnJSON['content'] .= __('Position') . ': (' . $row['longitude'] . ', ' . $row['latitude'] . ', ' . $row['altitude'] . ') <br />';
$returnJSON['content'] .= __('Start contact') . ': ' . $row['start_timestamp'] . '<br />';
$returnJSON['content'] .= __('Last contact') . ': ' . $row['end_timestamp'] . '<br />';
$returnJSON['content'] .= __('Num reports') . ': 666<br />'; //$row['num_packages']; //TODO
if ($row['manual_placemen']) $returnJSON['content'] .= '<br />' . __('Manual placement') . '<br />';
echo json_encode($returnJSON);
break;
}
// $returnJSON = array();
//
// $returnJSON['correct'] = 1;
// $returnJSON['content'] = '';
//
// //echo json_encode($returnJSON);
// break;
//}
//
//$listPoints = get_db_all_rows_sql('SELECT * FROM tgis_data WHERE tagente_id_agente = ' . $idAgent . ' ORDER BY end_timestamp ASC');
//
//$listPoints = array(
// array('id_tgis_data' => 0, 'longitude' => -3.709, 'latitude' => 40.422, 'altitude' => 0, 'manual_placemen' => 1),
// array('id_tgis_data' => 1, 'longitude' => -3.710, 'latitude' => 40.420, 'altitude' => 0, 'manual_placemen' => 0),
// array('id_tgis_data' => 2, 'longitude' => -3.711, 'latitude' => 40.420, 'altitude' => 0, 'manual_placemen' => 1),
// array('id_tgis_data' => 3, 'longitude' => -3.712, 'latitude' => 40.422, 'altitude' => 0, 'manual_placemen' => 0),
// array('id_tgis_data' => 4, 'longitude' => -3.708187, 'latitude' => 40.42056, 'altitude' => 0, 'manual_placemen' => 0)
//);
?>