java-mapscipt examples

Bas Vanmeulebrouk bvanmeul at EBE.UCT.AC.ZA
Fri Oct 21 02:01:10 PDT 2005


Hello Ahmet, list

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.");
       }
   }

Hope this helps.

Cheers,

Bas.

orkun wrote:

> hello
>
> As a new for java-mapscipt, I need to see related examples.
>
> I will appreciate, if you provide any examples.
>
> regards
>
>
> Ahmet Temiz
>
>
> ______________________________________
> XamimeLT - installed on mailserver for domain @deprem.gov.tr
> Queries to: postmaster at deprem.gov.tr
> ______________________________________
> The views and opinions expressed in this e-mail message are the 
> sender's own
> and do not necessarily represent the views and the opinions of 
> Earthquake Research Dept.
> of General Directorate of Disaster Affairs.
>
> Bu e-postadaki fikir ve gorusler gonderenin sahsina ait olup, yasal 
> olarak T.C.
> B.I.B. Afet Isleri Gn.Mud. Deprem Arastirma Dairesi'ni baglayici 
> nitelikte degildir.



More information about the MapServer-users mailing list