<?php

Main();

function Main()
{
$GLOBALS[“goMap”] = ms_newMapObj(“map/posisi.map” );

//batas koordinat seluruh peta, untuk tool ‘zoom all’
$GLOBALS[“gfMinX”] = (float)$GLOBALS[“goMap”]->extent->minx;
$GLOBALS[“gfMinY”] = (float)$GLOBALS[“goMap”]->extent->miny;
$GLOBALS[“gfMaxX”] = (float)$GLOBALS[“goMap”]->extent->maxx;
$GLOBALS[“gfMaxY”] = (float)$GLOBALS[“goMap”]->extent->maxy;

//set nilai $aVars dengan nilai parameter URL
if (sizeof($_POST) > 0) {
$aVars = $_POST;
} else {
if (sizeof($_GET) > 0) {
$aVars = $_GET;
} else {
$aVars = array();
}
}

//open database
$koneksi=mysql_connect(“localhost”,”root”,””) or die (mysql_error());
mysql_select_db(“kendaraan”,$koneksi);
$query1=mysql_query (“SELECT * FROM tampil”,$koneksi);
$row1=mysql_fetch_array($query1);
$id=$row1[id_kendaraan];
$query=mysql_query (“SELECT * FROM posisi where id_kendaraan= ‘$id’ order by id_posisi”,$koneksi);
$jumlah=mysql_num_rows($query);

while($row=mysql_fetch_array($query))
{
$data_x=$row[1];
$data_y=$row[2];

}
// Create another layer to hold point locations
$oLayerPoints = ms_newLayerObj($GLOBALS[“goMap”]);
$oLayerPoints->set( “name”, “kendaraan”);
$oLayerPoints->set( “type”, MS_LAYER_POINT);
$oLayerPoints->set( “status”, MS_DEFAULT);
$oLayerPoints->setMetaData( “description”,”Kendaraan” );

//Although we are creating points we are required to use a line object (newLineObj)
// with only one point. I call it a CoordList object for simplicity since we aren’t really drawing a line.
$oCoordList = ms_newLineObj();
$oPointShape = ms_newShapeObj(MS_SHAPE_POINT);
$oCoordList->addXY($data_x,$data_y);
$oPointShape->add($oCoordList);
$oLayerPoints->addFeature($oPointShape);

// Create a class object to set feature drawing styles.
$oMapClass = ms_newClassObj($oLayerPoints);

// Create a style object defining how to draw features
$oPointStyle = ms_newStyleObj($oMapClass);
$oPointStyle->color->setRGB(250,0,0);
$oPointStyle->outlinecolor->setRGB(255,255,255);
$oPointStyle->set( “symbolname”, “circle”);
$oPointStyle->set( “size”, “15”);

// Render the map into an image object
$oImg = $GLOBALS[“goMap”]->draw();
$url = $oImg->saveWebImage(MS_PNG, 1, 1, 0);

//tool navigasi default: zoom in
$GLOBALS[“gszCurrentTool”] = “ZOOM_IN”;
$GLOBALS[“gShowQueryResults”] = FALSE;

//proses parameter URL
ProcessURLArray( $aVars );
}

function DrawMap()
{
if ($GLOBALS[“gShowQueryResults”])
$img = $GLOBALS[“goMap”]->drawQuery();
else

$img = $GLOBALS[“goMap”]->draw();
$url = $img->saveWebImage();

$nWidth = $GLOBALS[“goMap”]->width;
$nHeight = $GLOBALS[“goMap”]->height;

echo “<INPUT TYPE=image SRC=”.$url.” BORDER=0 WIDTH=\””.
$nWidth.”\” HEIGHT=\””.$nHeight.”\” NAME=MAINMAP>\n”;
echo “<INPUT TYPE=HIDDEN NAME=MINX VALUE=\””.
$GLOBALS[“goMap”]->extent->minx.”\”>\n”;
echo “<INPUT TYPE=HIDDEN NAME=MINY VALUE=\””.
$GLOBALS[“goMap”]->extent->miny.”\”>\n”;
echo “<INPUT TYPE=HIDDEN NAME=MAXX VALUE=\””.
$GLOBALS[“goMap”]->extent->maxx.”\”>\n”;
echo “<INPUT TYPE=HIDDEN NAME=MAXY VALUE=\””.
$GLOBALS[“goMap”]->extent->maxy.”\”>\n”;
}

function DrawScaleBar()
{
$img = $GLOBALS[“goMap”]->drawScaleBar();
$url = $img->saveWebImage();

echo”<IMG SRC=$url BORDER=0>\n”;
}

function DrawLegend()
{
echo “<table cellspacing=0 cellpadding=0>”;
echo “<tr bgcolor=\”#E2EFF5\”>\n”;
echo “<td></td>\n”;
echo “<td></td>\n”;
echo “</tr>\n”;
echo $GLOBALS[“goMap”]->processLegendTemplate( array() );
echo “<tr>\n”;
echo “<td><input type=\”image\””.” src=\”./images/icon_update.gif\””.” width=\”20\” height=\”20\”></td>\n”;
echo “<td colspan=2>”.”<font face=\”Arial,Helvetica,sans-serif\” size=\”2\”>”.”Update</td>\n”;
echo “</tr>\n”;
echo “</table>”;
}

function DrawPointQueryResults()
{
if (!$GLOBALS[“gShowQueryResults”]) {
echo ” “;
} else {
$nResults = 0;
echo “<PRE>”;
echo “Kecamatan terpilih:\n”;
echo “——————\n”;
$oLayer = $GLOBALS[“goMap”]->getLayerByName(“Kecamatan”);
$nLayerResults = $oLayer->getNumResults();
if ($nLayerResults > 0) {
$oLayer->open();
$aField = explode(“;”, $oLayer->getMetaData(“RESULT_FIELDS”));
$aDesc = explode(“;”, $oLayer->getMetaData(“DESC_FIELDS”));
for ($i=0; $i<$nLayerResults; $i++) {
$oRes = $oLayer->getResult($i);
$oShape = $oLayer->getShape($oRes->tileindex, $oRes->shapeindex);
for ($j=0; $j<count($aField); $j++) {
echo $aDesc[$j].”: “;
echo $oShape->values[$aField[$j]].”\n”;
}
$oShape->free();
$nResults++;
}
$oLayer->close();
}

if ($nResults == 0) {
echo “Tidak ditemukan objek pada layer Propinsi.”;
}
echo “</PRE>”;
}
}

function DrawKeyMap()
{
$img = $GLOBALS[“goMap”]->drawreferencemap();
$url = $img->saveWebImage();

echo “<INPUT TYPE=image SRC=$url BORDER=1 NAME=KEYMAP>\n”;
}

function ProcessURLArray( $aVars)
{
//simpan tool navigasi yang sedang aktif
$GLOBALS[“gszCurrentTool”] = (isset($aVars[“CMD”])) ?
$aVars[“CMD”] : “ZOOM_IN”;

//set batas koordinat peta
$oExt = $GLOBALS[“goMap”];
$fMinX = isset($aVars[“MINX”]) ? $aVars[“MINX”] : $oExt->extent->minx;
$fMinY = isset($aVars[“MINY”]) ? $aVars[“MINY”] : $oExt->extent->miny;;
$fMaxX = isset($aVars[“MAXX”]) ? $aVars[“MAXX”] : $oExt->extent->maxx;;
$fMaxY = isset($aVars[“MAXY”]) ? $aVars[“MAXY”] : $oExt->extent->maxy;;
$GLOBALS[“goMap”]->setextent( $fMinX, $fMinY, $fMaxX, $fMaxY );

//lebar dan tinggi gambar peta
$fW = $GLOBALS[“goMap”]->width;
$fH = $GLOBALS[“goMap”]->height;

if (isset($_GET[“legendlayername”]))
{
for( $i=0; $i<$GLOBALS[“goMap”]->numlayers; $i++ )
{
$oLayer = $GLOBALS[“goMap”]->getLayer($i);
if (in_array( $oLayer->name, $_GET[“legendlayername”] ))
$oLayer->set( “status”, MS_ON );
else
$oLayer->set( “status”, MS_OFF );
}
}

//lakukan perubahan skala, sesuai tool navigasi terpilih
if (isset($aVars[“CMD”]) && isset ($aVars[“MAINMAP_x”])) {
//titik tempat user meng-klik pada lokasi peta
$nX = isset($aVars[“MAINMAP_x”]) ?
intval($aVars[“MAINMAP_x”]) : $fW/2.0;
$nY = isset($aVars[“MAINMAP_y”]) ?
intval($aVars[“MAINMAP_y”]) : $fW/2.0;

if (isset($aVars[“MAINMAP_x”]) && isset($aVars[“MAINMAP_y”])) {
$oPixelPos = ms_newpointobj();
$oPixelPos->setxy($nX, $nY);

$oGeoExt = ms_newrectobj();
$oGeoExt->setextent($fMinX, $fMinY, $fMaxX, $fMaxY);

//ubah skala peta, dengan method zoompoint atau setextent
if ($aVars[“CMD”] == “ZOOM_IN”) {
$GLOBALS[“goMap”]->zoompoint(2, $oPixelPos,
$fW, $fH, $oGeoExt);
} else if ($aVars[“CMD”] == “ZOOM_OUT”) {
$GLOBALS[“goMap”]->zoompoint(-2, $oPixelPos,
$fW, $fH, $oGeoExt);
} else if ($aVars[“CMD”] == “RECENTER”) {
$GLOBALS[“goMap”]->zoompoint(1, $oPixelPos,
$fW, $fH, $oGeoExt);
} else if ($aVars[“CMD”] == “ZOOM_ALL”) {
$GLOBALS[“goMap”]->setextent($GLOBALS[“gfMinX”],
$GLOBALS[“gfMinY”], $GLOBALS[“gfMaxX”],
$GLOBALS[“gfMaxY”]);
} else if ($aVars[“CMD”] == “QUERY”)
{
$nGeoX = Pix2Geo($nX, 0, $fW, $fMinX, $fMaxX, 0);
$nGeoY = Pix2Geo($nY, 0, $fH, $fMinY, $fMaxY, 1);

$oGeo = ms_newPointObj();
$oGeo->setXY($nGeoX, $nGeoY);

// Simbol ‘@’ digunakan supaya tidak muncul pesan peringatan
// ketika objek tidak ditemukan
@$GLOBALS[“goMap”]->queryByPoint($oGeo, MS_SINGLE, -1);

$GLOBALS[“gShowQueryResults”] = TRUE;
}
}
} else if (isset($aVars[“KEYMAP_x”]) && isset($aVars[“KEYMAP_y”])) {
$oRefExt = $GLOBALS[“goMap”]->reference->extent;

$nX = intval($aVars[“KEYMAP_x”]);
$nY = intval($aVars[“KEYMAP_y”]);

$fWidthPix = doubleval($GLOBALS[“goMap”]->reference->width);
$fHeightPix = doubleval($GLOBALS[“goMap”]->reference->height);

$nGeoX = Pix2Geo($nX, 0, $fWidthPix, $oRefExt->minx, $oRefExt->maxx, 0);
$nGeoY = Pix2Geo($nY, 0, $fHeightPix, $oRefExt->miny, $oRefExt->maxy, 1);

$fDeltaX = ($fMaxX – $fMinX) / 2.0;
$fDeltaY = ($fMaxY – $fMinY) / 2.0;

$GLOBALS[“goMap”]->setextent($nGeoX – $fDeltaX, $nGeoY – $fDeltaY,
$nGeoX + $fDeltaX, $nGeoY + $fDeltaY);
}

}

function Pix2Geo($nPixPos, $fPixMin, $fPixMax, $fGeoMin, $fGeoMax,
$bInversePix)
{
$fDeltaPix = ($bInversePix) ? $fPixMax – $nPixPos : $nPixPos – $fPixMin;

$fDeltaGeo = $fDeltaPix * ($fGeoMax – $fGeoMin) / ($fPixMax – $fPixMin);

return $fGeoMin + $fDeltaGeo;
}

function IsCurrentTool( $szTool )
{
return (strcasecmp($GLOBALS[“gszCurrentTool”], $szTool) == 0);
}

?>