EDN Code Exchange

Updated Sep 29, 2010
Samples

Get Symbols from the ServerStyleGallery

Description:

The code below demonstrates how you obtain MarkerSymbols from a ServerStyleGallery. StyleGallery files are located in the styles folder of your ArcGIS installation directory. StyleGallery files are primarily used for Desktop and Engine development, while ServerStyleGallery files are used only for server development. This example connects to an ArcGIS Server machine and creates an "empty" context within which the ServerStyleGallery object will be created and used.

Products:

Server: Java

Platforms: Windows, Unix, Linux

Minimum ArcGIS Release: 9.0

How to use:
  1. Copy and paste the Java code into a Java source editor. This runs as a standalone Java program. Compile and run it.
          package arcgissamples.display;

import java.io.*;

import com.esri.arcgis.display.*;
import com.esri.arcgis.server.*;
import com.esri.arcgis.system.*;

public class GetSymbolFromServerStyleGallery {

    private static AoInitialize aoInit;
    private IServerContext sc;
    public GetSymbolFromServerStyleGallery() {}

    private void connectToServer() {

        String host = "husker";
        String domain = "gisdomain";
        String user = "user1";
        String password = "password";

        try {
	
	    // Initialize ArcObjects for Server usage
            new ServerInitializer().initializeServer(domain,
                    user, password);
                    
            // Connect to the host machine where the ArcGIS Server Object Manager is running
            ServerConnection connection = new ServerConnection();
            connection.connect(host);

	// Get the SOM and create an empty context.
            IServerObjectManager som = connection.getServerObjectManager();
            sc = som.createServerContext("", "");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void listMarkerSymbols() {

        try {

           // Create the object on the server, within the empty context.
            ServerStyleGallery ssg = new ServerStyleGallery(sc.createObject(ServerStyleGallery.getClsid()));

            //You need to add the style file, by name, to the ServerStyleGallery
            String path = "C:\\ArcGIS\\Styles\\Caves.ServerStyle";
            ssg.addFile(path);

	     //Get the list of all Marker Symbols from the Default category of the gallery
            EnumServerStyleGalleryItem items =
                    new EnumServerStyleGalleryItem(ssg.getItems(
                            "Marker Symbols", path, "Default"));

	    //Iterate through the collection and print out the name and the size of each symbol
            IStyleGalleryItem item = items.next();

            while (item != null) {

                IMarkerSymbol sms = new IMarkerSymbolProxy(item.getItem());
                System.out.println("Symbol Name: " + item.getName());
                System.out.println("Symbol Size: " + sms.getSize());
                System.out.println("");
                item = items.next();
            }

           //Once we are done using the objects in the server context, remove them and release the context
            sc.removeAll();
            sc.releaseContext();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {

        GetSymbolFromServerStyleGallery getsymbolfromserverstylegallery = new
                GetSymbolFromServerStyleGallery();

        getsymbolfromserverstylegallery.connectToServer();
        getsymbolfromserverstylegallery.listMarkerSymbols();

    }
}
		
        

Loading ...

If you would like to post a comment, please login.