java mapscript and j2ee
Bas Vanmeulebrouk
bvanmeul at EBE.UCT.AC.ZA
Tue Nov 29 02:03:29 PST 2005
Hello Juan,
A couple of weeks ago, I posted this message as a response to a similar
question. Does this answer your question?
Bas.
I am not very experienced in Java MapScript either, but I may have some
code which may be usefull for you. In my servlet, I have got a
MapServerMap object to encapsulate MapScript. I create this object like
this:
public MapServerMap(String aMapFileName) throws Exception {
super();
try {
File f = new File(aMapFileName);
if (f.exists()) {
Map = new mapObj(aMapFileName);
} else {
throw new Exception("Map file not found: " + aMapFileName);
}
} catch (UnknownError e) {
throw new Exception(ErrorMessages.errCreatingMapServerMap);
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
And I use it like this for instance:
public void Zoom(int aZoomFactor) {
float x = Map.getWidth() / 2;
float y = Map.getHeight() / 2;
pointObj point = new pointObj(x, y, 0.0, 0.0);
Map.zoomPoint(aZoomFactor, point, Map.getWidth(), Map.getHeight(),
Map
.getExtent(), null);
}
After I have done all the panning, zooming, filtering and turning layers
on and off I draw the map like this:
public String Draw() throws MapServerException {
try {
/*
* Draw the map and return the URL under which it was stored
*/
imageObj image = Map.draw();
String fn = "map_" + getUniqueID() + "."
+ Map.getOutputformat().getExtension();
image.save(StringUtils.CheckAndAppend(image.getImagepath(),
"\\") + fn, Map);
return StringUtils.CheckAndAppend(image.getImageurl(), "/") + fn;
} catch (UnknownError e) {
throw new MapServerException("Error drawing map.");
}
}
Juan Baron wrote:
>Hi list,
>
>I have used mapserver like cgi but now I will use mapserver in an
>application j2ee using mapscript. I don't understand as to communicate
>with mapserver and to tell him for example that you layer to show, and
>neither I understand as mapserver gives me the exit.
>Could somebody give me a brief introduction of the mapscript use?
>
>Thank you
>
>
More information about the MapServer-users
mailing list