Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
    <html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <title>ArcGIS Developer Guide: Facility routing</title>
        <style>
            html,
            body,
            #viewDiv {
                padding: 0;
                margin: 0;
                height: 100%;
                width: 100%;
            }
        </style>

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

        <script>
            require([
                "esri/config",
                "esri/Map",
                "esri/views/MapView",
                "esri/Graphic",
                "esri/layers/GraphicsLayer",
                "esri/tasks/ClosestFacilityTask",
                "esri/tasks/support/ClosestFacilityParameters",
                "esri/tasks/support/FeatureSet",
                "esri/geometry/Point",
                "esri/symbols/Symbol",
                "esri/layers/FeatureLayer",
            ], (
                esriConfig,
                Map,
                MapView,
                Graphic,
                GraphicsLayer,
                ClosestFacilityTask,
                ClosestFacilityParameters,
                FeatureSet,
                Point,
                Symbol,
                FeatureLayer,
            ) => {
                esriConfig.apiKey =
                    "";

                let routeSymbol = {
                    type: "simple-line",
                    color: [50, 150, 255, 0.75],
                    width: "5",
                };

                const routesLayer = new GraphicsLayer();
                const facilitiesLayer = new GraphicsLayer();

                facilitiesFeatureLayer = new FeatureLayer(
                    "https://services6.arcgis.com/dUO3N3UOHvGU89bM/arcgis/rest/services/Murals_20201103/FeatureServer/0", {
                        mode:FeatureLayer.MODE_SNAPSHOT
                    });
                let featuresetFacilities = new FeatureSet({
                });
                featuresetFacilities.features = facilitiesFeatureLayer.graphics;
                
                let map = new Map({
                    basemap: "arcgis-streets",
                    layers: [routesLayer, facilitiesLayer,facilitiesFeatureLayer],
                });
                map.getlayer
                let view = new MapView({
                    container: "viewDiv",
                    map: map,
                    center: [-119.465459, 49.880083],
                    zoom: 13,
                    constraints: {
                        snapToZoom: false
                    }
                });

                view.popup.actions = [];

                view.when(() => {
                    addFacilityGraphics();
                    findClosestFacility(addStartGraphic(view.center), facilitiesFeatureLayer);
                });

                view.on("click", (event) => {
                    view.hitTest(event).then((response) => {
                        if (response.results.length === 1) {
                            findClosestFacility(
                                addStartGraphic(event.mapPoint),
                                facilitiesFeatureLayer
                            );
                        }
                    });
                });


                function findClosestFacility(startFeature, facilityFeatures) {

                    const closestFacilityTask = new ClosestFacilityTask({
                        url: "https://route-api.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility/",
                    });

                    const params = new ClosestFacilityParameters({
                        incidents: new FeatureSet({
                            features: [startFeature],
                        }),
                        returnRoutes: true,
                        returnFacilities: true,
                        defaultTargetFacilityCount: 3,
                    });
                    params.facilities = featuresetFacilities;




                    
                    closestFacilityTask.solve(params).then(
                        (results) => {
                            showRoutes(results.routes);
                            console.log(results.routes);
                        },
                        (error) => {
                            console.log(error.details);
                        }
                    );
                }


                function addStartGraphic(point) {
                    view.graphics.removeAll();
                    const graphic = new Graphic({
                        symbol: {
                            type: "simple-marker",
                            color: [255, 255, 255, 1.0],
                            size: 8,
                            outline: {
                                color: [50, 50, 50],
                                width: 1,
                            },
                        },
                        geometry: point,
                    });
                    view.graphics.add(graphic);
                    return graphic;
                }

                function addFacilityGraphics() {
                facilities.forEach((point) => {
                    facilitiesLayer.graphics.add(
                    new Graphic({
                        symbol: {
                        type: "web-style",
                        name: "grocery-store",
                        styleName: "Esri2DPointSymbolsStyle",
                        },
                        geometry: {
                        type: "point",
                        longitude: point[0],
                        latitude: point[1],
                        spatialReference: view.spatialReference,
                        },
                    })
                    );
                });
                }

                function showRoutes(routes) {
                    // Show the routes to the closest facilities
                    routesLayer.removeAll();
                    routes.forEach((route, i) => {
                        route.symbol = routeSymbol;
                        routesLayer.add(route);
                    });
                }
            });
        </script>
    </head>

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

    </html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console