ArcGIS 绘制多边形拖拽编辑旋转

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
  5.   <meta name=“viewport” content=“width=device-width,user-scalable=no”>
  6.   <meta name=“viewport” content=“initial-scale=1, maximum-scale=1,user-scalable=no”>
  7.   <title>地图</title>
  8.   <link rel=“stylesheet” href=“https://js.arcgis.com/3.38/dijit/themes/nihilo/nihilo.css”>
  9.   <link rel=“stylesheet” href=“https://js.arcgis.com/3.38/esri/css/esri.css”>
  10.   <style>
  11.     html,
  12.     body,
  13.     #mainWindow {
  14.       font-family: sans-serif;
  15.       height: 100%;
  16.       width: 100%;
  17.     }
  18.     html,
  19.     body {
  20.       margin: 0;
  21.       padding: 0;
  22.     }
  23.     #header {
  24.       height: 80px;
  25.       overflow: auto;
  26.       padding: 0.5em;
  27.     }
  28.   </style>
  29.   <script src=“https://js.arcgis.com/3.38/”></script>
  30.   <script>
  31.     var map, toolbar, symbol, geomTask;
  32.     require([
  33.       “esri/map”,
  34.       “esri/toolbars/draw”,
  35.       “esri/graphic”,
  36.       “esri/toolbars/edit”,
  37.       “esri/symbols/SimpleMarkerSymbol”,
  38.       “esri/symbols/SimpleLineSymbol”,
  39.       “esri/symbols/SimpleFillSymbol”,
  40.       “esri/geometry/Point”“esri/SpatialReference”// 坐标转换
  41.       “dojo/parser”“dijit/registry”“dijit/Menu”“dijit/MenuItem”“dijit/MenuSeparator”,
  42.       “dijit/layout/BorderContainer”“dijit/layout/ContentPane”,
  43.       “dijit/form/Button”“dijit/WidgetSet”“dojo/domReady!”,
  44.     ], function (
  45.       Map, Draw, Graphic, Edit,
  46.       SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
  47.       Point, SpatialReference,
  48.       parser, registry, Menu, MenuItem, MenuSeparator
  49.     ) {
  50.       parser.parse();
  51.       map = new esri.Map(“map”);
  52.       var layer = new esri.layers.ArcGISDynamicMapServiceLayer(“http://127.0.0.1:88/arcgis/rest/services/MyMapService/MapServer”);
  53.       map.addLayer(layer);
  54.       map.on(“load”, createToolbar);
  55.       // loop through all dijits, connect onClick event
  56.       // listeners for buttons to activate drawing tools
  57.       registry.forEach(function (d) {
  58.         // d is a reference to a dijit
  59.         // could be a layout container or a button
  60.         if (d.declaredClass === “dijit.form.Button”) {
  61.           d.on(“click”, activateTool);
  62.         }
  63.       });
  64.       function activateTool() {
  65.         debugger
  66.         var tool = this[‘data-s’].toUpperCase().replace(/ /g, “_”);
  67.         //var tool = this.label.toUpperCase().replace(/ /g, “_”);
  68.         toolbar.activate(Draw[tool]);
  69.         map.hideZoomSlider();
  70.       }
  71.       function createGraphicsMenu() {
  72.         // Creates right-click context menu for GRAPHICS
  73.         ctxMenuForGraphics = new Menu({});
  74.         ctxMenuForGraphics.addChild(new MenuItem({
  75.           label: “Edit”,
  76.           onClick: function () {
  77.             if (selected.geometry.type !== “point”) {
  78.               editToolbar.activate(Edit.EDIT_VERTICES, selected);
  79.             } else {
  80.               alert(“Not implemented”);
  81.             }
  82.           }
  83.         }));
  84.         ctxMenuForGraphics.addChild(new MenuItem({
  85.           label: “Move”,
  86.           onClick: function () {
  87.             editToolbar.activate(Edit.MOVE, selected);
  88.           }
  89.         }));
  90.         ctxMenuForGraphics.addChild(new MenuItem({
  91.           label: “Rotate/Scale”,
  92.           onClick: function () {
  93.             if (selected.geometry.type !== “point”) {
  94.               editToolbar.activate(Edit.ROTATE | Edit.SCALE, selected);
  95.             } else {
  96.               alert(“Not implemented”);
  97.             }
  98.           }
  99.         }));
  100.         ctxMenuForGraphics.addChild(new MenuItem({
  101.           label: “Style”,
  102.           onClick: function () {
  103.             alert(“Not implemented”);
  104.           }
  105.         }));
  106.         ctxMenuForGraphics.addChild(new MenuSeparator());
  107.         ctxMenuForGraphics.addChild(new MenuItem({
  108.           label: “Delete”,
  109.           onClick: function () {
  110.             map.graphics.remove(selected);
  111.           }
  112.         }));
  113.         ctxMenuForGraphics.startup();
  114.         map.graphics.on(“mouse-over”, function (evt) {
  115.           // We’ll use this “selected” graphic to enable editing tools
  116.           // on this graphic when the user click on one of the tools
  117.           // listed in the menu.
  118.           selected = evt.graphic;
  119.           // Let’s bind to the graphic underneath the mouse cursor           
  120.           ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode());
  121.         });
  122.         map.graphics.on(“mouse-out”, function (evt) {
  123.           ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode());
  124.         });
  125.       }
  126.       function createToolbar(themap) {
  127.         toolbar = new Draw(map);
  128.         toolbar.on(“draw-end”, addToMap);
  129.         editToolbar = new Edit(map);
  130.         map.on(“click”, function (evt) {
  131.           editToolbar.deactivate();
  132.         });
  133.         createGraphicsMenu();
  134.         // // 绘制多边形
  135.         // var features = [];
  136.         //     var point;
  137.         //     var rrr = {“name”:”MapServer”,”contents”:{“currentVersion”:10.22,”serviceDescription”:”555″,”mapName”:”图层”,”description”:””,”copyrightText”:”555″,”supportsDynamicLayers”:false,”layers”:[{“id”:0,”name”:”平度城区.tif”,”parentLayerId”:-1,”defaultVisibility”:true,”subLayerIds”:null,”minScale”:0,”maxScale”:0}],”tables”:[],”spatialReference”:{“wkid”:4528,”latestWkid”:4528},”singleFusedMapCache”:false,”initialExtent”:{“xmin”:40478239.026188038,”ymin”:4053735.2164187105,”xmax”:40529369.857616372,”ymax”:4082442.5655000778,”spatialReference”:{“wkid”:4528,”latestWkid”:4528}},”fullExtent”:{“xmin”:40485303.75,”ymin”:4063282.75,”xmax”:40507771.25,”ymax”:4078681.25,”spatialReference”:{“wkid”:4528,”latestWkid”:4528}},”minScale”:0,”maxScale”:0,”units”:”esriMeters”,”supportedImageFormatTypes”:”PNG32,PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,BMP”,”documentInfo”:{“Title”:”555″,”Author”:”555″,”Comments”:”555″,”Subject”:”555″,”Category”:””,”AntialiasingMode”:”Best”,”TextAntialiasingMode”:”Force”,”Keywords”:”555″},”capabilities”:”Map,Query,Data”,”supportedQueryFormats”:”JSON, AMF”,”exportTilesAllowed”:false,”maxRecordCount”:1000,”maxImageHeight”:4096,”maxImageWidth”:4096},”resourceInfo”:{“geoFullExtent”:{“xmin”:119.83524155804163,”ymin”:36.700465163402825,”xmax”:120.08712295814964,”ymax”:36.839337310357443},”spatialReferenceDomain”:{“xmin”:34876800,”ymin”:-10002100,”xmax”:54881000,”ymax”:10002100},”geoInitialExtent”:{“xmin”:119.75593233031574,”ymin”:36.614090397640318,”xmax”:120.32940660177833,”ymax”:36.873230684107618}},”resources”:[{“name”:”layers”,”resources”:[{“name”:”0″,”contents”:{“currentVersion”:10.22,”id”:0,”name”:”平度城区.tif”,”type”:”Raster Layer”,”description”:””,”geometryType”:null,”copyrightText”:””,”parentLayer”:null,”subLayers”:[],”minScale”:0,”maxScale”:0,”defaultVisibility”:true,”extent”:{“xmin”:40485303.75,”ymin”:4063282.75,”xmax”:40507771.25,”ymax”:4078681.25,”spatialReference”:{“wkid”:4528,”latestWkid”:4528}},”hasAttachments”:false,”htmlPopupType”:”esriServerHTMLPopupTypeNone”,”displayField”:””,”typeIdField”:null,”fields”:null,”relationships”:[],”canModifyLayer”:false,”canScaleSymbols”:false,”hasLabels”:false,”capabilities”:”Map,Query”,”supportsStatistics”:false,”supportsAdvancedQueries”:false,”supportedQueryFormats”:”JSON, AMF”,”ownershipBasedAccessControlForFeatures”:{“allowOthersToQuery”:true}}}]},{“name”:”tables”,”resources”:[]},{“name”:”legend”,”contents”:{“layers”:[{“layerId”:0,”layerName”:”平度城区.tif”,”layerType”:”栅格图层”,”minScale”:0,”maxScale”:0,”legend”:[{“label”:”红色:    Band_1″,”url”:”f7ea40b015f1d60df04924009513e076″,”imageData”:”iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAGZJREFUOI3t1LENgDAMBMAvLP0oWYS98ABmp6zBKN/RQBQoKGIqlG9sWdbJlQ0fx66GpGcgSd5Akr5JaxnEKoAgIcnbhQXAkrgwzmqvWwOZ4AQn+DOwJpD9CUryINsLGsntwfaDbA4UQBrHRWb9BwAAAABJRU5ErkJggg==”,”contentType”:”image/png”,”height”:20,”width”:20},{“label”:”绿色: Band_2″,”url”:”7dc83efc664def88ff1e522221ec5006″,”imageData”:”iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAGdJREFUOI3t1LEJgEAMBdBfBP4ot4h7mQHOnW4NR/mdhXioheDFSvKbhBAeqWL4OHY0JD0CSfIOknQtmlEGtQawEpK8X4gCYAqcWPdiz1vvk2CCCf4NbAFlvYGSnJX9BY3k8mDPg2g2D58ax6zV9GcAAAAASUVORK5CYII=”,”contentType”:”image/png”,”height”:20,”width”:20},{“label”:”蓝色:   Band_3″,”url”:”86fe416a22892c6789f665345a7f11b6″,”imageData”:”iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAGNJREFUOI3t1KERwDAMA0CB3GmULNK96gHcnbJGRxErStrQOKhnIZ/An5ALNqf0g6RFIEk2QJImXSdQF7kG0iHJyltWAEdgo2Ms3JkEE0zwd2ALMPcMSjLS0V/QSqYH+y2ieQAK/hrH3cWcAgAAAABJRU5ErkJggg==”,”contentType”:”image/png”,”height”:20,”width”:20}]}]}}]};
  138.         //     rrr.resources[0].resources.forEach(function (item) {
  139.         //       debugger
  140.         //       var attr = {};
  141.         //       attr[“description”] = item.name;
  142.         //       attr[“title”] = ‘测试文字1111’
  143.         //       var symbol = new SimpleFillSymbol({
  144.         //         “type”: “esriSFS”, “style”: “esriSFSSolid”, “color”: item.bg,
  145.         //         //背景色在服务器数据中定义 
  146.         //         “outline”: {//轮廓 
  147.         //           “type”: “esriSLS”, “style”: “esriSLSSolid”, “color”: item.outline, “width”: 1
  148.         //         }
  149.         //       });
  150.         //       //绘制一个多边形
  151.         //       var polygon = new Polygon(new SpatialReference({ wkid: 4326 }));
  152.         //       polygon.addRing(item.polygon); 
  153.         //       var graphic = new Graphic(polygon, symbol);
  154.         //       graphic.setAttributes(attr);
  155.         //       point = new Point([item.longitude, item.latitude], new SpatialReference({ wkid: 4326 }));
  156.         //       features.push(graphic);//画好的多边形加到要素集 
  157.         //     });
  158.         //     results.layers.forEach(function (resultitem) {//要素集加到图层 
  159.         //       resultitem.layer.applyEdits(features, null, null);
  160.         //     });
  161.       }
  162.       function addToMap(evt) {
  163.         var symbol;
  164.         toolbar.deactivate();
  165.         map.showZoomSlider();
  166.         switch (evt.geometry.type) {
  167.           case “point”:
  168.           case “multipoint”:
  169.             symbol = new SimpleMarkerSymbol();
  170.             break;
  171.           case “polyline”:
  172.             symbol = new SimpleLineSymbol();
  173.             break;
  174.           default:
  175.             symbol = new SimpleFillSymbol();
  176.             break;
  177.         }
  178.         var point = new Point(40498306.344383034068339.8746763663new SpatialReference(4528))
  179.         debugger
  180.         console.log(point)
  181.         var graphic = new Graphic(evt.geometry, symbol);
  182.         map.graphics.add(graphic);
  183.       }
  184.     });
  185.   </script>
  186. </head>
  187. <body class=“nihilo”>
  188.   <div id=“mainWindow” data-dojo-type=“dijit/layout/BorderContainer” data-dojo-props=“design:’headline'”>
  189.     <div id=“header” data-dojo-type=“dijit/layout/ContentPane” data-dojo-props=“region:’top'”>
  190.       <!– <button data-dojo-type=“dijit/form/Button”>Point</button>
  191.       <button data-dojo-type=“dijit/form/Button”>Multi Point</button>
  192.       <button data-dojo-type=“dijit/form/Button”>Line</button>
  193.       <button data-dojo-type=“dijit/form/Button”>Polyline</button>
  194.       <button data-dojo-type=“dijit/form/Button”>Polygon</button>
  195.       <button data-dojo-type=“dijit/form/Button”>Freehand Polyline</button>
  196.       <button data-dojo-type=“dijit/form/Button”>Freehand Polygon</button>
  197.       <button data-dojo-type=“dijit/form/Button”>Arrow</button>
  198.       <button data-dojo-type=“dijit/form/Button”>Triangle</button>
  199.       <button data-dojo-type=“dijit/form/Button”>Circle</button>
  200.       <button data-dojo-type=“dijit/form/Button”>Ellipse</button> –>
  201.       <button data-dojo-type=“dijit/form/Button” data-s=“Polygon”>标注</button>
  202.     </div>
  203.     <div id=“map” data-dojo-type=“dijit/layout/ContentPane” data-dojo-props=“region:’center'”></div>
  204.   </div>
  205. </body>
  206. </html>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注