Configuration of Java environment and JSP in WebGIS Based on Mapserver

Source: Internet
Author: User
Mapserver supports various interpreted languages through Mapscript, such as C #, java, TCL, and PHP.
Swig is an open-source tool. swig can Package c/c ++ code into code libraries available in various scripting languages. Swig this great
To package the c code of mapserver. I really like this swig. If we have such an open-source c/c ++ library on the internet
Some features are used, and the next one is packaged with swig, so we can see that java or c # is used, saving a lot of effort.
Using c/c ++ to write the core functions at the underlying layer helps improve the running speed, protect the source code, and use the open-source c/c ++ class library.
Swig is packaged for various languages and can directly enjoy the powerful explanatory functions such as C #, java, and TCL. Haha ......

We can download the corresponding mapscript.jarpackage. The downloaded ms4w_1.5.3.zip already contains this. With this jar
We can call mapserver in java.
The steps are as follows:
1. Set the environment variable PATH so that the JVM can locate mapscript. dll or mapscript. so. The following uses windows as an example.
Set PATH = D:/ms4w/Apache/cgi-bin; % PATH % # This is to locate the dll,
Set PROJ_LIB = D:/ms4w/proj/nad# this is for convenient projection
Set CLASSPATH = D:/ms4w/Apache/cgi-bin/mapscript/java/mapscript. jar; % CLASSPATH % # java.

It is best to set these environment variables to system environment variables instead of user environment variables (Remember, otherwise dll cannot be located ).
2. In tomcat, if no PATH is set before, you can do the same. Because tomcat runs on JVM, the script is added to tomcat.
Option-Djava. library. path = D:/ms4w/Apache/cgi-bin!

After the above two steps, we have configured the java environment. Next we will look at a small example.
This is a JSP code that can be run. These functions are mainly implemented.
1. Map Shrinkage
2. eagleeye chart
3. Legend
4. Scale
Since the code is very simple, Don doesn't say much about it. Let's take a look! Of course, Mapserver is much more powerful than this, and I like mapserver more and more.
The Comparison Between mapserver and ArcIMS is mentioned in the mailllist of Mapserver. Some of them are worth noting. Mapsever is faster than ArcIMS in terms of concurrency
It is better than ArcIMS and supports more webgis protocols than ArcIMS. The GIS functions of the two are similar. One is commercial and the other is open-source. For the poor
Playing with Mapserver is also good. If you want to start your own business, you can start from Mapserver.
In the future, we will use Servlet + Ajax to develop the webgis of Mapserver! Switch to the next decomposition.

The result is as follows:

<% @ Page contentType = "text/html; charset = GB2312" language = "java" %>
<% @ Page import = "edu. umn. GIS. mapscript. *" %>
<% @ Page import = "Java. util. iterator, java. util. arraylist" %>
<% @ Page import = "Java. util. Date" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> my first mapserver-WebGIS good-luck </title>
</Head>
<Body>
<Form method = post action = "index. jsp">

<%!
Static int I = 0;
%>

<%

Mapobj map;
String vmapfile = "";
String vscalebarfile = "";
String vlengdbarfile = "";
String vreferencefile = "";
Double rodio = 1;
Map = new mapObj ("D:/SuperMap/SuperMapISJava/thirdparty/tomcat/webapps/mapserver/tutorial. map ");
If (map = null)
{
System. out. println ("! OK ");

}
Else
{
If (request. getParameter ("rodio ")! = Null)
{
If (request. getParameter ("rodio ")! = "")
{
Rodio = Double. parseDouble (request. getParameter ("rodio "));
}
}
RectObj ro = map. getExtent ();
Double xw = ro. getMaxx ()-ro. getMinx ();
Double yw = ro. getMaxy ()-ro. getMiny ();
Double cx = (ro. getMaxx () + ro. getMinx ()/2;
Double cy = (ro. getMaxy () + ro. getMiny ()/2;
Double newxw = xw * rodio;
Double newyw = yw * rodio;
Double maxx = cx + newxw/2;
Double minx = cx-newxw/2;
Double maxy = cy + newyw/2;
Double miny = cy-newyw/2;
Map. setExtent (minx, miny, maxx, maxy );
System. out. println ("minx:" + minx );
System. out. println ("miny:" + miny );
System. out. println ("maxx:" + maxx );
System. out. println ("maxy:" + maxy );
Map. setImagecolor (new colorObj (10,128, 98,13 ));
ImageObj imagen = map. draw ();
// Imagen. setImageDir ("/tmp ");
Date dt = new Date ();
VMapFile = "output/tangnf" + (dt. getTime () + ". png ";
// Map. embedScalebar (imagen );
Imagen. Save (vmapfile, MAP );

Scalebarobj scalebar = map. getscalebar ();
Scalebar. setheight (10 );
Scaling. setwidth (200 );
Scalebar. setbackgroundcolor (New colorobj (0,255 ));
Scalebar. setcolor (New colorobj (, 0 ));
Scalebar. setimagecolor (New colorobj (255,255,255, 13 ));
Scalebar. setoutlinecolor (New colorobj (0,230,255, 13 ));
// Scalebar. setstyle (3 );
Scalebar. setunits (3 );
Scalebar. setintervals (3 );
// Scalebar. setlabel (New labelobj
Imageobj scalebarimage = map. drawscalebar ();
Vscalebarfile = "output/scalebar" + (Dt. gettime () + ". jpg ";
Scalebarimage. save (vScaleBarFile, map );
 
LegendObj legend = map. getLegend ();
Legend. setHeight (200 );
Legend. setWidth (100 );
System. out. println (legend. getLabel (). getEncoding ());
ImageObj Legendimage = map. drawLegend ();
VLengdBarFile = "output/Legend" + (dt. getTime () + ". png ";
Legendimage. save (vLengdBarFile, map );
Int layerCount = map. getNumlayers ();
For (int I = 0; I <layerCount; I ++)
{
LayerObj layer = map. getLayer (I );
System. out. println ("layer" + (I) + ":" + layer. getName ());
}
System. out. println ("layerCount:" + layerCount );

ReferenceMapObj referenceMap = map. getReference ();
ReferenceMap. setHeight (200 );
ReferenceMap. setWidth (200 );

ImageObj ReferenceImg = map. drawReferenceMap ();
VReferenceFile = "output/Reference" + (dt. getTime () + ". png ";
ReferenceImg. save (vReferenceFile, map );
System. out. println ("I succeeded ");
}

%>
<Table border = 1>
<Tr> <td>
Contraction factor: & nbsp;
<Input type = "text" NAME = "rodio" value = "<% = rodio %>" id = "rodio">
</Td>
<Td>
<Input type = "submit" value = "submit">
</Td>
<Tr> <td width = 80>
Scale: & nbsp;
<Input name = "ScaleBar" TYPE = "image" SRC = "<% = vScaleBarFile %>" border = 1>
<! -- </img> -->
</Td>
</Tr>
<Tr> <td>
<Input name = "imgMap" TYPE = "image" SRC = "<% = vMapFile %>" width = 600 height = 400 border = 0>
</Td>
</Tr>
<Tr> <td>
Legend: & nbsp;
<Input name = "imgLengd" TYPE = "image" SRC = "<% = vLengdBarFile %>" border = 0>
</Td>
<Td>
Eagleeye: & nbsp;
<Input name = "vReferenceF" TYPE = "image" SRC = "<% = vReferenceFile %>" border = 0>
</Td>
</Tr>
</Table>
</FORM>
</BODY>
</HTML>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.