[mapserver-users] ASP Implementation Notes (re-post from 10/23)

Richard Greenwood Rich at GreenwoodMap.com
Thu Dec 6 13:30:15 EST 2001


Ed,

Thanks for sharing you ASP knowledge and for providing such a detailed 
example. Another way to do pretty much the same thing is:
     mapserver.exe QUERY_STRING=xxxxxxxxxxxx
This allows you to run mapserver from the command prompt without calling it 
from a httpd, although I don't know if it is considered a supported 
interface (Steve?). Basic ASP doesn't let you execute external commands but 
www.serverobjects.com has a free tool that provides that ability.

Another very general comment on using ASP and MapServer together - there's 
nothing wrong with mixing ASP and CGI pages on the same site. e.g. I have a 
series of reports that are generated by user queries against a SQL Server 
database and displayed in ASP pages. The user can click a line in the 
report which calls MapServer with appropriate parameters to map the record 
the user clicked.

Rich

At 08:57 AM 12/6/2001 -0500, you wrote:
>Folks -
>
>The current thread about ASP implementation issues with MapServer
>prompts me to provide a few ideas for folks struggling in that
>direction.
>
>One of the great benefits of MapServer is its ability to provide a LOT
>of power and capability to users who are NOT using a scripting
>environment such as PHP or ASP or whatever.  The ability to echo state
>information into form variables gives you lots of flexibility.
>
>On the other hand, if you ARE using a scripting environment, this
>capability will get in your way.  You don't hear problems from people
>using PHP asking how to make MapServer generate PHP output.  Why?
>Because they don't think of the problem that way.  They use MapScript to
>control the operation of MapServer externally (not the mapserv binary
>exactly, but you get the point).
>
>There are some pretty simple things you can do to make life easier in
>the ASP environment.  It would be great to have an ASP-style MapScript
>someday, but there's a lot you can do right now.
>
>First, make sure your ASP environment is "on top".  That is, you're
>going to use an ASP page to direct MapServer, not use MapServer to
>generate ASP.
>
>Second, don't use MapServer to do things you can do yourself in ASP.  A
>lot of what MapServer does with template files is help to preserve state
>information.  An HTML form can be pre-filled with lots of settings that
>simply reflect the current mapping state, so it's easy to let the user
>make a few modifications and make a new map (i.e. resubmit the form).
>But you don't need that in an ASP environment!  You can remember what
>your parameters were, no?
>
>Here's a very simple example that might help ASP developers think
>differently (with apologies to Apple).  Let's start with getting a layer
>name from my ASP parameters.  The URL being processed here is:
>
>http://myserver.com/iwanttouse.asp?mybaselayer=BASEMAP
>
>Here's how to start:
>
><%
>         layername = Request.QueryString ("mybaselayer")
>%>
>
>I can pull off any other useful parameters from my ASP querystring that
>I like.  They don't have to be MapServer parameters - I just get enough
>info to describe the map I want in any format that's convenient and
>appropriate for the application.  I can then generate the MapServer
>querystring myself.
>
>Although there are several ways to do the next step, I then use a nice
>little component called ASPHTTP (www.serverobjects.com) that lets you
>submit HTTP requests and get the results back in a string variable.  So
>to submit a request to MapServer and get the results back in a VBScript
>string, you can do this:
>
><%
>'
>'       mapServerURL has been set to the complete MapServer querystring,
>adding the
>'       layername I extracted from the ASP page parameters:
>'
>         mapServerURL =
>"http://myserver.com/cgi-bin/mapserv.exe?map=mymapfile.map&layer=" &
>layername
>'
>'       Issue that HTTP GET request and retrieve the HTML MapServer
>returns into a string variable
>'
>         Set httpObj = Server.CreateObject("AspHTTP.Conn")       ' Create
>the object
>         HTTPObj.Url = mapServerURL
>' Set the URL
>         mapServerHTML = HTTPObj.GetURL                          ' Issue
>HTTP GET and store output in mapServerHTML
>         Set httpObj = Nothing
>%>
>
>Now the string mapServerHTML has the complete HTML generated by
>MapServer from your TEMPLATE file.  That's nice, you say, but what do I
>do with that big HTML file now?  You do very little, because you don't
>have a big HTML file.  Your HTML file, generated by MapServer, and now
>resident inside the string mapServerHTML, looks like this:
>
><!-- MapServer header line -->
>/tmp/Map123.jpg|/tmp/MapSB123.jpg
>
>What's that?  It's the output you get when your TEMPLATE file looks like
>this:
>
>[img]|[scalebar]
>
>That's all.  You don't need to make MapServer generate a whole HTML page
>for you - you've got your ASP page to do that.  Once you get MapServer
>to generate this little HTML tidbit for you, parse it out into two ASP
>string variables, one with the URL of the map image file, one with the
>URL of the scalebar image file (note the lack of error checking):
>
><%
>         commentPos = InStr (mapServerHTML, ">")         ' Strip out
>MapServer header comment
>         delimiterPos = InStr (mapServerHTML, "|")               ' Find
>field separator
>         imgURL = Mid (mapServerHTML, commentPos + 1, delimiterPos -
>commentPos - 1)
>         scalebarURL = Mid (mapServerHTML, delimiterPos + 1)
>%>
>
>Now I'm ready to generate my output HTML page.  I've taken my ASP
>parameters, generated a MapServer request, directed MapServer to
>generate the map image and a scalebar image, and I've put the URLs of
>those images into the variables imgURL and scalebarURL.
>
>The rest of my ASP page will generate my HTML (all the stuff that's NOT
>in the TEMPLATE file).  At strategic points I will do things like:
>
><table>
>   <tr>
>     <td>
>       <img src="<% =imgURL %>"><br>
>       <img src="<% =scalebarURL %>">
>     </td>
>   </tr>
></table>
>
>or other such thing.  I get to develop my pages in ASP and make
>MapServer do all the work!
>
>         - Ed
>
>Ed McNierney
>Chief Mapmaker
>TopoZone.com
>ed at topozone.com
>(978) 251-4242
>
>
>-----Original Message-----
>From: Jan Hartmann [mailto:jhart at frw.uva.nl]
>Sent: Thursday, December 06, 2001 8:52 AM
>To: Ed McNierney; mapserver-users at lists.gis.umn.edu
>Subject: RE: [mapserver-users] MapServer, ArcIMS, or SVG??
>
>
>At 09:57 AM 12/5/2001 -0500, Ed McNiemey wrote:
>
>
> >Can MapServer be used with Java or ASP?  Yes.  I have developed an
> >application for a customer that uses a lot of both.  I also posted a
> >note on the list a while ago about some techniques for using MapServer
> >effectively in an ASP environment.
>
>
>I searched the mailing list on ASP and Active Server Pages, but found
>nothing but the entries for the last few days. Could you give some
>details
>on using MapServer with ASP?
>
>Jan Hartmann
>Department of Geography
>University of Amsterdam
>jhart at frw.uva.nl


Richard W. Greenwood, PLS
Greenwood Mapping, Inc.
Rich at GreenwoodMap.com
(307) 733-0203
http://www.GreenwoodMap.com




More information about the mapserver-users mailing list