All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.geoviewer.jxmap.map.JXMapPanel Maven / Gradle / Ivy

Go to download

AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.

There is a newer version: 13.03-beta
Show newest version
/**
 * Copyright (C) 2010-2012 Agrosense [email protected]
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer.jxmap.map;

import java.util.prefs.Preferences;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.mapviewer.TileFactory;
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.util.NbPreferences;

/**
 * Wrapper around the JXMapViewer with some appropriate defaults
 *
 * @author Timon Veenstra
 */
public class JXMapPanel extends JXMapViewer{

    protected static double DEFAULT_LATITUDE = 52.155174;
    protected static double DEFAULT_LONGITUDE = 5.387206;
    protected static int DEFAULT_ZOOM_LEVEL = 11; // Max, any higher then 11 will default to 1!
    
    public JXMapPanel() {

        setOpaque(true);
        final int max = 19;
        TileFactoryInfo info = new TileFactoryInfo(1, max - 8, max,
                256, true, true, // tile size is 256 and x/y orientation is normal
                "http://tile.openstreetmap.org",//5/15/10.png",
                "x", "y", "z") {

            @Override
            public String getTileUrl(int x, int y, int zoom) {
                int calculatedZoom = max - zoom;
                return this.baseURL + "/" + calculatedZoom + "/" + x + "/" + y + ".png";
            }
        };
        TileFactory tf = new DefaultTileFactory(info);
        setTileFactory(tf);
        putClientProperty("print.printable", true);
    }

    @Override
     public void addNotify() {
        // Set saved coordinates and zoomlevel
        Preferences preferences = NbPreferences.forModule(JXMapPanel.class);
        Double latitude = preferences.getDouble("jxmap.lat", DEFAULT_LATITUDE);
        Double longitude = preferences.getDouble("jxmap.long", DEFAULT_LONGITUDE);
        int zoomLevel = preferences.getInt("jxmap.zoomlevel", DEFAULT_ZOOM_LEVEL);
        this.setAddressLocation(new GeoPosition(latitude, longitude));
        this.setZoom(zoomLevel);
        
        super.addNotify();
//        ExplorerUtils.activateActions(manager, true);
    }

    @Override
    public void removeNotify() {
        // Save coordinates and zoomlevel.
        Preferences preferences = NbPreferences.forModule(JXMapPanel.class);
        preferences.putDouble("jxmap.lat", this.getCenterPosition().getLatitude());
        preferences.putDouble("jxmap.long", this.getCenterPosition().getLongitude());
        preferences.putInt("jxmap.zoomlevel", this.getZoom());
        
//        ExplorerUtils.activateActions(manager, false);
        super.removeNotify();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy