How to create a map of only one state in Arcgis Javascript?

1656
8
06-30-2017 03:30 PM
MRReddy
Occasional Contributor

This is a very simple question but a Google search did not provide an answer.

Basically suppose you have a map of the U.S. with states and county layers, as well as other layers like roads, etc.

I want to work with a map of only one state. in Arcgis JavaScript.

I did below code for whole world map loading:

var map;
require([
"esri/map",
"dojo/domReady!"
], function (
Map
) {
map = new Map("map", {
basemap: "osm",
center: [-122.9007, 47.0379],
zoom: 9
});
});

0 Kudos
8 Replies
MRReddy
Occasional Contributor
0 Kudos
SethLewis1
Occasional Contributor III
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>FeatureLayer - 4.3</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.3/esri/css/main.css">
    <script src="https://js.arcgis.com/4.3/"></script>

    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>

    <script>
        require([
                "esri/Map",
                "esri/views/MapView",

                "esri/layers/FeatureLayer",

                "dojo/domReady!"
            ],
            function(
                Map, MapView,
                FeatureLayer
            ) {

                var map = new Map({
                    basemap: "hybrid"
                });

                var view = new MapView({

                    container: "viewDiv",
                    map: map,
                    center: [-120.007, 47.0379],
                    zoom: 7
                });

                /********************
                 * Add feature layer
                 ********************/


                // Carbon storage of trees in Warren Wilson College.
                var featureLayer = new FeatureLayer({
                    url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_States_Generalized/FeatureServ...",
                    outFields: ["*"],
                    definitionExpression: "STATE_NAME = 'Washington'"
                });

                map.add(featureLayer);

            });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
</body>

</html>
MRReddy
Occasional Contributor

sethlewistempe‌ Something is missing, It loading empty screen

0 Kudos
SethLewis1
Occasional Contributor III

JS Bin - Collaborative JavaScript Debugging 

Does the jsbin link above render for you?

0 Kudos
MRReddy
Occasional Contributor

Is there any way to show only one state on screen, 

0 Kudos
SethLewis1
Occasional Contributor III

The code provided  shows only one state based on a definition expression.

0 Kudos
MRReddy
Occasional Contributor

above code highlights one state and loads total map. I'm looking for to show only one state on screen

above code looks as in image

0 Kudos
SethLewis1
Occasional Contributor III

JS Bin - Collaborative JavaScript Debugging 

Changing the basemap property from "hybrid" to "satellilte" should provide what you're looking for.

0 Kudos