Select to view content in your preferred language

Local Tiled Layer (sample) problems.

3027
2
12-09-2013 10:33 AM
IbrahimHussein
Deactivated User
Hey guys, I am playing around with multiple runtime SDKs (WPF, Java...) to see which one suites my needs. I am trying to load one of the sample codes into eclipse. I was able to do it for a few of them, but the "Tiled layers>Local Tiled Layer sample" does not work.

This line of code is what is causing the problem,
LocalTiledLayer localTiledLayerApp = new LocalTiledLayer();
The error states " LocalTiledLayer cannot be resolved to a type" which leads me to believe its there is an import missing, I directly copied all the ones from the sample.

Im using eclipse kepler, arcgis runtime sdk 10.2.

any help would be apperciated, hope this is enough information. I pasted the code below for ease of access to the code. hope thats ok.
// Copyright 2013 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions.
//
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;

import com.esri.client.local.ArcGISLocalTiledLayer;
import com.esri.core.geometry.Envelope;
import com.esri.map.JMap;
import com.esri.runtime.ArcGISRuntime;

/**
 * <p>
 * This application shows how to add a local tiled layer (<code>ArcGISLocalTiledLayer</code>)
 * into a map from a tile package (.tpk) file created using ArcGIS Desktop.  Please refer to
 * the Desktop Help for "How to create a Tile Package".
 * </p>
 * <p>
 * Furthermore, the <code>setWrapAroundEnabled</code> method is called on the JMap,
 * making the map wrap around the dateline for a smooth user experience.
 * </p>
 */

public class LocalTitleLayer {

    private JComponent contentPane;
    private JMap map;
    private static final String FSP = System.getProperty("file.separator");

    public LocalTiledLayer() {
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    // instance of this application
                    LocalTiledLayer localTiledLayerApp = new LocalTiledLayer(); // this is where the problem is. 

                    // create the UI, including the map, for the application.
                    JFrame appWindow = localTiledLayerApp.createWindow();
                    appWindow.add(localTiledLayerApp.createUI());
                    appWindow.setVisible(true);
                } catch (Exception e) {
                    // on any error, display the stack trace.
                    e.printStackTrace();
                }
            }
        });
    }

    public JComponent createUI() {

        contentPane = createContentPane();

        // create map
        map = createMap();

        // checkbox to control logo display
        final JCheckBox cbxEsriLogo = new JCheckBox("Show Esri logo");
        cbxEsriLogo.setLocation(10, 10);
        cbxEsriLogo.setSize(140, 20);
        cbxEsriLogo.setSelected(map.isShowingEsriLogo());
        cbxEsriLogo.setBackground(Color.BLACK);
        cbxEsriLogo.setForeground(Color.WHITE);
        cbxEsriLogo.setFocusPainted(false);
        cbxEsriLogo.setFont(new Font("Dialog", Font.BOLD, 12));
        cbxEsriLogo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                map.setShowingEsriLogo(!map.isShowingEsriLogo());
                cbxEsriLogo.setSelected(map.isShowingEsriLogo());
            }
        });
        contentPane.add(cbxEsriLogo);

        // enable map wrap around
        map.setWrapAroundEnabled(true);
        // add the map to our content pane
        contentPane.add(map);

        return contentPane;
    }

    /**
     * Creates the map.
     * @return a map.
     */
    private JMap createMap() {

        // create the jMap
        JMap jMap = new JMap();

        // show Esri logo by default
        jMap.setShowingEsriLogo(true);

        // set initial extent 
        jMap.setExtent(new Envelope(-19856505, -8827900, 18574809, 16806021));

        // add the local tiled layer (.tpk)
        ArcGISLocalTiledLayer tiledLayer =
            new ArcGISLocalTiledLayer(getPathSampleData() + "tpks" + FSP + "Topographic.tpk");
        jMap.getLayers().add(tiledLayer);

        return jMap;
    }

    /**
     * Creates a content pane.
     * @return a content pane.
     */
    private static JLayeredPane createContentPane() {
        JLayeredPane contentPane = new JLayeredPane();
        contentPane.setBounds(100, 100, 1000, 700);
        contentPane.setLayout(new BorderLayout(0, 0));
        contentPane.setVisible(true);
        return contentPane;
    }

    /**
     * Creates a window.
     * @return a window.
     */
    private JFrame createWindow() {
        JFrame window = new JFrame("Local Tiled Layer Application");
        window.setBounds(100, 100, 1000, 700);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.getContentPane().setLayout(new BorderLayout(0, 0));
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent windowEvent) {
                super.windowClosing(windowEvent);
                map.dispose();
            }
        });
        return window;
    }

    private String getPathSampleData() {
        String dataPath = null;
        String javaPath = ArcGISRuntime.getInstallDirectory();
        if (javaPath != null) {
            if (!(javaPath.endsWith("/") || javaPath.endsWith("\\"))){
                javaPath += FSP;
            }
            dataPath = javaPath + "sdk" + FSP + "samples" + FSP + "data" + FSP;
        }
        File dataFile = new File(dataPath);
        if (!dataFile.exists()) { 
          dataPath = ".." + FSP + "data" + FSP;
        }
        return dataPath;
    }
}
0 Kudos
2 Replies
VijayGandhi
Deactivated User
Looks like your class name is incorrect -

LocalTitleLayer should be LocalTiledLayer
0 Kudos
IbrahimHussein
Deactivated User
Looks like your class name is incorrect -  

LocalTitleLayer should be LocalTiledLayer


[strike]Thanks for the reply, but that was not it. I actually renamed the class, but I took your suggesstion and fixed it, and the error still appears. [/strike]
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
 LocalTiledLayer cannot be resolved to a type
 LocalTiledLayer cannot be resolved to a type

 at LocalTitledLayer$1.run(LocalTitledLayer.java:61)
 at java.awt.event.InvocationEvent.dispatch(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)


I actually figured it out, I just reinstalled the SDK and it seemed to work.
0 Kudos