Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 15.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8" />
  5.     <meta
  6.      name="viewport"
  7.      content="initial-scale=1,maximum-scale=1,user-scalable=no"
  8.    />
  9.     <title>Intro to layers - 4.13</title>
  10.  
  11.     <link
  12.      rel="stylesheet"
  13.      href="https://js.arcgis.com/4.13/esri/themes/light/main.css"
  14.    />
  15.     <script src="https://js.arcgis.com/4.13/"></script>
  16.  
  17.     <style>
  18.       html,
  19.       body,
  20.       #viewDiv {
  21.         padding: 0;
  22.         margin: 0;
  23.         height: 100%;
  24.         width: 100%;
  25.       }
  26.  
  27.       #layerToggle {
  28.         top: 20px;
  29.         right: 20px;
  30.         position: absolute;
  31.         z-index: 99;
  32.         background-color: white;
  33.         border-radius: 8px;
  34.         padding: 10px;
  35.         opacity: 0.75;
  36.       }
  37.     </style>
  38.  
  39.     <script>
  40.     require(["esri/Map", "esri/views/MapView","esri/Graphic","esri/layers/TileLayer","esri/layers/FeatureLayer","esri/widgets/Search","esri/widgets/Print","esri/widgets/Locate","esri/widgets/Expand",
  41.         "esri/widgets/BasemapGallery"], function(Map, MapView,Graphic,TileLayer,FeatureLayer,Search,Print,Locate,Expand, BasemapGallery)
  42.        {
  43.         /*****************************************************************
  44.          * Create two TileLayer instances. One pointing to a
  45.          * cached map service depicting U.S. male population and the other
  46.          * pointing to a layer of roads and highways.
  47.          *****************************************************************/
  48.         var transportationLayer = new TileLayer({
  49.           url:
  50.             "https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer",
  51.           // This property can be used to uniquely identify the layer
  52.           id: "streets",
  53.           visible: false
  54.         });
  55.  
  56.         var housingLayer = new TileLayer({
  57.           url:
  58.             "https://tiles.arcgis.com/tiles/kla6QEoN1wAmqwT1/arcgis/rest/services/344964p1r/MapServer",
  59.           id: "ny-housing",
  60.           opacity: 0.9
  61.         });
  62.        
  63.         var housingLayer1 = new TileLayer({
  64.           url:
  65.             "https://tiles.arcgis.com/tiles/kla6QEoN1wAmqwT1/arcgis/rest/services/344836p1r_1/MapServer",
  66.           id: "ny-housing",
  67.           opacity: 0.9
  68.         });
  69.        
  70.  
  71.         /*****************************************************************
  72.          * Layers may be added to the map in the map's constructor
  73.          *****************************************************************/
  74.         var map = new Map({
  75.           basemap: "oceans",
  76.           layers: [housingLayer,housingLayer1]
  77.         });
  78.  
  79.         /*****************************************************************
  80.          * Or they may be added to the map using map.add()
  81.          *****************************************************************/
  82.         map.add(transportationLayer);
  83.  
  84.         var view = new MapView({
  85.           container: "viewDiv",
  86.           map: map,
  87.           extent: {
  88.             // autocasts as new Extent()
  89.             xmin: -179018.23379999958,
  90.             ymin: 5782901.2578,
  91.             xmax: 976907.7906999998,
  92.             ymax: 6641143.556299999,
  93.             spatialReference: 2600
  94.           },
  95.           zoom: 12,
  96.           scale: 100000,
  97.           center: [25.279652, 54.687157,] // longitude, latitude
  98.         });
  99.         /********************
  100.          * Add feature layer
  101.          ********************/
  102.  
  103.         // Carbon storage of trees in Warren Wilson College.
  104.         var featureLayer = new FeatureLayer({
  105.           url:
  106.             "https://services.arcgis.com/fFwZ4t9mPyCe14FA/arcgis/rest/services/HBContent_DMGRFA_G1KM/FeatureServer",
  107.              opacity: 0.5
  108.         });
  109.  
  110.         map.add(featureLayer);
  111.        
  112.         view.when(function() {
  113.           var print = new Print({
  114.             view: view,
  115.             // specify your own print service
  116.             printServiceUrl:
  117.               "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
  118.           });
  119.  
  120.           // Add widget to the top right corner of the view
  121.           view.ui.add(print, "top-right");
  122.         });
  123.        
  124.        
  125.           var featureLayerDistricts = new FeatureLayer({
  126.           url:
  127.             "https://services.arcgis.com/fFwZ4t9mPyCe14FA/arcgis/rest/services/HBContent_RTNGAS15/FeatureServer",
  128.           popupTemplate: {
  129.             // autocasts as new PopupTemplate()
  130.             title: "Pavadinimas: {MOKYKLA} </br>Reitingas 2014 : {REITINGAS2014_LT}</br>Reitingas 2015 : {REITINGAS2015_LT}",
  131.             overwriteActions: true
  132.           }
  133.         });
  134.  
  135.         var featureLayerSenators = new FeatureLayer({
  136.           url:
  137.             "https://services.arcgis.com/fFwZ4t9mPyCe14FA/arcgis/rest/services/HBContent_STMBGBRTES/FeatureServer",
  138.           popupTemplate: {
  139.             // autocasts as new PopupTemplate()
  140.              title: "Savivaldybe: {SAV} </br>Adresas:{ADR}</br>Telefonas: {TEL} </br>Darbo laikas: {DL} </br>",
  141.             overwriteActions: true
  142.           }
  143.         });
  144.  
  145.         var searchWidget = new Search({
  146.           view: view,
  147.           allPlaceholder: "Mokykla",
  148.           sources: [
  149.             {
  150.               layer: featureLayerDistricts,
  151.               searchFields: ["MOKYKLA"],
  152.               displayField: "MOKYKLA",
  153.               exactMatch: false,
  154.               outFields: ["MOKYKLOS_ID", "MOKYKLA", "SAVIVALDYBE"],
  155.               name: "Mokyklos pavadinimas",
  156.               placeholder: "example: Klaipedos Vytauto didiojo gimnazija"
  157.             },
  158.             {
  159.               layer: featureLayerSenators,
  160.               searchFields: ["SAV","ADR"],
  161.               suggestionTemplate: "{SAV},{ADR}",
  162.               exactMatch: false,
  163.               outFields: ["*"],
  164.               placeholder: "pavyzdziui: Vilniaus",
  165.               name: "Stambiagabariciu savivaldybe ar adresas",
  166.             }
  167.           ]
  168.         });
  169.  
  170.         // Add the search widget to the top left corner of the view
  171.         view.ui.add(searchWidget, {
  172.           position: "bottom-right"
  173.         });
  174.         var locateBtn = new Locate({
  175.           view: view
  176.         });
  177.  
  178.         // Add the locate widget to the top left corner of the view
  179.         view.ui.add(locateBtn, {
  180.           position: "top-left"
  181.         });
  182.         var basemapGallery = new BasemapGallery({
  183.           view: view,
  184.           container: document.createElement("div")
  185.         });
  186.  
  187.         // Create an Expand instance and set the content
  188.         // property to the DOM node of the basemap gallery widget
  189.         // Use an Esri icon font to represent the content inside
  190.         // of the Expand widget
  191.  
  192.         var bgExpand = new Expand({
  193.           view: view,
  194.           content: basemapGallery
  195.         });
  196.  
  197.         // close the expand whenever a basemap is selected
  198.         basemapGallery.watch("activeBasemap", function() {
  199.           var mobileSize =
  200.             view.heightBreakpoint === "xsmall" ||
  201.             view.widthBreakpoint === "xsmall";
  202.  
  203.           if (mobileSize) {
  204.             bgExpand.collapse();
  205.           }
  206.         });
  207.  
  208.         // Add the expand instance to the ui
  209.  
  210.         view.ui.add(bgExpand, "top-right");
  211.  
  212.         /*****************************************************************
  213.          * The map handles the layers' data while the view and layer views
  214.          * take care of renderering the layers
  215.          *****************************************************************/
  216.         view.on("layerview-create", function(event) {
  217.           if (event.layer.id === "ny-housing") {
  218.             // Explore the properties of the population layer's layer view here
  219.             console.log(
  220.               "LayerView for male population created!",
  221.               event.layerView
  222.             );
  223.           }
  224.           if (event.layer.id === "streets") {
  225.             // Explore the properties of the transportation layer's layer view here
  226.             // Explore the properties of the transportation layer's layer view here
  227.             console.log("LayerView for streets created!", event.layerView);
  228.           }
  229.         });
  230.  
  231.         /*****************************************************************
  232.          * Layers are promises that resolve when loaded, or when all their
  233.          * properties may be accessed. Once the population layer has loaded,
  234.          * the view will animate to it's initial extent.
  235.          *****************************************************************/
  236.         view.when(function() {
  237.           housingLayer.when(function() {
  238.             view.goTo(housingLayer.fullExtent);
  239.           });
  240.         });
  241.  
  242.         var streetsLayerToggle = document.getElementById("streetsLayer");
  243.  
  244.         /*****************************************************************
  245.          * The visible property on the layer can be used to toggle the
  246.          * layer's visibility in the view. When the visibility is turned off
  247.          * the layer is still part of the map, which means you can access
  248.          * its properties and perform analysis even though it isn't visible.
  249.          *******************************************************************/
  250.         streetsLayerToggle.addEventListener("change", function() {
  251.           transportationLayer.visible = streetsLayerToggle.checked;
  252.         });
  253.       /*************************
  254.          * Create a point graphic
  255.          *************************/
  256.  
  257.         // First create a point geometry (this is the location of the Titanic)
  258.         var point = {
  259.           type: "point", // autocasts as new Point()
  260.           longitude: -70,
  261.           latitude: 25
  262.         };
  263.  
  264.         // Create a symbol for drawing the point
  265.         var markerSymbol = {
  266.           type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
  267.           color: [255, 0, 0],
  268.           outline: {
  269.             // autocasts as new SimpleLineSymbol()
  270.             color: [0, 0, 0],
  271.             width: 3
  272.           }
  273.         };
  274.  
  275.         // Create a graphic and add the geometry and symbol to it
  276.         var pointGraphic = new Graphic({
  277.           geometry: point,
  278.           symbol: markerSymbol
  279.         });
  280.  
  281.         /****************************
  282.          * Create a polyline graphic
  283.          ****************************/
  284.  
  285.         // First create a line geometry (this is the Keystone pipeline)
  286.         var polyline = {
  287.           type: "polyline", // autocasts as new Polyline()
  288.           paths: [[-111.3, 52.68], [-98, 49.5], [-93.94, 29.89]]
  289.         };
  290.  
  291.         // Create a symbol for drawing the line
  292.         var lineSymbol = {
  293.           type: "simple-line", // autocasts as SimpleLineSymbol()
  294.           color: [226, 119, 40],
  295.           width: 4
  296.         };
  297.  
  298.         // Create an object for storing attributes related to the line
  299.         var lineAtt = {
  300.           Name: "Keystone Pipeline",
  301.           Owner: "TransCanada",
  302.           Length: "3,456 km"
  303.         };
  304.  
  305.         /*******************************************
  306.          * Create a new graphic and add the geometry,
  307.          * symbol, and attributes to it. You may also
  308.          * add a simple PopupTemplate to the graphic.
  309.          * This allows users to view the graphic's
  310.          * attributes when it is clicked.
  311.          ******************************************/
  312.         var polylineGraphic = new Graphic({
  313.           geometry: polyline,
  314.           symbol: lineSymbol,
  315.           attributes: lineAtt,
  316.           popupTemplate: {
  317.             // autocasts as new PopupTemplate()
  318.             title: "{Name}",
  319.             content: [
  320.               {
  321.                 type: "fields",
  322.                 fieldInfos: [
  323.                   {
  324.                     fieldName: "Name"
  325.                   },
  326.                   {
  327.                     fieldName: "Owner"
  328.                   },
  329.                   {
  330.                     fieldName: "Length"
  331.                   }
  332.                 ]
  333.               }
  334.             ]
  335.           }
  336.         });
  337.  
  338.         /***************************
  339.          * Create a polygon graphic
  340.          ***************************/
  341.  
  342.         // Create a polygon geometry
  343.         var polygon = {
  344.           type: "polygon", // autocasts as new Polygon()
  345.           rings: [
  346.             [140,36],
  347.             [130,36],
  348.             [130,30],
  349.             [140,30],
  350.           ]
  351.         };
  352.  
  353.         // Create a symbol for rendering the graphic
  354.         var fillSymbol = {
  355.           type: "simple-fill", // autocasts as new SimpleFillSymbol()
  356.           color: [255, 255, 255, 1],
  357.           outline: {
  358.             // autocasts as new SimpleLineSymbol()
  359.             color: [0, 0, 0],
  360.             width: 1
  361.           }
  362.         };
  363.        
  364.        
  365.  
  366.         // Add the geometry and symbol to a new graphic
  367.         var polygonGraphic = new Graphic({
  368.           geometry: polygon,
  369.           symbol: fillSymbol
  370.         });
  371.        
  372.         /*************************
  373.          * Create a point graphic
  374.          *************************/
  375.  
  376.         // First create a point geometry (this is the location of the Titanic)
  377.         var point1 = {
  378.           type: "point", // autocasts as new Point()
  379.           longitude: 135,
  380.           latitude: 33,
  381.           width: 5
  382.         };
  383.  
  384.         // Create a symbol for drawing the point
  385.         var markerSymbol1 = {
  386.           type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
  387.           color: [255, 0, 0],
  388.           outline: {
  389.             // autocasts as new SimpleLineSymbol()
  390.             color: [0, 0, 0],
  391.             width: 1
  392.           }
  393.         };
  394.  
  395.         // Create a graphic and add the geometry and symbol to it
  396.         var pointGraphic1 = new Graphic({
  397.           geometry: point1,
  398.           symbol: markerSymbol1
  399.         });
  400.        
  401.         /****************************
  402.          * Create a polyline graphic
  403.          ****************************/
  404.  
  405.         // First create a line geometry (this is the Keystone pipeline)
  406.         var polyline1 = {
  407.           type: "polyline", // autocasts as new Polyline()
  408.           paths: [[130, 36.5], [130, 24]]
  409.         };
  410.  
  411.         // Create a symbol for drawing the line
  412.         var lineSymbol1 = {
  413.           type: "simple-line", // autocasts as SimpleLineSymbol()
  414.           color: [0, 0, 0],
  415.           width: 4
  416.         };
  417.  
  418.         // Create an object for storing attributes related to the line
  419.         var lineAtt1 = {
  420.           Name: "Keystone Pipeline",
  421.           Owner: "TransCanada",
  422.           Length: "3,456 km"
  423.         };
  424.  
  425.         /*******************************************
  426.          * Create a new graphic and add the geometry,
  427.          * symbol, and attributes to it. You may also
  428.          * add a simple PopupTemplate to the graphic.
  429.          * This allows users to view the graphic's
  430.          * attributes when it is clicked.
  431.          ******************************************/
  432.         var polylineGraphic1 = new Graphic({
  433.           geometry: polyline1,
  434.           symbol: lineSymbol1,
  435.           attributes: lineAtt1,
  436.           popupTemplate: {
  437.             // autocasts as new PopupTemplate()
  438.             title: "{Name}",
  439.             content: [
  440.               {
  441.                 type: "fields",
  442.                 fieldInfos: [
  443.                   {
  444.                     fieldName: "Name"
  445.                   },
  446.                   {
  447.                     fieldName: "Owner"
  448.                   },
  449.                   {
  450.                     fieldName: "Length"
  451.                   }
  452.                 ]
  453.               }
  454.             ]
  455.           }
  456.         });
  457.  
  458.         // Add the graphics to the view's graphics layer
  459.         view.graphics.addMany([pointGraphic, polylineGraphic, polygonGraphic,pointGraphic1,polylineGraphic1]);
  460.       });
  461.     </script>
  462.   </head>
  463.  
  464.   <body>
  465.     <div id="viewDiv"></div>
  466.     <span id="layerToggle" class="esri-widget">
  467.       <input type="checkbox" id="streetsLayer" /> Transportation
  468.     </span>
  469.   </body>
  470. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement