hi folks,
<br>
<br>i've used the mapserver cgi for about 4 years, and only started using mapscript recently. although i managed to grab some points from a mysql table and throw them on top of a map (along with labels from the same table), i have no idea how to save that query for subsequent zooming in / out / panning or trying to do an nquery.
<br>
<br>what i did was to cobble together the mapscript call to mysql and draw new objects then put them into the old CGI template along with JBOX. needless to say, I can draw the first map with my points retreived from mysql, but if i click on the map to zoom or query the database points are lost.
<br>
<br>there must be a sort of mapscript - integrated way of doing this, isn't there? can anyone help me to get to the next step? what i am hoping to do somehow is to be able to query both the items from mysql points layer and the shapefiles called from the mapfile at the same time, or if that is impossible then at least to preserve and to SEE the layer from the database for reference purposes while being able to browse and query the shapefiles in the mapserver.
<br>
<br>>>>apologies for code that follows (& "img src" is changed to "image src")>>>
<br>
<br><?php
<br>
<br>/* factor for query */
<br>$beg_yr = "800";
<br>$end_yr = "1000";
<br>
<br>/* connect to mysql */
<br>$connect = @mysql_connect("$host", "$user", "$password");
<br>
<br>/* grab the point data from mysql table */
<br>@mysql_select_db("$dbase");
<br>$query = " SELECT * FROM table WHERE beg_yr>$beg_yr and end_yr<$end_yr ";
<br>
<br>$result = mysql_query($query) or die(mysql_error());
<br>$numrows = mysql_num_rows($result);
<br>
<br>/* fire up mapscript */
<br>dl('php_mapscript.so');
<br>
<br>/* set default variables */
<br>$val_zsize=3;
<br>$check_pan="CHECKED";
<br>$map_path="/path/to/mapfile/";
<br>$host="<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>";
<br>
<br>/* start up the mapscript process */
<br>$map = ms_newMapObj($map_path."mapfile.map");
<br>$image=$map->draw();
<br>
<br>$this_layer = $map->getLayerByName('sites');
<br>$this_layer->set('status', MS_ON);
<br>
<br>while ($site = mysql_fetch_assoc($result)){
<br>
<br> $mypoint = ms_newPointObj();
<br> $mypoint->setXY($site['point_x_coord'],$site['point_y_coord']);
<br> $pt_id = $site['point_id'];
<br> $mypoint->draw($map, $this_layer, $image, 0, "$pt_id");
<br>}
<br>
<br>mysql_free_result($result);
<br>
<br>/* get the extents and set up drawing objects*/
<br>if ( isset($HTTP_POST_VARS["mapa_x"]) && isset($HTTP_POST_VARS["mapa_y"])
<br> && !isset($HTTP_POST_VARS["full"]) ) {
<br>
<br> $extent_to_set = explode(" ",$HTTP_POST_VARS["extent"]);
<br>
<br> $map->setextent($extent_to_set[0],$extent_to_set[1],
<br> $extent_to_set[2],$extent_to_set[3]);
<br>
<br> $my_point = ms_newpointObj();
<br> $my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);
<br>
<br> $my_extent = ms_newrectObj();
<br>
<br> $my_extent->setextent($extent_to_set[0],$extent_to_set[1],
<br> $extent_to_set[2],$extent_to_set[3]);
<br>
<br> $zoom_factor = $HTTP_POST_VARS["zoom"]*$HTTP_POST_VARS["zsize"];
<br> if ($zoom_factor == 0) {
<br> $zoom_factor = 1;
<br> $check_pan = "CHECKED";
<br> $check_zout = "";
<br> $check_zin = "";
<br> } else if ($zoom_factor < 0) {
<br> $check_pan = "";
<br> $check_zout = "CHECKED";
<br> $check_zin = "";
<br> } else {
<br> $check_pan = "";
<br> $check_zout = "";
<br> $check_zin = "CHECKED";
<br> }
<br>
<br> $val_zsize = abs($zoom_factor);
<br>
<br> $map->zoompoint($zoom_factor,$my_point,$map->width,$map->height,
<br> $my_extent);
<br>
<br> }
<br>
<br>
<br>/* draw the images to cache */
<br>$map->drawLabelCache($image);
<br>$image_url=$image->saveWebImage();
<br>
<br> $extent_to_html = $map->extent->minx." ".$map->extent->miny." "
<br> .$map->extent->maxx." ".$map->extent->maxy;
<br>
<br>$scale_img = $map->drawScaleBar();
<br>$scale_url = $scale_img->saveWebImage();
<br>
<br>$ref_img = $map->drawReferenceMap();
<br>$ref_url = $ref_img->saveWebImage();
<br>
<br>$leg_img = $map->drawLegend();
<br>$leg_url = $leg_img->saveWebImage();
<br>
<br>
<br>?>
<br>
<br><html>
<br><head><title>point mapping from database</title>
<br>
<br>/* set up jbox */
<br> <SCRIPT LANGUAGE="JavaScript">
<br>
<br> function setbox_handler(name, minx, miny, maxx, maxy) {
<br> document.mapserv.imgbox.value = minx + " " + miny + " " + maxx + " " + maxy;
<br> document.mapserv.imgxy.value = minx + " " + miny;
<br> // Additional code can go here prior to the form submit, below.
<br> // For example, form validation code.
<br> document.mapserv.submit();
<br> }
<br>
<br> function seterror_handler(message) {
<br> alert(message);
<br> }
<br>
<br> </SCRIPT>
<br>
<br></head>
<br><META http-equiv=Content-Type content="text/html; charset=utf-8">
<br><body>
<br>
<br>/* falling back on CGI template */
<br>
<br><form name="mapserv" method=GET action="/cgi-bin/mapserv">
<br>
<br> <input type="hidden" name="map" value="<?php echo $map_path."mapfile.map" ?>">
<br> <input type="hidden" name="imgext" value="<?php echo $extent_to_html ?>">
<br> <input type="hidden" name="imgxy" value="299.5 224.5">
<br> <input type="hidden" name="savequery" value="true">
<br> <input type="hidden" name="imgbox" value="-1 -1 -1 -1">
<br>
<br>
<br> <applet
<br> codebase="/misc/java"
<br> code="jBox.class"
<br> archive="jBox.jar"
<br> width="600"
<br> height="450"
<br> name="jBox"
<br> MAYSCRIPT>
<br> <param name="image" value="<?php echo "<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>".$image_url; ?>">
<br> <param name='drag' value="+drag+">
<br> <param name='box' value="+box+">
<br> <param name='verbose' value='false'>
<br> <param name='thickness' value='2'>
<br>
<br> </applet>
<br>
<br>
<br><p>scalebar:<br>
<br><image src="<? php echo "<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>".$scale_url; ?>">
<br>
<br><hr>
<br>
<br> <input type="submit" value="Refresh Map"><p>
<br>
<br> select mode:<br>
<br>
<br> <input type="radio" name="mode" value="browse" CHECKED> zoom<br>
<br> <input type="radio" name="mode" value="nquery"> query feature<br>
<br>
<br><p>
<br> select zoom factors:<br>
<br>
<br> Recenter <font size=-2>(click on map)<font size=-1><input type=radio name=zoomdir value=0 <?php echo $check_pan?> [zoomdir_0_check]><br>
<br> Zoom In <font size=-2>(click or drag box)<font size=-1> <input type=radio name=zoomdir value=1 <?php echo $check_zin?> [zoomdir_1_check]><br>
<br> Zoom Out <input type=radio name=zoomdir value=-1 <?php echo $check_zout?> [zoomdir_-1_check]><br>
<br> Zoom Size <input typed=hidden name=zoomsize size=2 value="<?php echo $val_zsize?>">
<br>
<br></form>
<br>
<br><p>
<br><image src="<? php echo "<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>".$ref_url; ? >">
<br>
<br><p>
<br><image src="<? php echo "<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>".$leg_url; ? >">
<br>
<br></body></html>
<br>
<br><hr align="left" width="300">
View this message in context: <a href="http://www.nabble.com/mapscript---map-query-based-on-points-from-mysql-t898123.html#a2328043">mapscript - map query based on points from mysql</a><br>
Sent from the <a href="http://www.nabble.com/Mapserver---User-f1215.html">Mapserver - User</a> forum at Nabble.com.