create a map based on one of the predefined base maps which is centred at a given latitude and longitude using esri - Java Geographic Information System

Java examples for Geographic Information System:Esri

Description

create a map based on one of the predefined base maps which is centred at a given latitude and longitude using esri

Demo Code

/* Copyright 2015 Esri./*from www  . ja  v  a2  s.  c  o  m*/
     
Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
     
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 com.esri.sampleviewer.samples.map;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import com.esri.arcgisruntime.mapping.BasemapType;
import com.esri.arcgisruntime.mapping.Map;
import com.esri.arcgisruntime.mapping.view.MapView;

/**
 * This sample shows how to create a map based on one of the predefined 
 * base maps which is centred at a given latitude and longitude (56.075844,-2.681572) 
 * at a zoom level of 10.
 */

public class SetInitialMapLocation extends Application {

    private MapView mapView;
    private Map map;

    @Override
    public void start(Stage stage) throws Exception {
        // create a border pane
        BorderPane borderPane = new BorderPane();
        Scene scene = new Scene(borderPane);

        // size the stage and add a title
        stage.setTitle("Set initial map location");
        stage.setWidth(700);
        stage.setHeight(800);
        stage.setScene(scene);
        stage.show();

        // create a Map which defines the layers of data to view
        try {
            //make a new map using National Geographic mapping centred over East Scotland at zoom level 10.
            map = new Map(BasemapType.NATIONAL_GEOGRAPHIC, 56.075844,
                    -2.681572, 10);

            // create the MapView JavaFX control and assign its map
            mapView = new MapView();
            mapView.setMap(map);

            // add the MapView
            borderPane.setCenter(mapView);

        } catch (Exception e) {
            System.out.println("can't see the map");
            e.printStackTrace();
        }
    }

    @Override
    public void stop() throws Exception {
        // release resources when the application closes
        mapView.dispose();
        map.dispose();
        System.exit(0);

    };

    public static void main(String[] args) {
        Application.launch(args);
    }
}

Related Tutorials