Tuesday, August 16, 2005

Integrating AJAX with ArcGIS Server - II

Now lets take a look at AGSMap class mentioned earlier. Given below is the complete code for this class. Since I have added comments in between the code describing each part of the code, this should be self explanatory.

package com.esri.arcgis.sample;

import com.esri.arcgis.server.IServerConnection;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.IServerContext;

import com.esri.arcgis.carto.IMapServer;
import com.esri.arcgis.carto.IMapServerProxy;
import com.esri.arcgis.carto.IMapDescription;
import com.esri.arcgis.carto.IMapServerObjects;
import com.esri.arcgis.carto.IMapServerObjectsProxy;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.IMapProxy;
import com.esri.arcgis.carto.IMapDescriptionProxy;
import com.esri.arcgis.carto.MapDescription;
import com.esri.arcgis.carto.IImageDescription;
import com.esri.arcgis.carto.IImageDescriptionProxy;
import com.esri.arcgis.carto.ImageDescription;
import com.esri.arcgis.carto.IImageType;
import com.esri.arcgis.carto.IImageTypeProxy;
import com.esri.arcgis.carto.ImageType;
import com.esri.arcgis.carto.IImageDisplay;
import com.esri.arcgis.carto.IImageDisplayProxy;
import com.esri.arcgis.carto.ImageDisplay;
import com.esri.arcgis.carto.IMapImage;
import com.esri.arcgis.carto.IMapImageProxy;
import com.esri.arcgis.carto.MapImage;
import com.esri.arcgis.carto.IMapExtent;
import com.esri.arcgis.carto.IMapExtentProxy;
import com.esri.arcgis.carto.MapExtent;
import com.esri.arcgis.carto.IMapArea;
import com.esri.arcgis.carto.IMapAreaProxy;
import com.esri.arcgis.carto.esriImageFormat;
import com.esri.arcgis.carto.esriImageReturnType;
import com.esri.arcgis.carto.IImageResult;

import com.esri.arcgis.system.LongArray;
import com.esri.arcgis.system.ILongArray;
import com.esri.arcgis.system.ILongArrayProxy;

import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.IPointCollection;
import com.esri.arcgis.geometry.IEnvelope;
import com.esri.arcgis.geometry.Envelope;
import com.esri.arcgis.geometry.IEnvelopeProxy;

import com.esri.arcgis.webcontrols.ags.data.*;

public class AgsMap {

public synchronized static String
getImageUrl(AGSWebContext context, int x, int y){
try{
//get IMapServer from AGSWebContext
IMapServer m_mapServer = context.getServer();
//QI to IMapServerObjects
IMapServerObjects m_mapServerObj =
new IMapServerObjectsProxy(m_mapServer);
// get IServerContext from AGSWebContext
IServerContext m_context = context.getServerContext();

IMap m_map = null;
//if there is a default map, get IMap
if (m_mapServer.getDefaultMapName() != null) {
m_map = new IMapProxy(m_mapServerObj.getMap(
m_mapServer.getDefaultMapName()));
} else return null;

//get Default MapDescription from AGSWebContext
IMapDescription m_mapDesc = context.getMapDescription(
m_mapServer.getDefaultMapName());
/*
create a new ImageType and set the properties
we are getting the image url, so make sure to
specify output directory in ArcCatalog
for the server object config being used in
this application
*/
IImageType m_imageType = new IImageTypeProxy(
m_context.createObject(ImageType.getClsid()));
m_imageType.setFormat(esriImageFormat.esriImagePNG);
m_imageType.setReturnType(
esriImageReturnType.esriImageReturnURL);

//create a new IImageDisplay
//set width and height same as that of the Map Control
//because we will be using it to convert pixel
//point to Map point
IImageDisplay m_imageDisplay = new IImageDisplayProxy(
m_context.createObject(ImageDisplay.getClsid()));
m_imageDisplay.setDeviceResolution(96D);
m_imageDisplay.setWidth(context.getWebMap().getWidth());
m_imageDisplay.setHeight(context.getWebMap().getHeight());

//set the above IImageDisplay and IImageType
// to IImageDescription
IImageDescription m_imageDesc = new IImageDescriptionProxy(
m_context.createObject(ImageDescription.getClsid()));
m_imageDesc.setDisplay(m_imageDisplay);
m_imageDesc.setType(m_imageType);

//convert pixel point into map point
//notice that we are using the above map
//description and image description
// in mapserver.toMapPoints method
ILongArray longArrayX = new ILongArrayProxy(
m_context.createObject(LongArray.getClsid()));
longArrayX.insert(0, x-10);
ILongArray longArrayY = new ILongArrayProxy(
m_context.createObject(LongArray.getClsid()));
longArrayY.insert(0, y+10);
longArrayX.insert(1,x+10);
longArrayY.insert(1,y-10);
IPointCollection pointColl = m_mapServer.toMapPoints(
m_mapDesc,
m_imageDesc.getDisplay(),
longArrayX,
longArrayY);
IPoint point1 = null;
IPoint point2 = null;
if (pointColl.getPointCount() > 0) {
point1 = pointColl.getPoint(0);
point2 = pointColl.getPoint(1);
}

//generate a small envelope based on map points
IEnvelope env = new IEnvelopeProxy(
m_context.createObject(Envelope.getClsid()));
env.setXMin(point1.getX());
env.setYMin(point1.getY());
env.setXMax(point2.getX());
env.setYMax(point2.getY());

//reset the Image size to 200X200
//this is the size of the magnified image
m_imageDesc.getDisplay().setWidth(200);
m_imageDesc.getDisplay().setHeight(200);

//set the new MapExtent based on the above envelope
IMapExtent mapExtent = new IMapExtentProxy(
m_context.createObject(MapExtent.getClsid()));
mapExtent.setExtent(env);

//create a new map description and set above
//extent and default LayerDescriptions to it
IMapDescription m_mapDesc1 = new IMapDescriptionProxy(
m_context.createObject(MapDescription.getClsid()));
IMapArea mapArea = new IMapAreaProxy(mapExtent);
m_mapDesc1.setMapArea(mapArea);
m_mapDesc1.setLayerDescriptions(
m_mapDesc.getLayerDescriptions());
m_mapDesc1.setName(m_mapServer.getDefaultMapName());

//export the map image and get its URL
IMapImage mapImage = m_mapServer.exportMapImage(
m_mapDesc1, m_imageDesc);
String url = mapImage.getURL();
//finally release the context
m_context.removeAll();
m_context.releaseContext();
return url;
}catch (Exception ex){
ex.printStackTrace();
return null;
}
}
}

17 Comments:

At 7:50 PM, Blogger Kong said...

After test this code, I have some problem in nearly lastest line.

"String url = mapImage.getURL();"

I got "" return form "mapImage.getURL()". Could you pls suggest me to solve this problem.

Thanks in advance,
Kong
p.s. my server use MIME option.

 
At 9:32 AM, Anonymous Anonymous said...

Latest news. Viagra, cialis

viagra
cialis
tramadol

 
At 1:21 PM, Anonymous us flower shops said...

After test this code, I have some problem in nearly lastest line."String url = mapImage.getURL();"I got "" return form "mapImage.getURL()". Could you pls suggest me to solve this problem.Thanks in advance, Kong p.s. my server use MIME option.

 
At 5:46 AM, Anonymous Viagra Online said...

thi look a little bit complicated, but with time and a good look maybe I can learn how use this to my benefit.

 
At 4:11 PM, Anonymous miami computer rental said...

I don't quite understand this part:

//generate a small envelope based on map points
IEnvelope env = new IEnvelopeProxy(
m_context.createObject(Envelope.getClsid()));
env.setXMin(point1.getX());
env.setYMin(point1.getY());
env.setXMax(point2.getX());
env.setYMax(point2.getY());

 
At 7:39 PM, Anonymous cellulite exercises said...

Very great articles. I’ve discovered your site by Aol and I’m really pleased regarding the info you could have inside your post. By the way in which your blogs design is kind of broken with the Chrome internet browser. Could be actually nice in case you’re can repair that. Anyway maintain within the great function!

 
At 2:29 AM, Blogger hibeyond said...

black boots

Chocolate boots

sand boots

Chestnut boots

gray boots

pink boots

grey boots

pink boots

 
At 6:20 AM, Anonymous www.tapicerias.nom.es said...

So, I don't actually believe this will work.

 
At 3:48 PM, Anonymous vrnjacka banja said...

I'm enjoyed reading this article and whole website, thanks a lot for this informations!
vrnjacka banja smestaj
vrnjacka banja privatni smestaj

 
At 7:47 AM, Anonymous pepa prase said...

I'm so excited. I really appreciate sharing this great post. Keep up your excellent work.
bojanke za decu
bojanke
gledanje u solju

 
At 2:04 PM, Anonymous hypnosis said...

Hypnosis for Beginners

 
At 5:00 AM, Anonymous cinema arts said...

I will bookmark this site and visit again. It is very informative. Thanks for sharing.

 
At 6:13 AM, Anonymous get girlfriend give oral sex said...

I will bookmark this site and visit again. It is very informative. Thanks for sharing.

 
At 3:49 AM, Anonymous How to get rid of cellulite said...

Wow, took a while to work it out and I am honestly surprised that you did! How long did it take?

 
At 5:18 PM, Anonymous price per head bookmaking said...

It was nice visiting your blog. There are some interesting and useful things have been shared her

 
At 6:00 PM, Blogger Kzaxcpnd Molluskxbny said...

Love is a telephone which, when you use it for the first time, makes you so nervous RS Gold and excited that you Runescape Gold either hold the receiver upside down or dial the wrong number. By the time you have calmed down, you will beat a loss Runescape Gold to whom you should make the call.

 
At 6:03 PM, Blogger Kzaxcpnd Molluskxbny said...

The next time you find yourself RuneScape Gold in the middle of a very stressful time, or you feel angry RuneScape Gold or frustrated, stop. Yes, that's right, stop. Whatever you're doing, stop and sit for one minute. While you're sitting there, completely immerse rs gold yourself in the negative emotion.

 

Post a Comment

<< Home