diff -urN share-2.0.0.colored_label/api/classes/CMap.php share/api/classes/CMap.php
--- share-2.0.0.colored_label/api/classes/CMap.php	2012-07-10 15:06:15.000000000 -0400
+++ share/api/classes/CMap.php	2012-07-12 14:53:31.000000000 -0400
@@ -476,7 +476,7 @@
 				if (!isset($result[$link['sysmapid']]['links'])) {
 					$result[$link['sysmapid']]['links'] = array();
 				}
-
+				$link = $this->splitDrawtypeAndAnchors($link);
 				if (!is_null($options['preservekeys'])) {
 					$result[$link['sysmapid']]['links'][$link['linkid']] = $link;
 				}
@@ -785,6 +785,48 @@
 	}
 
 	/**
+	* Split the database draw type to return the proper drawtype and anchors position.
+	* In order to avoid modifying the database, we use the last digit to keep the drawtype and
+	* store the anchor1 with the hundreds and anchor2 in decimals.
+	*
+	* @param array $selement an array containing the element data
+	* @return the updated array containing the element data
+	*/
+	private function splitDrawtypeAndAnchors($link) {
+		if (!is_null($link['drawtype'])) {
+			# Anchor1 is stored in the hundreds
+			$link['anchor1'] = intval($link['drawtype']/100);
+			# Anchor2 is stored in the decimals
+			$link['anchor2'] = intval($link['drawtype']/10)%10;
+			# drawtype is stored in the units
+			$link['drawtype'] = $link['drawtype']%10;
+		}
+		return $link;
+	}
+	
+	/**
+	 * Merge the drawtype and anchor fields to be stored in the database.
+	 * In order to avoid modifying the database, we use the last digit to keep the drawtype and
+	 * store the anchor1 with the hundreds and anchor2 in decimals.
+	 *
+	 * @param array $selements multidimensional array with elements data
+	 * @return the updated multidimensional array with elements data
+	 */
+	private function mergeDrawtypeAndAnchors($links) {
+		foreach (array_keys($links) as $key) {
+			if (key_exists('anchor1', $links[$key]) && !is_null($links[$key]['anchor1'])) {
+				$links[$key]['drawtype']+=$links[$key]['anchor1']*100;
+				unset($links[$key]['anchor1']);
+			}
+			if (key_exists('anchor2', $links[$key]) && !is_null($links[$key]['anchor2'])) {
+				$links[$key]['drawtype']+=$links[$key]['anchor2']*10;
+				unset($links[$key]['anchor2']);
+			}
+		}
+		return $links;
+	}
+	
+	/**
 	* Split the database label location to return the proper label_location and label rotation.
 	* In order to avoid modifying the database, we use the last digit to keep the label location and
 	* multiple the rotation angle by 10 to store it.
@@ -953,10 +995,12 @@
 
 		$newLinkids = $updLinkids = array('linkids' => array());
 		if (!empty($linksToAdd)) {
+			$linksToAdd=$this->mergeDrawtypeAndAnchors($linksToAdd);
 			$newLinkids = $this->createLinks($linksToAdd);
 		}
 
 		if (!empty($linksToUpdate)) {
+			$linksToUpdate=$this->mergeDrawtypeAndAnchors($linksToUpdate);
 			$updLinkids = $this->updateLinks($linksToUpdate);
 		}
 
diff -urN share-2.0.0.colored_label/include/maps.inc.php share/include/maps.inc.php
--- share-2.0.0.colored_label/include/maps.inc.php	2012-07-10 15:39:05.000000000 -0400
+++ share/include/maps.inc.php	2012-07-12 14:55:19.000000000 -0400
@@ -1292,49 +1292,188 @@
 	}
 	return $elements;
 }
+/*
+ * Calculate the distance between two points
+*
+* Params:       $point1         The first point to evaluate (Array containing component for X,Y and Z)
+*               $point2         The second point to evaluate (Array containing component for X,Y and Z)
+*
+* Returns the distance between 2 points in space as a float
+*/
+function distancePointPoint($point1, $point2) {
+	$tmp=array('x'=>$point2['x']-$point1['x'],'y'=>$point2['y']-$point1['y'],'z'=>$point2['z']-$point1['z']);
+	return sqrt($tmp['x']*$tmp['x']+$tmp['y']*$tmp['y']+$tmp['z']*$tmp['z']);
+}
+/*
+ * Calculate the distance between a point and a line
+*
+* Params:       $point          The point to valuate (Array containing component for X,Y and Z)
+*               $start          The point where the segment starts (Array containing component for X,Y and Z)
+*               $end            The point where the segment ends (Array containing component for X,Y and Z)
+*
+* Returns the closest point on the line from the provided point. The distance between both points is also returned.
+*/
+function  distancePointLine($point, $start, $end) {
+	$res=array('x'=>-1,'y'=>-1,'z'=>-1,'dst'=>0);
+	$distance= distancePointPoint($end,$start);
+	// The next line allow to use this fonction to calculate the distance between two points ($start == $end)
+	if ($distance==0) $distance=1;
+	$u = (  (($point['x']-$start['x'])*($end['x']-$start['x'])) +
+					(($point['y']-$start['y'])*($end['y']-$start['y'])) +
+					(($point['z']-$start['z'])*($end['z']-$start['z']))) /
+					($distance*$distance);
+	if ($u<0) {
+		$res['x'] = $start['x'];
+		$res['y'] = $start['y'];
+		$res['z'] = $start['z'];
+	} else if ($u>1) {
+		$res['x'] = $end['x'];
+		$res['y'] = $end['y'];
+		$res['z'] = $end['z'];
+	} else {
+		$res['x'] = $start['x'] + $u * ($end['x'] - $start['x']);
+		$res['y'] = $start['y'] + $u * ($end['y'] - $start['y']);
+		$res['z'] = $start['z'] + $u * ($end['z'] - $start['z']);
+	}
+	$res['dst'] = distancePointPoint($point,$res);
+	return $res;
+}
 
-function drawMapConnectors(&$im, $map, $map_info, $drawAll = false) {
-	$selements = $map['selements'];
-
-	foreach ($map['links'] as $link) {
-		$selement1 = $selements[$link['selementid1']];
-		$selement2 = $selements[$link['selementid2']];
+/*
+ * Determine if a point is closer than another point, inclusive or not.
+*
+* Params:       $point1         The first point to evaluate (Array containing component for X,Y,Z and distance)
+*               $point2         The second point to evaluate (Array containing component for X,Y,Z and distance)
+*               $inclusive      True if we want verification to be inclusive (if $p1.dst<=$p2.dst instead of $p1.dst<$p2.dst)
+*
+* Returns true if the distance contained in the $point1 array is lower (lower and equals if $inclusive) than the distance component of $point2
+*/
+function isCloser($point1,$point2,$inclusive) {
+	$res=false;
+	if ($inclusive and $point1['dst'] <= $point2['dst'])
+	$res=true;
+	else if ($point1['dst'] < $point2['dst'])
+	$res=true;
+	return $res;
+}
+function getIconLineByElement($element, $anchor, $map, $info=null) {
+	$res = array();
+	$x = $element['x'];
+	$y = $element['y'];
+	$dx = 0;
+	$dy = 0;
+	$image = get_png_by_selement($element, $info);
+	if($image){
+		$dx = imagesx($image);
+		$dy = imagesy($image);
+	}
+	switch($anchor) {
+		// Steady Y axis, we move along the X axis
+		case MAP_LABEL_ALIGN_BOTTOM:
+			$res['start']   = array('x'=>$x,        'y'=>$y+$dy,    'z'=>0);
+			$res['center']  = array('x'=>$x+$dx/2,  'y'=>$y+$dy,    'z'=>0);
+			$res['end']     = array('x'=>$x+$dx,    'y'=>$y+$dy,    'z'=>0);
+			break;
+		case MAP_LABEL_ALIGN_TOP:
+			$res['start']   = array('x'=>$x,        'y'=>$y,        'z'=>0);
+			$res['center']  = array('x'=>$x+$dx/2,  'y'=>$y,        'z'=>0);
+			$res['end']     = array('x'=>$x+$dx,    'y'=>$y,        'z'=>0);
+			break;
+			// Steady X axis, we move along the Y axis
+		case MAP_LABEL_ALIGN_LEFT:
+			$res['start']   = array('x'=>$x,        'y'=>$y,        'z'=>0);
+			$res['center']  = array('x'=>$x,        'y'=>$y+$dy/2,  'z'=>0);
+			$res['end']     = array('x'=>$x,        'y'=>$y+$dy,    'z'=>0);
+			break;
+		case MAP_LABEL_ALIGN_RIGHT:
+			$res['start']   = array('x'=>$x+$dx,    'y'=>$y,        'z'=>0);
+			$res['center']  = array('x'=>$x+$dx,    'y'=>$y+$dy/2,  'z'=>0);
+			$res['end']     = array('x'=>$x+$dx,    'y'=>$y+$dy,    'z'=>0);
+			break;
+			// Middle point (default behavior)
+		case MAP_LABEL_ALIGN_CENTER:
+		default:
+			$res=pointToCoord(get_icon_center_by_selement($element, $info, $map),0);
+	}
+	return $res;
+}
 
-		list($x1, $y1) = get_icon_center_by_selement($selement1, $map_info[$link['selementid1']], $map);
-		list($x2, $y2) = get_icon_center_by_selement($selement2, $map_info[$link['selementid2']], $map);
+function pointToCoord($point) {
+	$res = array();
+	$res['start'] = array('x'=>$point[0],'y'=>$point[1],'z'=>0);
+	$res['center'] = $res['start'];
+	$res['end'] = $res['start'];
+	return $res;
+}
 
-		if (isset($selement1['elementsubtype']) && $selement1['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-			if (!$drawAll && ($selement2['elementsubtype'] != SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
-				continue;
-			}
+function getConnectorCoordinates($map, $map_info, $link, $drawAll = false) {
+	$selements = $map['selements'];
+	$selement1 = $selements[$link['selementid1']];
+	$selement2 = $selements[$link['selementid2']];
 
-			if ($selement1['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-				$w = $selement1['width'];
-				$h = $selement1['height'];
-			}
-			else {
-				$w = $map['width'];
-				$h = $map['height'];
-			}
-			list($x1, $y1) = calculateMapAreaLinkCoord($x1, $y1, $w, $h, $x2, $y2);
+	$line1 = getIconLineByElement($selement1, $link['anchor1'], $map, $map_info[$link['selementid1']]);
+	$line2 = getIconLineByElement($selement2, $link['anchor2'], $map, $map_info[$link['selementid2']]);
+	
+	if (isset($selement1['elementsubtype']) && $selement1['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
+		if (!$drawAll && ($selement2['elementsubtype'] != SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
+			continue;
 		}
-
-		if (isset($selement2['elementsubtype']) && $selement2['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-			if (!$drawAll && ($selement1['elementsubtype'] != SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
-				continue;
-			}
-
-			if ($selement2['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-				$w = $selement2['width'];
-				$h = $selement2['height'];
-			}
-			else {
-				$w = $map['width'];
-				$h = $map['height'];
-			}
-			list($x2, $y2) = calculateMapAreaLinkCoord($x2, $y2, $w,$h, $x1, $y1);
+	
+		if ($selement1['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
+			$w = $selement1['width'];
+			$h = $selement1['height'];
 		}
+		else {
+			$w = $map['width'];
+			$h = $map['height'];
+		}
+		$line1 = pointToLine(caculateMapAreaLinkCoord($x1, $y1, $w, $h, $x2, $y2));
+	}
+	
+	if (isset($selement2['elementsubtype']) && $selement2['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
+		if (!$drawAll && ($selement1['elementsubtype'] != SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
+			continue;
+		}
+	
+		if ($selement2['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
+			$w = $selement2['width'];
+			$h = $selement2['height'];
+		}
+		else {
+			$w = $map['width'];
+			$h = $map['height'];
+		}
+		$line2 = pointToLine(calculateMapAreaLinkCoord($x2, $y2, $w,$h, $x1, $y1));
+	} 
+	
+	// Okay, this is where the fun begins. The next array (tests) will hold all distance that must be mesured. Since we are working
+	// with finite lines, we know for sure that the closest point will be an extremity of one of the two lines. Therefore,
+	// all we need to do is to test the extremities of each line (start-end) with the other line.
+	// Yet, for two parallel lines, I prefer to view the line starting from the center than the extremities.
+	// By adding the incl=true to those tests, that will give them predominance, line of element 2 being predominant
+	// of element 1.
+	$res=array('x'=>-1,'y'=>-1,'z'=>-1,'dst'=>99999999999);
+	$tests=array(   array('point'=>$line1['start'], 'incl'=>false,'line'=>$line2),
+	array('point'=>$line2['start'], 'incl'=>false,'line'=>$line1),
+	array('point'=>$line1['center'],'incl'=>true, 'line'=>$line2),
+	array('point'=>$line2['center'],'incl'=>true, 'line'=>$line1),
+	array('point'=>$line1['end'],   'incl'=>false,'line'=>$line2),
+	array('point'=>$line2['end'],   'incl'=>false,'line'=>$line1)
+	);
+	foreach ($tests as $test) {
+		$tmp=distancePointLine($test['point'],$test['line']['start'],$test['line']['end']);
+		if (isCloser($tmp,$res,$test['incl'])) {
+			$p1=$test['point'];
+			$res=$tmp;
+		}
+	}
+	return array($p1['x'],$p1['y'],$res['x'],$res['y']);
+}
 
+function drawMapConnectors(&$im, $map, $map_info, $drawAll = false) {
+	foreach ($map['links'] as $link) {
+		list($x1,$y1,$x2,$y2) = getConnectorCoordinates($map, $map_info, $link,$drawAll);
+		
 		$drawtype = $link['drawtype'];
 		$color = convertColor($im, $link['color']);
 
@@ -1594,42 +1733,13 @@
 	global $colors;
 
 	$links = $map['links'];
-	$selements = $map['selements'];
 
 	foreach ($links as $link) {
 		if (empty($link['label'])) {
 			continue;
 		}
 
-		$selement1 = $selements[$link['selementid1']];
-		list($x1, $y1) = get_icon_center_by_selement($selement1, $map_info[$link['selementid1']], $map);
-
-		$selement2 = $selements[$link['selementid2']];
-		list($x2, $y2) = get_icon_center_by_selement($selement2, $map_info[$link['selementid2']], $map);
-
-		if (isset($selement1['elementsubtype']) && $selement1['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-			if ($selement1['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-				$w = $selement1['width'];
-				$h = $selement1['height'];
-			}
-			else {
-				$w = $map['width'];
-				$h = $map['height'];
-			}
-			list($x1, $y1) = calculateMapAreaLinkCoord($x1, $y1, $w, $h, $x2, $y2);
-		}
-
-		if (isset($selement2['elementsubtype']) && $selement2['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-			if ($selement2['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) {
-				$w = $selement2['width'];
-				$h = $selement2['height'];
-			}
-			else {
-				$w = $map['width'];
-				$h = $map['height'];
-			}
-			list($x2, $y2) = calculateMapAreaLinkCoord($x2, $y2, $w, $h, $x1, $y1);
-		}
+		list($x1,$y1,$x2,$y2) = getConnectorCoordinates($map, $map_info, $link);
 
 		$drawtype = $link['drawtype'];
 		$color = convertColor($im, $link['color']);
diff -urN share-2.0.0.colored_label/include/views/js/configuration.sysmaps.js.php share/include/views/js/configuration.sysmaps.js.php
--- share-2.0.0.colored_label/include/views/js/configuration.sysmaps.js.php	2012-07-10 15:16:06.000000000 -0400
+++ share/include/views/js/configuration.sysmaps.js.php	2012-07-12 11:01:56.000000000 -0400
@@ -219,6 +219,7 @@
 
 		<form id="linkForm" name="linkForm" style="display: none;">
 			<input type="hidden" name="selementid1">
+			<input type="hidden" name="anchor1">
 
 			<table class="formtable" style="width: 100%;">
 				<tbody>
@@ -231,6 +232,18 @@
 					<td><select class="input" name="selementid2" id="selementid2"></select></td>
 				</tr>
 				<tr>
+					<td><label for="anchor2"><?php echo _('Anchor point'); ?></label></td>
+					<td>
+						<select class="input" name="anchor2" id="anchor2">
+							<option value="<?php echo MAP_LABEL_ALIGN_CENTER; ?>"><?php echo _('Center'); ?></option>
+							<option value="<?php echo MAP_LABEL_ALIGN_BOTTOM; ?>"><?php echo _('Bottom'); ?></option>
+							<option value="<?php echo MAP_LABEL_ALIGN_TOP; ?>"><?php echo _('Top'); ?></option>
+							<option value="<?php echo MAP_LABEL_ALIGN_LEFT; ?>"><?php echo _('Left'); ?></option>
+							<option value="<?php echo MAP_LABEL_ALIGN_RIGHT; ?>"><?php echo _('Right'); ?></option>
+						</select>
+					</td>
+				</tr>
+				<tr>
 					<td><label for="drawtype"><?php echo _('Type (OK)'); ?></label></td>
 					<td >
 						<select size="1" class="input" name="drawtype" id="drawtype">
diff -urN share-2.0.0.colored_label/js/class.cmap.js share/js/class.cmap.js
--- share-2.0.0.colored_label/js/class.cmap.js	2012-07-10 15:16:47.000000000 -0400
+++ share/js/class.cmap.js	2012-07-12 15:00:27.000000000 -0400
@@ -643,6 +643,8 @@
 					selementid2:	null,
 					linktriggers:	{},
 					drawtype:		0,
+					anchor1:		0,
+					anchor2:		0,
 					color:			'00CC00'
 				};
 
@@ -1635,8 +1637,13 @@
 					tmp = link.selementid1;
 					link.selementid1 = selement1.id;
 					link.selementid2 = tmp;
-				}
 
+					tmp = link.anchor1;
+					link.anchor1 = link.anchor2;
+					link.anchor2 = tmp;
+
+				}
+				
 				// populate list of elements to connect with
 				jQuery('#selementid2').empty();
 
