2010-02-09 18:06:25 +01:00
|
|
|
// 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 Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; 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.
|
|
|
|
|
|
|
|
var map; // Map global var object is use in multiple places.
|
2010-02-24 12:49:03 +01:00
|
|
|
var statusShow = 'all';
|
2010-03-02 13:00:57 +01:00
|
|
|
//The name of layer hierachy because in PHP change the text name into language of user.
|
|
|
|
var storeLayerNameHierachy = '';
|
|
|
|
|
|
|
|
function js_refreshParentLines(layerName) {
|
|
|
|
if (typeof(layerName) == 'undefined') {
|
|
|
|
layerName = storeLayerNameHierachy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
storeLayerNameHierachy = layerName;
|
|
|
|
}
|
|
|
|
|
|
|
|
listFeaturesWithParents = Array();
|
|
|
|
|
|
|
|
jQuery.each(map.getLayersByClass("OpenLayers.Layer.Vector"), function (i, layer) {
|
|
|
|
visible = layer.visibility;
|
|
|
|
|
|
|
|
jQuery.each(layer.features, function (i, feature) {
|
|
|
|
if (feature.data.type == "point_agent_info") {
|
|
|
|
id_parent = feature.data.id_parent;
|
|
|
|
long_lat = feature.data.long_lat;
|
|
|
|
id = feature.data.id;
|
|
|
|
status = feature.data.status;
|
|
|
|
|
2013-05-20 18:35:49 +02:00
|
|
|
listFeaturesWithParents[id] = {
|
|
|
|
'id': id,
|
|
|
|
'id_parent': id_parent,
|
|
|
|
'long_lat': long_lat,
|
|
|
|
'status': status,
|
|
|
|
'visible': visible};
|
2010-03-02 13:00:57 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var layer = map.getLayersByName(layerName);
|
|
|
|
layer = layer[0];
|
|
|
|
|
|
|
|
layer.destroyFeatures();
|
|
|
|
|
|
|
|
jQuery.each(listFeaturesWithParents, function (i, feature) {
|
2010-03-02 16:13:04 +01:00
|
|
|
//INI "break" of foreach posibilites
|
2010-03-02 13:00:57 +01:00
|
|
|
if (typeof(feature) == 'undefined') return;
|
|
|
|
if (feature.id_parent == 0) return;
|
2010-03-02 16:13:04 +01:00
|
|
|
if (typeof(listFeaturesWithParents[feature.id_parent]) == 'undefined') return; //The agent have parent but this parent is not in the map.
|
2010-03-02 13:00:57 +01:00
|
|
|
if ((!feature.visible)
|
|
|
|
|| (!listFeaturesWithParents[feature.id_parent].visible)) return;
|
|
|
|
if ((isHideFeatureByStatus(feature.status))
|
|
|
|
|| (isHideFeatureByStatus(listFeaturesWithParents[feature.id_parent].status))) return;
|
2010-03-02 16:13:04 +01:00
|
|
|
//END "break" of foreach posibilites
|
2010-03-02 13:00:57 +01:00
|
|
|
|
|
|
|
points = new Array();
|
|
|
|
|
|
|
|
points[0] = new OpenLayers.Geometry.Point(feature.long_lat.lon, feature.long_lat.lat);
|
|
|
|
points[1] = new OpenLayers.Geometry.Point(listFeaturesWithParents[feature.id_parent].long_lat.lon, listFeaturesWithParents[feature.id_parent].long_lat.lat);
|
|
|
|
|
|
|
|
var line = new OpenLayers.Feature.Vector(
|
|
|
|
new OpenLayers.Geometry.LineString(points),
|
|
|
|
null,
|
|
|
|
{ strokeWidth: 2, fillOpacity: 0.2, fillColor: 'red', strokeDashstyle: "dash", strokeColor: 'red'});
|
|
|
|
|
|
|
|
layer.addFeatures(line);
|
|
|
|
});
|
|
|
|
}
|
2010-02-09 18:06:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inicialize the map in the browser and the object map.
|
|
|
|
*
|
|
|
|
* @param string id_div The id of div to draw the map.
|
|
|
|
* @param integer initial_zoom The initial zoom to show the map.
|
|
|
|
* @param float center_latitude The coord of latitude for center.
|
|
|
|
* @param float center_longitude The coord of longitude for center.
|
|
|
|
* @param array objBaseLayers The array of baselayers with number index, and the baselayer is another asociative array that content 'type', 'name' and 'url'.
|
|
|
|
* @param array arrayControls The array of enabled controls, the controls is: 'Navigation', 'MousePosition', 'OverviewMap', 'PanZoom', 'PanZoomBar', 'ScaleLine', 'Scale'
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
2010-03-08 18:40:23 +01:00
|
|
|
function js_printMap(id_div, initial_zoom, center_latitude, center_longitude, objBaseLayers, arrayControls) {
|
|
|
|
controlsList = [];
|
|
|
|
|
|
|
|
for (var controlIndex in arrayControls) {
|
|
|
|
if (isInt(controlIndex)) {
|
|
|
|
switch (arrayControls[controlIndex]) {
|
|
|
|
case 'Navigation':
|
|
|
|
controlsList.push(new OpenLayers.Control.Navigation());
|
|
|
|
break;
|
|
|
|
case 'MousePosition':
|
|
|
|
controlsList.push(new OpenLayers.Control.MousePosition());
|
|
|
|
break;
|
|
|
|
case 'OverviewMap':
|
|
|
|
controlsList.push(new OpenLayers.Control.OverviewMap());
|
|
|
|
break;
|
|
|
|
case 'PanZoom':
|
|
|
|
controlsList.push(new OpenLayers.Control.PanZoom());
|
|
|
|
break;
|
|
|
|
case 'PanZoomBar':
|
|
|
|
controlsList.push(new OpenLayers.Control.PanZoomBar());
|
|
|
|
break;
|
|
|
|
case 'ScaleLine':
|
|
|
|
controlsList.push(new OpenLayers.Control.ScaleLine());
|
|
|
|
break;
|
|
|
|
case 'Scale':
|
|
|
|
controlsList.push(new OpenLayers.Control.Scale());
|
|
|
|
break;
|
|
|
|
case 'layerSwitcher':
|
|
|
|
controlsList.push(new OpenLayers.Control.LayerSwitcher());
|
|
|
|
break;
|
2010-02-09 18:06:25 +01:00
|
|
|
}
|
2010-03-08 18:40:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var option = {
|
2013-02-05 12:30:04 +01:00
|
|
|
controls: controlsList,
|
|
|
|
projection: new OpenLayers.Projection("EPSG:900913"),
|
|
|
|
displayProjection: new OpenLayers.Projection("EPSG:4326"),
|
|
|
|
units: "m",
|
|
|
|
numZoomLevels: 18,
|
|
|
|
maxResolution: 156543.0339,
|
|
|
|
maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)};
|
2012-08-17 13:39:25 +02:00
|
|
|
|
2010-03-08 18:40:23 +01:00
|
|
|
map = new OpenLayers.Map(id_div, option);
|
2017-04-10 17:46:32 +02:00
|
|
|
map.events.Event
|
2010-03-08 18:40:23 +01:00
|
|
|
var baseLayer = null;
|
|
|
|
|
2017-04-10 17:46:32 +02:00
|
|
|
map.events.on({"zoomend": EventZoomEnd});
|
2017-07-12 18:49:39 +02:00
|
|
|
map.events.on({"mouseup": EventZoomEnd});
|
2018-04-27 12:17:42 +02:00
|
|
|
|
2010-03-08 18:40:23 +01:00
|
|
|
//Define the maps layer
|
|
|
|
for (var baselayerIndex in objBaseLayers) {
|
|
|
|
if (isInt(baselayerIndex)) {
|
|
|
|
switch (objBaseLayers[baselayerIndex]['type']) {
|
|
|
|
case 'OSM':
|
|
|
|
baseLayer = null;
|
|
|
|
baseLayer = new OpenLayers.Layer.OSM(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
objBaseLayers[baselayerIndex]['url'],
|
2013-02-05 12:30:04 +01:00
|
|
|
{
|
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels'],
|
2010-03-08 18:40:23 +01:00
|
|
|
'sphericalMercator': true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
map.addLayer(baseLayer);
|
|
|
|
break;
|
|
|
|
case 'Gmap':
|
|
|
|
switch (objBaseLayers[baselayerIndex]['gmap_type']) {
|
|
|
|
case 'G_PHYSICAL_MAP':
|
|
|
|
baseLayer = new OpenLayers.Layer.Google(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
{type: G_PHYSICAL_MAP,
|
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels'],
|
|
|
|
'sphericalMercator': true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
map.addLayer(baseLayer);
|
|
|
|
break;
|
|
|
|
case 'G_HYBRID_MAP':
|
|
|
|
baseLayer = new OpenLayers.Layer.Google(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
{type: G_HYBRID_MAP,
|
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels'],
|
|
|
|
'sphericalMercator': true
|
|
|
|
}
|
|
|
|
);
|
2010-02-09 18:06:25 +01:00
|
|
|
map.addLayer(baseLayer);
|
|
|
|
break;
|
2010-03-08 18:40:23 +01:00
|
|
|
case 'G_SATELLITE_MAP':
|
|
|
|
baseLayer = new OpenLayers.Layer.Google(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
{type: G_SATELLITE_MAP,
|
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels'],
|
|
|
|
'sphericalMercator': true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
map.addLayer(baseLayer);
|
2010-03-01 21:42:49 +01:00
|
|
|
break;
|
2010-03-08 18:40:23 +01:00
|
|
|
default:
|
|
|
|
baseLayer = new OpenLayers.Layer.Google(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
{numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels'],
|
|
|
|
'sphericalMercator': true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
map.addLayer(baseLayer);
|
2010-02-24 14:42:01 +01:00
|
|
|
break;
|
2010-02-09 18:06:25 +01:00
|
|
|
}
|
2010-03-08 18:40:23 +01:00
|
|
|
break;
|
|
|
|
case 'Static_Image':
|
|
|
|
baseLayer = null;
|
|
|
|
baseLayer = new OpenLayers.Layer.Image(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
objBaseLayers[baselayerIndex]['url'],
|
|
|
|
new OpenLayers.Bounds(objBaseLayers[baselayerIndex]['bb_left'],
|
|
|
|
objBaseLayers[baselayerIndex]['bb_bottom'],
|
|
|
|
objBaseLayers[baselayerIndex]['bb_right'],
|
|
|
|
objBaseLayers[baselayerIndex]['bb_top']
|
|
|
|
),
|
|
|
|
new OpenLayers.Size(objBaseLayers[baselayerIndex]['image_width'], objBaseLayers[baselayerIndex]['image_height']),
|
2013-02-05 12:30:04 +01:00
|
|
|
{
|
|
|
|
projection: new OpenLayers.Projection("EPSG:4326"),
|
2012-08-17 13:39:25 +02:00
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels']
|
2010-03-08 18:40:23 +01:00
|
|
|
}
|
|
|
|
);
|
2012-08-17 13:39:25 +02:00
|
|
|
map.addLayer(baseLayer);
|
2010-03-08 18:40:23 +01:00
|
|
|
break;
|
2018-04-27 12:17:42 +02:00
|
|
|
case 'WMS':
|
|
|
|
// http://<server>/geoserver/wms
|
|
|
|
// ?bbox=-130,24,-66,50
|
|
|
|
// &styles=population
|
|
|
|
// &Format=application/openlayers
|
|
|
|
// &request=GetMap
|
|
|
|
// &layers=topp:states
|
|
|
|
// &width=550
|
|
|
|
// &height=250
|
|
|
|
// &srs=EPSG:4326
|
|
|
|
var layer = new OpenLayers.Layer.WMS(
|
|
|
|
objBaseLayers[baselayerIndex]['name'],
|
|
|
|
objBaseLayers[baselayerIndex]['url'],
|
|
|
|
{
|
|
|
|
layers: objBaseLayers[baselayerIndex]['layers'],
|
|
|
|
format: "image/png"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
numZoomLevels: objBaseLayers[baselayerIndex]['num_zoom_levels']
|
|
|
|
}
|
|
|
|
);
|
|
|
|
map.addLayer(layer);
|
|
|
|
break;
|
2010-02-09 18:06:25 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-08 18:40:23 +01:00
|
|
|
}
|
2010-03-08 18:49:34 +01:00
|
|
|
|
2010-03-08 18:40:23 +01:00
|
|
|
var lonLat = new OpenLayers.LonLat(center_longitude, center_latitude)
|
|
|
|
.transform(map.displayProjection, map.getProjectionObject());
|
2012-08-17 13:39:25 +02:00
|
|
|
|
2010-03-08 18:40:23 +01:00
|
|
|
map.setCenter (lonLat, initial_zoom);
|
2017-07-12 18:49:39 +02:00
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-12 18:49:39 +02:00
|
|
|
function EventZoomEnd (evt,zoom = map.zoom) {
|
|
|
|
if(evt == null){
|
|
|
|
var actual_zoom = (zoom < 6) ? 6 : zoom;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var actual_zoom = (evt.object.zoom < 6) ? 6 : evt.object.zoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-10 17:46:32 +02:00
|
|
|
var max_width_marker = 38;
|
|
|
|
var max_zoom_map = map.numZoomLevels;
|
|
|
|
var max_font_size = 15;
|
|
|
|
|
|
|
|
var actual_font_size = (actual_zoom * max_font_size) / max_zoom_map;
|
|
|
|
|
|
|
|
jQuery.each($("tspan"), function (i, tspan) {
|
|
|
|
if (actual_zoom <= 18 && actual_zoom > 13)
|
2017-07-13 12:07:53 +02:00
|
|
|
actual_font_size = (max_font_size - 3);
|
2017-04-10 17:46:32 +02:00
|
|
|
else if (actual_zoom <= 13 && actual_zoom >= 8)
|
2017-07-13 12:07:53 +02:00
|
|
|
actual_font_size = (max_font_size - 6);
|
2017-04-10 17:46:32 +02:00
|
|
|
else if (actual_zoom <= 8)
|
2017-07-13 12:07:53 +02:00
|
|
|
actual_font_size = (max_font_size - 6);
|
2017-04-10 17:46:32 +02:00
|
|
|
$(tspan).css('font-size', actual_font_size);
|
|
|
|
});
|
|
|
|
|
|
|
|
var layers = map.getLayersByClass("OpenLayers.Layer.Vector");
|
|
|
|
|
|
|
|
|
|
|
|
jQuery.each(layers, function (i, layer) {
|
|
|
|
var features = layer.features;
|
|
|
|
|
|
|
|
jQuery.each(features, function (j, feature) {
|
|
|
|
var graphicHeight = feature.style.graphicHeight || -1;
|
|
|
|
var graphicWidth = feature.style.graphicWidth || -1;
|
|
|
|
|
|
|
|
if (graphicHeight > 0 && graphicWidth > 0) {
|
|
|
|
var new_width_marker = (actual_zoom * max_width_marker) / max_zoom_map;
|
|
|
|
var new_height_marker = (actual_zoom * max_width_marker) / max_zoom_map;
|
|
|
|
|
|
|
|
feature.style.fontSize = '' + actual_font_size + ' !important';
|
|
|
|
feature.style.graphicHeight = new_height_marker;
|
|
|
|
feature.style.graphicWidth = new_width_marker;
|
|
|
|
feature.style.labelYOffset = (new_width_marker * -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
layer.redraw();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-02-24 12:49:03 +01:00
|
|
|
/**
|
|
|
|
* Change the style of state button, and call the function "hideAgentsStatus"
|
|
|
|
* whith new state for agents icons to show.
|
|
|
|
*
|
|
|
|
* @param string newShowStatus State to show.
|
|
|
|
* @return none
|
|
|
|
*/
|
|
|
|
function changeShowStatus(newShowStatus) {
|
2017-12-04 11:41:52 +01:00
|
|
|
statusShow = newShowStatus;
|
2010-02-24 12:49:03 +01:00
|
|
|
hideAgentsStatus();
|
2017-07-13 12:07:53 +02:00
|
|
|
EventZoomEnd(null,map.zoom);
|
2010-03-02 13:00:57 +01:00
|
|
|
js_refreshParentLines();
|
2010-02-24 12:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that change the visibility of feature by status and state var
|
|
|
|
* statusShow
|
|
|
|
*
|
|
|
|
* @param object feature The feature to change the visibility
|
|
|
|
* @param int status The status code, it can be (1,4) for bad, (2) for warning, (0) for ok and the rest
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
function hideFeatureByStatus(feature, status) {
|
|
|
|
feature.style.display = 'none';
|
|
|
|
|
|
|
|
switch (statusShow) {
|
|
|
|
case 'bad':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 1) || (status == 4) || (status == 100))
|
2010-02-24 12:49:03 +01:00
|
|
|
feature.style.display = '';
|
|
|
|
break;
|
|
|
|
case 'warning':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 2) || (status == 200))
|
2010-02-24 12:49:03 +01:00
|
|
|
feature.style.display = '';
|
|
|
|
break;
|
|
|
|
case 'ok':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 0) || (status == 300))
|
2010-02-24 12:49:03 +01:00
|
|
|
feature.style.display = '';
|
|
|
|
break;
|
|
|
|
case 'default':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status != 1) && (status != 4) && (status != 2) && (status != 0) && (status != 100) && (status != 200) && (status != 300))
|
2010-02-24 12:49:03 +01:00
|
|
|
feature.style.display = '';
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
feature.style.display = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the feature is hidden.
|
|
|
|
*
|
|
|
|
* @param integer status The integer status.
|
|
|
|
* @return boolean The true or false.
|
|
|
|
*/
|
|
|
|
function isHideFeatureByStatus(status) {
|
|
|
|
returnVar = true;
|
|
|
|
|
|
|
|
switch (statusShow) {
|
|
|
|
case 'bad':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 1) || (status == 4) || (status == 100))
|
2010-02-24 12:49:03 +01:00
|
|
|
returnVar = false;
|
|
|
|
break;
|
|
|
|
case 'warning':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 2) || (status == 200))
|
2010-02-24 12:49:03 +01:00
|
|
|
returnVar = false;
|
|
|
|
break;
|
|
|
|
case 'ok':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status == 0) || (status == 300))
|
2010-02-24 12:49:03 +01:00
|
|
|
returnVar = false;
|
|
|
|
break;
|
|
|
|
case 'default':
|
2017-12-04 11:41:52 +01:00
|
|
|
if ((status != 1) && (status != 4) && (status != 2) && (status != 0) && (status != 100) && (status != 200) && (status != 300))
|
2010-02-24 12:49:03 +01:00
|
|
|
returnVar = false;
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
returnVar = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the agents icons that not is of current state var statusShow.
|
|
|
|
*
|
|
|
|
* @return none
|
|
|
|
*/
|
|
|
|
function hideAgentsStatus() {
|
|
|
|
layers = map.getLayersByClass("OpenLayers.Layer.Vector");
|
|
|
|
|
|
|
|
jQuery.each(layers, function (i, layer) {
|
|
|
|
features = layer.features;
|
|
|
|
|
|
|
|
jQuery.each(features, function (j, feature) {
|
|
|
|
status = feature.data.status;
|
|
|
|
|
|
|
|
hideFeatureByStatus(feature, status);
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.redraw();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-02-23 17:36:24 +01:00
|
|
|
/**
|
|
|
|
* Change the refresh time for the map.
|
|
|
|
*
|
|
|
|
* @param int time seconds
|
|
|
|
* @return none
|
|
|
|
*/
|
|
|
|
function changeRefreshTime(time) {
|
|
|
|
refreshAjaxIntervalSeconds = time * 1000;
|
2010-02-24 12:49:03 +01:00
|
|
|
|
|
|
|
clearInterval(idIntervalAjax);
|
|
|
|
idIntervalAjax = setInterval("clock_ajax_refresh()", refreshAjaxIntervalSeconds);
|
|
|
|
oldRefreshAjaxIntervalSeconds = refreshAjaxIntervalSeconds;
|
2010-02-23 17:36:24 +01:00
|
|
|
}
|
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
/**
|
|
|
|
* Make the layer in the map.
|
|
|
|
*
|
|
|
|
* @param string name The name of layer, it's show in the toolbar of layer.
|
|
|
|
* @param boolean visible Set visible the layer.
|
|
|
|
* @param array dot It's a asociative array that have 'url' of icon image, 'width' in pixeles and 'height' in pixeles.
|
|
|
|
*
|
|
|
|
* @return object The layer created.
|
|
|
|
*/
|
|
|
|
function js_makeLayer(name, visible, dot) {
|
|
|
|
if (dot == null) {
|
|
|
|
dot = Array();
|
|
|
|
dot['url'] = 'images/dot_green.png';
|
|
|
|
dot['width'] = 20; //11;
|
|
|
|
dot['height'] = 20; //11;
|
|
|
|
}
|
2013-05-20 18:35:49 +02:00
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
//Set the style in layer
|
|
|
|
var style = new OpenLayers.StyleMap(
|
|
|
|
{fontColor: "#ff0000",
|
|
|
|
labelYOffset: - dot['height'],
|
|
|
|
graphicHeight: dot['height'],
|
|
|
|
graphicWidth: dot['width'],
|
|
|
|
externalGraphic: dot['url'],
|
|
|
|
label:"${nombre}"
|
|
|
|
}
|
|
|
|
);
|
2013-05-20 18:35:49 +02:00
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
//Make the layer as type vector
|
|
|
|
var layer = new OpenLayers.Layer.Vector(name, {styleMap: style});
|
2013-05-20 18:35:49 +02:00
|
|
|
|
|
|
|
layer.setVisibility(visible);
|
2010-02-09 18:06:25 +01:00
|
|
|
map.addLayer(layer);
|
|
|
|
|
|
|
|
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, {
|
2013-07-30 12:25:49 +02:00
|
|
|
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);
|
|
|
|
}
|
2010-02-09 18:06:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var click = new OpenLayers.Control.PandoraClick({callbackFunctionClick: callbackFunClick});
|
2013-07-30 12:25:49 +02:00
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
map.addControl(click);
|
2013-07-30 12:25:49 +02:00
|
|
|
click.activate();
|
2010-02-09 18:06:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2010-02-25 18:27:55 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param integer statusAgent The status of point.
|
|
|
|
* @param integer idParent Id Parent of agent.
|
|
|
|
*
|
|
|
|
* @return Object The point.
|
|
|
|
*/
|
|
|
|
function js_addAgentPoint(layerName, pointName, lon, lat, id, type_string, statusAgent, idParent) {
|
|
|
|
var point = new OpenLayers.Geometry.Point(lon, lat)
|
|
|
|
.transform(map.displayProjection, map.getProjectionObject());
|
2012-08-17 13:39:25 +02:00
|
|
|
|
2010-02-25 18:27:55 +01:00
|
|
|
var layer = map.getLayersByName(layerName);
|
|
|
|
layer = layer[0];
|
2012-08-17 13:39:25 +02:00
|
|
|
|
2013-05-20 18:35:49 +02:00
|
|
|
feature = new OpenLayers.Feature.Vector(point,
|
|
|
|
{
|
|
|
|
id_parent: idParent,
|
|
|
|
status: statusAgent,
|
|
|
|
nombre: pointName,
|
|
|
|
id: id,
|
|
|
|
type: type_string,
|
|
|
|
long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject())
|
|
|
|
});
|
2017-03-01 09:20:28 +01:00
|
|
|
|
2010-02-25 18:27:55 +01:00
|
|
|
if (isHideFeatureByStatus(statusAgent)) {
|
|
|
|
feature.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.addFeatures(feature);
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
2010-02-24 12:49:03 +01:00
|
|
|
* @param integer statusAgent The status of point.
|
2010-02-09 18:06:25 +01:00
|
|
|
*
|
|
|
|
* @return Object The point.
|
|
|
|
*/
|
2010-02-24 12:49:03 +01:00
|
|
|
function js_addPoint(layerName, pointName, lon, lat, id, type_string, statusAgent) {
|
2010-02-09 18:06:25 +01:00
|
|
|
var point = new OpenLayers.Geometry.Point(lon, lat)
|
|
|
|
.transform(map.displayProjection, map.getProjectionObject());
|
|
|
|
|
|
|
|
var layer = map.getLayersByName(layerName);
|
|
|
|
layer = layer[0];
|
|
|
|
|
2010-02-24 12:49:03 +01:00
|
|
|
feature = new OpenLayers.Feature.Vector(point,{status: statusAgent, nombre: pointName, id: id, type: type_string, long_lat: new OpenLayers.LonLat(lon, lat).transform(map.displayProjection, map.getProjectionObject()) });
|
|
|
|
|
|
|
|
if (isHideFeatureByStatus(statusAgent)) {
|
|
|
|
feature.style.display = 'none';
|
|
|
|
}
|
2010-02-09 18:06:25 +01:00
|
|
|
|
|
|
|
layer.addFeatures(feature);
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
|
2010-02-25 18:27:55 +01:00
|
|
|
/**
|
|
|
|
* Add a agent 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.
|
|
|
|
* @param integer statusAgent The status of point.
|
|
|
|
* @param integer idParent Id Parent of agent.
|
|
|
|
*
|
|
|
|
* @return Object The point.
|
|
|
|
*/
|
|
|
|
function js_addAgentPointExtent(layerName, pointName, lon, lat, icon, width, height, id, type_string, statusAgent, idParent) {
|
|
|
|
var point = new OpenLayers.Geometry.Point(lon, lat)
|
|
|
|
.transform(map.displayProjection, map.getProjectionObject());
|
2013-05-20 14:49:57 +02:00
|
|
|
|
2010-02-25 18:27:55 +01:00
|
|
|
var layer = map.getLayersByName(layerName);
|
|
|
|
layer = layer[0];
|
|
|
|
|
|
|
|
if (typeof(statusAgent) == 'string')
|
|
|
|
statusA = parseInt(statusAgent);
|
|
|
|
else
|
|
|
|
statusA = statusAgent;
|
|
|
|
|
2013-05-20 18:35:49 +02:00
|
|
|
feature = new OpenLayers.Feature.Vector(point,
|
|
|
|
{
|
2017-03-01 09:20:28 +01:00
|
|
|
id_parent: idParent.toString(),
|
2013-05-20 18:35:49 +02:00
|
|
|
status: statusA,
|
2017-03-01 09:20:28 +01:00
|
|
|
id: id.toString(),
|
2013-05-20 18:35:49 +02:00
|
|
|
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
|
|
|
|
});
|
2010-02-25 18:27:55 +01:00
|
|
|
|
|
|
|
if (isHideFeatureByStatus(statusAgent)) {
|
|
|
|
feature.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.addFeatures(feature);
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
|
2010-02-09 18:06:25 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
2010-02-24 12:49:03 +01:00
|
|
|
* @param integer statusAgent The status of point.
|
2010-02-09 18:06:25 +01:00
|
|
|
*
|
|
|
|
* @return Object The point.
|
|
|
|
*/
|
2010-02-24 12:49:03 +01:00
|
|
|
function js_addPointExtent(layerName, pointName, lon, lat, icon, width, height, id, type_string, statusAgent) {
|
2010-02-09 18:06:25 +01:00
|
|
|
var point = new OpenLayers.Geometry.Point(lon, lat)
|
|
|
|
.transform(map.displayProjection, map.getProjectionObject());
|
|
|
|
|
|
|
|
var layer = map.getLayersByName(layerName);
|
|
|
|
layer = layer[0];
|
|
|
|
|
2010-02-24 12:49:03 +01:00
|
|
|
if (typeof(statusAgent) == 'string')
|
|
|
|
statusA = parseInt(statusAgent);
|
|
|
|
else
|
|
|
|
statusA = statusAgent;
|
|
|
|
|
|
|
|
feature = new OpenLayers.Feature.Vector(point,{status: statusA, 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});
|
|
|
|
|
|
|
|
if (isHideFeatureByStatus(statusAgent)) {
|
|
|
|
feature.style.display = 'none';
|
|
|
|
}
|
2010-02-09 18:06:25 +01:00
|
|
|
|
|
|
|
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);
|
2010-02-19 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return feature object for a id agent passed.
|
|
|
|
*
|
|
|
|
* @param interger id The agent id.
|
|
|
|
* @return mixed Return the feature object, if it didn't found then return null.
|
|
|
|
*/
|
|
|
|
function searchPointAgentById(id) {
|
|
|
|
for (layerIndex = 0; layerIndex < map.getNumLayers(); layerIndex++) {
|
|
|
|
layer = map.layers[layerIndex];
|
|
|
|
|
|
|
|
if (layer.features != undefined) {
|
|
|
|
for (featureIndex = 0; featureIndex < layer.features.length; featureIndex++) {
|
|
|
|
feature = layer.features[featureIndex];
|
|
|
|
if (feature.data.id == id) {
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2013-12-16 10:29:43 +01:00
|
|
|
}
|