Beispiel #1
0
/**
 * @param $mapfile
 * @param $corx
 * @param $cory
 * @param $minx
 * @param $maxx
 * @param $miny
 * @param $maxy
 * @param $xsize
 * @param $ysize
 * @param $layers
 * @param $labels
 * @param $zoom
 * @param bool $changeleg
 * @param int $corx2
 * @param int $cory2
 * @return xajaxResponse
 */
function map_redraw($mapfile, $corx, $cory, $minx, $maxx, $miny, $maxy, $xsize, $ysize, $layers, $labels, $zoom, $changeleg = false, $corx2 = 0, $cory2 = 0)
{
    global $prefs;
    $objResponse = new xajaxResponse();
    if (strstr($mapfile, '..')) {
        $msg = tra('You do not have permission to do that');
        $objResponse->alert($msg);
        return $objResponse;
    }
    $prefs['map_path'] = preg_replace('/\\/?$/', '/', $prefs['map_path']);
    //checking the mapfile
    if (!is_file($prefs['map_path'] . $mapfile) || preg_match('/(\\/\\.)/', $prefs['map_path'] . $mapfile)) {
        $msg = tra('invalid mapfile name');
        $objResponse->alert($msg);
        return $objResponse;
    }
    $map = ms_newMapObj($prefs['map_path'] . $mapfile);
    for ($j = 0; $j < $map->numlayers; $j++) {
        $my_layer = $map->getLayer($j);
        if ($layers[$j] == 'true') {
            $my_layer->set('status', MS_ON);
        } else {
            $my_layer->set('status', MS_OFF);
        }
        if ($labels[$j] == 'false') {
            $my_layer->set('labelmaxscale', 0);
        }
    }
    $map->Set('width', $xsize);
    $map->Set('height', $ysize);
    $my_point = ms_newpointObj();
    if ($zoom == 3) {
        $my_point->setXY($map->width / 2, $map->height / 2);
    } else {
        $my_point->setXY(floor($corx), floor($cory));
    }
    $my_extent = ms_newrectObj();
    $my_extent->setextent($minx, $miny, $maxx, $maxy);
    $result = '';
    if ($zoom == 3) {
        $map->zoompoint(1, $my_point, $map->width, $map->height, $my_extent);
        $result = map_query($map, $corx, $cory);
    } elseif ($zoom == 5) {
        $my_rect = ms_newrectObj();
        $my_rect->setextent($corx, $cory, $corx2, $cory2);
        $map->zoomrectangle($my_rect, $map->width, $map->height, $my_extent);
        $objResponse->assign('minx', 'value', $map->extent->minx);
        $objResponse->assign('miny', 'value', $map->extent->miny);
        $objResponse->assign('maxx', 'value', $map->extent->maxx);
        $objResponse->assign('maxy', 'value', $map->extent->maxy);
        $objResponse->assign('map', 'style.cursor', 'default');
        $objResponse->assign('zoomselect', 'style.visibility', 'hidden');
        $objResponse->script("xMoveTo(xGetElementById('map'),0,0);");
        $objResponse->script('minx=' . $map->extent->minx . ';');
        $objResponse->script('miny=' . $map->extent->miny . ';');
        $objResponse->script('maxx=' . $map->extent->maxx . ';');
        $objResponse->script('maxy=' . $map->extent->maxy . ';');
    } else {
        $map->zoompoint(1, $my_point, $map->width, $map->height, $my_extent);
        $objResponse->assign('minx', 'value', $map->extent->minx);
        $objResponse->assign('miny', 'value', $map->extent->miny);
        $objResponse->assign('maxx', 'value', $map->extent->maxx);
        $objResponse->assign('maxy', 'value', $map->extent->maxy);
        $objResponse->assign('map', 'style.cursor', 'move');
        $objResponse->script("xMoveTo(xGetElementById('map'),0,0);");
        $objResponse->script('minx=' . $map->extent->minx . ';');
        $objResponse->script('miny=' . $map->extent->miny . ';');
        $objResponse->script('maxx=' . $map->extent->maxx . ';');
        $objResponse->script('maxy=' . $map->extent->maxy . ';');
    }
    $image = $map->drawquery();
    $image_url = $image->saveWebImage();
    if ($zoom != 3) {
        $image_ref = $map->drawReferenceMap();
        $image_ref_url = $image_ref->saveWebImage();
        $image_ref->free();
    }
    if ($changeleg) {
        $image_leg = $map->drawLegend();
        $image_leg_url = $image_leg->saveWebImage();
        $image_leg->free();
    }
    if ($zoom == 2 || $zoom == 5) {
        $image_scale = $map->drawScaleBar();
        $image_scale_url = $image_scale->saveWebImage();
        $image_scale->free();
    }
    $image->free();
    $objResponse->assign('innerBoxContent', 'innerHTML', $result);
    $objResponse->assign('resultBox', 'innerHTML', $result);
    $objResponse->assign('map', 'src', $image_url);
    if ($zoom != 3) {
        $objResponse->assign('ref', 'src', $image_ref_url);
    }
    if ($zoom == 2 || $zoom == 5) {
        $objResponse->assign('scale', 'src', $image_scale_url);
    }
    if ($changeleg) {
        $objResponse->assign('leg', 'src', $image_leg_url);
    }
    return $objResponse;
}
Beispiel #2
0
        } else {
            $my_layers_label_checked[$j] = "";
            $my_layer->Set("labelmaxscale", 0);
        }
    } else {
        $layer_label[$j] = "Off";
    }
    if ($my_layer->tolerance != -1) {
        $layer_query[$j] = "On";
    } else {
        $layer_query[$j] = "Off";
    }
}
// We have a query so let's get the results.
if ($query) {
    $map_querymsg = map_query($map, $corx, $cory);
    $smarty->assign('map_querymsg', $map_querymsg);
}
if (@$_REQUEST['maponly'] == 'frame') {
    $scalebar = $map->scalebar;
    $scalebar->set("status", MS_EMBED);
    $scalebar->set("transparent", TRUE);
}
$image = $map->drawquery();
$image_url = $image->saveWebImage();
//the user wants an image only
if (isset($_REQUEST['maponly']) && $_REQUEST['maponly'] == 'yes') {
    header("Content-type: image/png");
    $image_file = str_replace($image->imageurl, $image->imagepath, $image_url);
    readfile($image_file);
    $image->free();
    }
    echo json_encode(array("Locations" => $points));
    exit;
}
// Save a point from our form
if ($_POST['action'] == 'savepoint') {
    $name = $_POST['name'];
    if (preg_match('/[^\\w\\s]/i', $name)) {
        fail('Invalid name provided.');
    }
    if (empty($name)) {
        fail('Please enter a name.');
    }
    // Query
    $query = "INSERT INTO locations SET name='{$_POST['name']}', lat='{$_POST['lat']}', lng='{$_POST['lng']}', ip='{$ip}'";
    $result = map_query($query);
    if ($result) {
        success(array('lat' => $_POST['lat'], 'lng' => $_POST['lng'], 'name' => $name));
    } else {
        fail('Failed to add point.');
    }
    exit;
}
function map_query($query)
{
    // Connect
    mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die(fail('Could not connect to database.'));
    mysql_select_db('mysql_database');
    return mysql_query($query);
}
function fail($message)
Beispiel #4
0
function map_redraw($mapfile, $corx, $cory, $minx, $maxx, $miny, $maxy, $xsize, $ysize, $layers, $labels, $zoom, $changeleg = false, $corx2 = 0, $cory2 = 0)
{
    global $prefs;
    $objResponse = new xajaxResponse();
    if (strstr($mapfile, '..')) {
        $msg = tra("You do not have permission to do that");
        $objResponse->addAlert($msg);
        return $objResponse;
    }
    $prefs['map_path'] = preg_replace("/\\/?\$/", "/", $prefs['map_path']);
    //checking the mapfile
    if (!is_file($prefs['map_path'] . $mapfile) || preg_match("/(\\/\\.)/", $prefs['map_path'] . $mapfile)) {
        $msg = tra("invalid mapfile name");
        $objResponse->addAlert($msg);
        return $objResponse;
    }
    $map = ms_newMapObj($prefs['map_path'] . $mapfile);
    for ($j = 0; $j < $map->numlayers; $j++) {
        $my_layer = $map->getLayer($j);
        if ($layers[$j] == "true") {
            $my_layer->set("status", MS_ON);
        } else {
            $my_layer->set("status", MS_OFF);
        }
        if ($labels[$j] == "false") {
            $my_layer->set("labelmaxscale", 0);
        }
    }
    $map->Set("width", $xsize);
    $map->Set("height", $ysize);
    $my_point = ms_newpointObj();
    if ($zoom == 3) {
        $my_point->setXY($map->width / 2, $map->height / 2);
    } else {
        $my_point->setXY(floor($corx), floor($cory));
    }
    $my_extent = ms_newrectObj();
    $my_extent->setextent($minx, $miny, $maxx, $maxy);
    $result = "";
    if ($zoom == 3) {
        $map->zoompoint(1, $my_point, $map->width, $map->height, $my_extent);
        $result = map_query($map, $corx, $cory);
    } elseif ($zoom == 5) {
        $my_rect = ms_newrectObj();
        $my_rect->setextent($corx, $cory, $corx2, $cory2);
        $map->zoomrectangle($my_rect, $map->width, $map->height, $my_extent);
        $objResponse->addAssign("minx", "value", $map->extent->minx);
        $objResponse->addAssign("miny", "value", $map->extent->miny);
        $objResponse->addAssign("maxx", "value", $map->extent->maxx);
        $objResponse->addAssign("maxy", "value", $map->extent->maxy);
        $objResponse->addAssign("map", "style.cursor", "default");
        $objResponse->addAssign("zoomselect", "style.visibility", "hidden");
        $objResponse->addScript("xMoveTo(xGetElementById('map'),0,0);");
        $objResponse->addScript("minx=" . $map->extent->minx . ";");
        $objResponse->addScript("miny=" . $map->extent->miny . ";");
        $objResponse->addScript("maxx=" . $map->extent->maxx . ";");
        $objResponse->addScript("maxy=" . $map->extent->maxy . ";");
    } else {
        $map->zoompoint(1, $my_point, $map->width, $map->height, $my_extent);
        $objResponse->addAssign("minx", "value", $map->extent->minx);
        $objResponse->addAssign("miny", "value", $map->extent->miny);
        $objResponse->addAssign("maxx", "value", $map->extent->maxx);
        $objResponse->addAssign("maxy", "value", $map->extent->maxy);
        $objResponse->addAssign("map", "style.cursor", "move");
        $objResponse->addScript("xMoveTo(xGetElementById('map'),0,0);");
        $objResponse->addScript("minx=" . $map->extent->minx . ";");
        $objResponse->addScript("miny=" . $map->extent->miny . ";");
        $objResponse->addScript("maxx=" . $map->extent->maxx . ";");
        $objResponse->addScript("maxy=" . $map->extent->maxy . ";");
    }
    $image = $map->drawquery();
    $image_url = $image->saveWebImage();
    if ($zoom != 3) {
        $image_ref = $map->drawReferenceMap();
        $image_ref_url = $image_ref->saveWebImage();
        $image_ref->free();
    }
    if ($changeleg) {
        $image_leg = $map->drawLegend();
        $image_leg_url = $image_leg->saveWebImage();
        $image_leg->free();
    }
    if ($zoom == 2 || $zoom == 5) {
        $image_scale = $map->drawScaleBar();
        $image_scale_url = $image_scale->saveWebImage();
        $image_scale->free();
    }
    $image->free();
    $objResponse->addAssign("innerBoxContent", "innerHTML", $result);
    $objResponse->addAssign("resultBox", "innerHTML", $result);
    $objResponse->addAssign("map", "src", $image_url);
    if ($zoom != 3) {
        $objResponse->addAssign("ref", "src", $image_ref_url);
    }
    if ($zoom == 2 || $zoom == 5) {
        $objResponse->addAssign("scale", "src", $image_scale_url);
    }
    if ($changeleg) {
        $objResponse->addAssign("leg", "src", $image_leg_url);
    }
    return $objResponse;
}