hi folks,
<br>
<br>i've used the mapserver cgi for about 4 years, and only started using mapscript recently. &nbsp;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. &nbsp; 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? &nbsp;can anyone help me to get to the next step? &nbsp; 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>&gt;&gt;&gt;apologies for code that follows (& &quot;img src&quot; is changed to &quot;image src&quot;)&gt;&gt;&gt;
<br>
<br>&lt;?php
<br>
<br>/* factor for query */
<br>$beg_yr = &quot;800&quot;;
<br>$end_yr = &quot;1000&quot;;
<br>
<br>/* connect to mysql */
<br>$connect = @mysql_connect(&quot;$host&quot;, &quot;$user&quot;, &quot;$password&quot;);
<br>
<br>/* grab the point data from mysql table */
<br>@mysql_select_db(&quot;$dbase&quot;);
<br>$query = &quot; SELECT * FROM table WHERE beg_yr&gt;$beg_yr and end_yr&lt;$end_yr &quot;;
<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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>/* set default variables */
<br>$val_zsize=3;
<br>$check_pan=&quot;CHECKED&quot;;
<br>$map_path=&quot;/path/to/mapfile/&quot;;
<br>$host=&quot;<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>&quot;;
<br>
<br>/* start up the mapscript process */
<br>$map = ms_newMapObj($map_path.&quot;mapfile.map&quot;);
<br>$image=$map-&gt;draw();
<br>
<br>$this_layer = $map-&gt;getLayerByName('sites');
<br>$this_layer-&gt;set('status', MS_ON);
<br>
<br>while ($site = mysql_fetch_assoc($result)){ 
<br>
<br>&nbsp; &nbsp;$mypoint = ms_newPointObj();
<br>&nbsp; &nbsp;$mypoint-&gt;setXY($site['point_x_coord'],$site['point_y_coord']);
<br>&nbsp; &nbsp;$pt_id = $site['point_id'];
<br>&nbsp; &nbsp;$mypoint-&gt;draw($map, $this_layer, $image, 0, &quot;$pt_id&quot;);
<br>} 
<br>
<br>mysql_free_result($result);
<br>
<br>/* get the extents and set up drawing objects*/
<br>if ( isset($HTTP_POST_VARS[&quot;mapa_x&quot;]) && isset($HTTP_POST_VARS[&quot;mapa_y&quot;])
<br>&nbsp; &nbsp; &nbsp; && !isset($HTTP_POST_VARS[&quot;full&quot;]) ) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $extent_to_set = explode(&quot; &quot;,$HTTP_POST_VARS[&quot;extent&quot;]); 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $map-&gt;setextent($extent_to_set[0],$extent_to_set[1],
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $extent_to_set[2],$extent_to_set[3]);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $my_point = ms_newpointObj();
<br>&nbsp; &nbsp; &nbsp; $my_point-&gt;setXY($HTTP_POST_VARS[&quot;mapa_x&quot;],$HTTP_POST_VARS[&quot;mapa_y&quot;]);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $my_extent = ms_newrectObj();
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $my_extent-&gt;setextent($extent_to_set[0],$extent_to_set[1],
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $extent_to_set[2],$extent_to_set[3]);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $zoom_factor = $HTTP_POST_VARS[&quot;zoom&quot;]*$HTTP_POST_VARS[&quot;zsize&quot;];
<br>&nbsp; &nbsp; &nbsp; if ($zoom_factor == 0) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $zoom_factor = 1;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_pan = &quot;CHECKED&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zout = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zin = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; } else if ($zoom_factor &lt;&nbsp;0) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_pan = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zout = &quot;CHECKED&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zin = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; } else {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_pan = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zout = &quot;&quot;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $check_zin = &quot;CHECKED&quot;;
<br>&nbsp; &nbsp; &nbsp; }
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $val_zsize = abs($zoom_factor);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; $map-&gt;zoompoint($zoom_factor,$my_point,$map-&gt;width,$map-&gt;height,
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $my_extent);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp;}
<br>
<br>
<br>/* draw the images to cache */
<br>$map-&gt;drawLabelCache($image); 
<br>$image_url=$image-&gt;saveWebImage();
<br>
<br>&nbsp;$extent_to_html = $map-&gt;extent-&gt;minx.&quot; &quot;.$map-&gt;extent-&gt;miny.&quot; &quot;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .$map-&gt;extent-&gt;maxx.&quot; &quot;.$map-&gt;extent-&gt;maxy;
<br>
<br>$scale_img = $map-&gt;drawScaleBar();
<br>$scale_url = $scale_img-&gt;saveWebImage();
<br>
<br>$ref_img = $map-&gt;drawReferenceMap();
<br>$ref_url = $ref_img-&gt;saveWebImage();
<br>
<br>$leg_img = $map-&gt;drawLegend();
<br>$leg_url = $leg_img-&gt;saveWebImage();
<br>
<br>
<br>?&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&lt;html&gt;
<br>&lt;head&gt;&lt;title&gt;point mapping from database&lt;/title&gt;
<br>
<br>/* set up jbox */
<br>&nbsp; &nbsp; &nbsp; &lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; function setbox_handler(name, minx, miny, maxx, maxy) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.mapserv.imgbox.value = minx + &quot; &quot; + miny + &quot; &quot; + maxx + &quot; &quot; + maxy;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.mapserv.imgxy.value = minx + &quot; &quot; + miny;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Additional code can go here prior to the form submit, below.
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // For example, form validation code.
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.mapserv.submit();
<br>&nbsp; &nbsp; &nbsp; &nbsp; }
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; function seterror_handler(message) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(message);
<br>&nbsp; &nbsp; &nbsp; &nbsp; }
<br>
<br>&nbsp; &nbsp; &nbsp; &lt;/SCRIPT&gt;
<br>
<br>&lt;/head&gt;
<br>&lt;META http-equiv=Content-Type content=&quot;text/html; charset=utf-8&quot;&gt;
<br>&lt;body&gt;
<br>
<br>/* falling back on CGI template */
<br>
<br>&lt;form name=&quot;mapserv&quot; method=GET action=&quot;/cgi-bin/mapserv&quot;&gt;
<br>
<br>&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;map&quot; value=&quot;&lt;?php echo $map_path.&quot;mapfile.map&quot; ?&gt;&quot;&gt;
<br>&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;imgext&quot; value=&quot;&lt;?php echo $extent_to_html ?&gt;&quot;&gt;
<br>&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;imgxy&quot; value=&quot;299.5 224.5&quot;&gt;
<br>&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;savequery&quot; value=&quot;true&quot;&gt;
<br>&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;imgbox&quot; value=&quot;-1 -1 -1 -1&quot;&gt;
<br>
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;applet 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; codebase=&quot;/misc/java&quot;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; code=&quot;jBox.class&quot;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; archive=&quot;jBox.jar&quot;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width=&quot;600&quot;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height=&quot;450&quot; 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=&quot;jBox&quot; 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MAYSCRIPT&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param name=&quot;image&quot; value=&quot;&lt;?php echo &quot;<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>&quot;.$image_url; ?&gt;&quot;&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;param name='drag' value=&quot;+drag+&quot;&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;param name='box' value=&quot;+box+&quot;&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;param name='verbose' value='false'&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;param name='thickness' value='2'&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/applet&gt;
<br>
<br>
<br>&lt;p&gt;scalebar:&lt;br&gt;
<br>&lt;image src=&quot;&lt;? php echo &quot;<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>&quot;.$scale_url; ?&gt;&quot;&gt;
<br>
<br>&lt;hr&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; value=&quot;Refresh Map&quot;&gt;&lt;p&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; select mode:&lt;br&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;radio&quot; name=&quot;mode&quot; value=&quot;browse&quot; CHECKED&gt; zoom&lt;br&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;radio&quot; name=&quot;mode&quot; value=&quot;nquery&quot;&gt; query feature&lt;br&gt;
<br>
<br>&lt;p&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;select zoom factors:&lt;br&gt;
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp;Recenter &lt;font size=-2&gt;(click on map)&lt;font size=-1&gt;&lt;input type=radio name=zoomdir value=0 &nbsp;&lt;?php echo $check_pan?&gt; [zoomdir_0_check]&gt;&lt;br&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp;Zoom In &lt;font size=-2&gt;(click or drag box)&lt;font size=-1&gt; &lt;input type=radio name=zoomdir value=1 &lt;?php echo $check_zin?&gt; [zoomdir_1_check]&gt;&lt;br&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp;Zoom Out &lt;input type=radio name=zoomdir value=-1 &lt;?php echo $check_zout?&gt; [zoomdir_-1_check]&gt;&lt;br&gt;
<br>&nbsp; &nbsp; &nbsp; &nbsp;Zoom Size &lt;input typed=hidden name=zoomsize size=2 value=&quot;&lt;?php echo $val_zsize?&gt;&quot;&gt;
<br>
<br>&lt;/form&gt;
<br>
<br>&lt;p&gt;
<br>&lt;image src=&quot;&lt;? php echo &quot;<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>&quot;.$ref_url; ? &gt;&quot;&gt;
<br>
<br>&lt;p&gt;
<br>&lt;image src=&quot;&lt;? php echo &quot;<a href="http://blah.foo.edu" target="_top" rel="nofollow">http://blah.foo.edu</a>&quot;.$leg_url; ? &gt;&quot;&gt;
<br>
<br>&lt;/body&gt;&lt;/html&gt;
<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.