Dear All,<br><br> I am Venkat,I have one problem that is "how to work with Query Map".How to get zoom to shape.I have done some code getting extents for shape and set extents for shape(The complete Envelop of shape) with that i have done some code that is set extents for shape <br>
Ex :-<br> lyar = map.getLayerByName("Continents");<br> if (ddlContinents.SelectedIndex.ToString() == "0") //dropdownbox filtering <br> { map.setExtent(-25.36055756, -34.82200241, 63.49575806, 37.34041214); } //shape extents<br>
<br> But i have 3000 plues shapes .I can not write code for each and every shape.code will be very big and complicated.<br><br> I got some sample code in Mapserver5.0.but is Console Application.I have modified that application.I am getting error. "object not initialized" <br>
<br> Please anyone can help me how to use "Query Map" sample code.<br><br>Here is Sample code for Query Map :-<br><br> private static bool IsLayerQueryable(layerObj layer)<br> {<br> if (layer.type == MS_LAYER_TYPE.MS_LAYER_TILEINDEX)<br>
return false;<br><br> if (layer.template != null && layer.template.Length > 0) return true;<br><br> for (int i = 0; i < layer.numclasses; i++)<br> {<br> if (layer.getClass(i).template != null && layer.getClass(i).template.Length > 0)<br>
return true;<br> }<br> return false;<br> }<br><br> public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)<br> {<br> <br> try<br> {<br> layerObj layer;<br>
rectObj query_bounds = null;<br> for (int i = 0; i < map.numlayers; i++)<br> {<br> layer = map.getLayer(i);<br> if (layer.connection != null && IsLayerQueryable(layer))<br>
{<br> MessageBox.Show("Layer [" + i + "] name: " + <a href="http://layer.name">layer.name</a>);<br> BuildQuery(layer, qstring);<br> // zoom to the query results<br>
using (resultCacheObj results = layer.getResults())<br> {<br> if (results != null && results.numresults > 0)<br> {<br> // calculating the extent of the results<br>
if (query_bounds == null)<br> query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,<br> results.bounds.maxx, results.bounds.maxy, 0);<br>
else<br> {<br> if (results.bounds.minx < query_bounds.minx) query_bounds.minx = results.bounds.minx;<br> if (results.bounds.miny < query_bounds.miny) query_bounds.miny = results.bounds.miny;<br>
if (results.bounds.maxx > query_bounds.maxx) query_bounds.maxx = results.bounds.maxx;<br> if (results.bounds.maxy > query_bounds.maxy) query_bounds.maxy = results.bounds.maxy;<br>
}<br> }<br> }<br> }<br> }<br> // setting the map extent to the result bounds<br> if (zoomToResults)<br>
{<br> map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);<br> MessageBox.Show("Current map scale: 1:" + (int)map.scaledenom);<br> }<br>
}<br> catch (Exception e)<br> {<br> MessageBox.Show("QueryByAttribute: " + e.Message);<br> }<br> }<br><br> private static void BuildQuery(layerObj layer, string qstring)<br>
{<br> if (layer != null && layer.map != null)<br> {<br><br> string qs = qstring;<br> string att = null;<br><br> MessageBox.Show("Query string: " + qs);<br>
<br> try<br> {<br> layer.queryByAttributes(layer.map, att, qs, 1);<br> }<br> catch (Exception e)<br> {<br> MessageBox.Show("BuildQuery: " + e.Message);<br>
}<br> }<br> }<br> protected void Button1_Click(object sender, EventArgs e)<br> {<br> bool ZoomToResults = true;<br><br><br> QueryByAttribute("India",map, ZoomToResults);<br>
<br> map.querymap.status = mapscript.MS_ON;<br> map.querymap.color.setRGB(0, 0, 255);<br> map.querymap.style = (int)MS_QUERYMAP_STYLES.MS_HILITE;<br> }<br><br>Thanks And Regards,<br>Venkat.<br>