exit; } $x1 = $_REQUEST['x1']; $y1 = $_REQUEST['y1']; $x2 = $_REQUEST['x2']; $y2 = $_REQUEST['y2']; if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) { $oMap = ms_newMapObj($_SESSION['maps'][$mapName]); } if ($oMap->units == MS_DD) { /*this already returns a meter*/ $distance = distHaversine($x1, $y1, $x2, $y2); } else { $distance = sqrt(pow($x2 - $x1, 2) + pow($y2 - $y1, 2)); /*convert to meter*/ $distance = GetMetersPerUnit($oMap->units) * $distance; } header('Content-type: application/json'); header('X-JSON: true'); echo "{distance:{$distance}}"; exit; } catch (MgException $e) { echo "last error"; echo "ERROR: " . $e->GetExceptionMessage() . "\n"; echo $e->GetDetails() . "\n"; echo $e->GetStackTrace() . "\n"; } /************************************************************************/ /* Calculate distance in meters fro 2 lat/long coordinates. */ /* Comes from http://www.movable-type.co.uk/scripts/latlong.html */ /************************************************************************/
$mapObj = NULL; if ($oMap) { $mapName = $oMap->name; //header('Content-type: application/json'); //header('X-JSON: true'); $mapObj->sessionId = $sessionID; $mapObj->mapId = $mapId; $mapObj->metadata = NULL; if (isset($_REQUEST['map_metadata'])) { $mapMetadataKeys = explode(',', $_REQUEST['map_metadata']); foreach ($mapMetadataKeys as $key) { $mapObj->metadata->{$key} = $oMap->getMetadata($key); } } $mapObj->projString = $oMap->getProjection(); $mapObj->metersPerUnit = GetMetersPerUnit($oMap->units); $mapObj->dpi = $oMap->resolution; $mapObj->imagetype = $oMap->imagetype; $mapObj->mapName = $oMap->name; if (!isset($_SESSION['maps'])) { $_SESSION['maps'] = array(); } if (!isset($_SESSION['maps'][$mapObj->mapName])) { $_SESSION['maps'][$mapObj->mapName] = $mapId; } $mapObj->extent = array($oMap->extent->minx, $oMap->extent->miny, $oMap->extent->maxx, $oMap->extent->maxy); $minScale = $oMap->web->minscale == -1 ? MIN_SCALE : $oMap->web->minscale; $maxScale = $oMap->web->maxscale == -1 ? MAX_SCALE : $oMap->web->maxscale; $title = $oMap->getmetadata('legend_title'); $mapObj->mapTitle = $title == "" ? $mapObj->mapName : $title; //layers