- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
- <meta name=“viewport” content=“width=device-width,user-scalable=no”>
- <meta name=“viewport” content=“initial-scale=1, maximum-scale=1,user-scalable=no”>
- <title>地图</title>
- <link rel=“stylesheet” href=“https://js.arcgis.com/3.38/dijit/themes/nihilo/nihilo.css”>
- <link rel=“stylesheet” href=“https://js.arcgis.com/3.38/esri/css/esri.css”>
- <style>
- html,
- body,
- #mainWindow {
- font-family: sans-serif;
- height: 100%;
- width: 100%;
- }
- html,
- body {
- margin: 0;
- padding: 0;
- }
- #header {
- height: 80px;
- overflow: auto;
- padding: 0.5em;
- }
- </style>
- <script src=“https://js.arcgis.com/3.38/”></script>
- <script>
- var map, toolbar, symbol, geomTask;
- require([
- “esri/map”,
- “esri/toolbars/draw”,
- “esri/graphic”,
- “esri/toolbars/edit”,
- “esri/symbols/SimpleMarkerSymbol”,
- “esri/symbols/SimpleLineSymbol”,
- “esri/symbols/SimpleFillSymbol”,
- “esri/geometry/Point”, “esri/SpatialReference”, // 坐标转换
- “dojo/parser”, “dijit/registry”, “dijit/Menu”, “dijit/MenuItem”, “dijit/MenuSeparator”,
- “dijit/layout/BorderContainer”, “dijit/layout/ContentPane”,
- “dijit/form/Button”, “dijit/WidgetSet”, “dojo/domReady!”,
- ], function (
- Map, Draw, Graphic, Edit,
- SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
- Point, SpatialReference,
- parser, registry, Menu, MenuItem, MenuSeparator
- ) {
- parser.parse();
- map = new esri.Map(“map”);
- var layer = new esri.layers.ArcGISDynamicMapServiceLayer(“http://127.0.0.1:88/arcgis/rest/services/MyMapService/MapServer”);
- map.addLayer(layer);
- map.on(“load”, createToolbar);
- // loop through all dijits, connect onClick event
- // listeners for buttons to activate drawing tools
- registry.forEach(function (d) {
- // d is a reference to a dijit
- // could be a layout container or a button
- if (d.declaredClass === “dijit.form.Button”) {
- d.on(“click”, activateTool);
- }
- });
- function activateTool() {
- debugger
- var tool = this[‘data-s’].toUpperCase().replace(/ /g, “_”);
- //var tool = this.label.toUpperCase().replace(/ /g, “_”);
- toolbar.activate(Draw[tool]);
- map.hideZoomSlider();
- }
- function createGraphicsMenu() {
- // Creates right-click context menu for GRAPHICS
- ctxMenuForGraphics = new Menu({});
- ctxMenuForGraphics.addChild(new MenuItem({
- label: “Edit”,
- onClick: function () {
- if (selected.geometry.type !== “point”) {
- editToolbar.activate(Edit.EDIT_VERTICES, selected);
- } else {
- alert(“Not implemented”);
- }
- }
- }));
- ctxMenuForGraphics.addChild(new MenuItem({
- label: “Move”,
- onClick: function () {
- editToolbar.activate(Edit.MOVE, selected);
- }
- }));
- ctxMenuForGraphics.addChild(new MenuItem({
- label: “Rotate/Scale”,
- onClick: function () {
- if (selected.geometry.type !== “point”) {
- editToolbar.activate(Edit.ROTATE | Edit.SCALE, selected);
- } else {
- alert(“Not implemented”);
- }
- }
- }));
- ctxMenuForGraphics.addChild(new MenuItem({
- label: “Style”,
- onClick: function () {
- alert(“Not implemented”);
- }
- }));
- ctxMenuForGraphics.addChild(new MenuSeparator());
- ctxMenuForGraphics.addChild(new MenuItem({
- label: “Delete”,
- onClick: function () {
- map.graphics.remove(selected);
- }
- }));
- ctxMenuForGraphics.startup();
- map.graphics.on(“mouse-over”, function (evt) {
- // We’ll use this “selected” graphic to enable editing tools
- // on this graphic when the user click on one of the tools
- // listed in the menu.
- selected = evt.graphic;
- // Let’s bind to the graphic underneath the mouse cursor
- ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode());
- });
- map.graphics.on(“mouse-out”, function (evt) {
- ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode());
- });
- }
- function createToolbar(themap) {
- toolbar = new Draw(map);
- toolbar.on(“draw-end”, addToMap);
- editToolbar = new Edit(map);
- map.on(“click”, function (evt) {
- editToolbar.deactivate();
- });
- createGraphicsMenu();
- // // 绘制多边形
- // var features = [];
- // var point;
- // 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}]}]}}]};
- // rrr.resources[0].resources.forEach(function (item) {
- // debugger
- // var attr = {};
- // attr[“description”] = item.name;
- // attr[“title”] = ‘测试文字1111’
- // var symbol = new SimpleFillSymbol({
- // “type”: “esriSFS”, “style”: “esriSFSSolid”, “color”: item.bg,
- // //背景色在服务器数据中定义
- // “outline”: {//轮廓
- // “type”: “esriSLS”, “style”: “esriSLSSolid”, “color”: item.outline, “width”: 1
- // }
- // });
- // //绘制一个多边形
- // var polygon = new Polygon(new SpatialReference({ wkid: 4326 }));
- // polygon.addRing(item.polygon);
- // var graphic = new Graphic(polygon, symbol);
- // graphic.setAttributes(attr);
- // point = new Point([item.longitude, item.latitude], new SpatialReference({ wkid: 4326 }));
- // features.push(graphic);//画好的多边形加到要素集
- // });
- // results.layers.forEach(function (resultitem) {//要素集加到图层
- // resultitem.layer.applyEdits(features, null, null);
- // });
- }
- function addToMap(evt) {
- var symbol;
- toolbar.deactivate();
- map.showZoomSlider();
- switch (evt.geometry.type) {
- case “point”:
- case “multipoint”:
- symbol = new SimpleMarkerSymbol();
- break;
- case “polyline”:
- symbol = new SimpleLineSymbol();
- break;
- default:
- symbol = new SimpleFillSymbol();
- break;
- }
- var point = new Point(40498306.34438303, 4068339.8746763663, new SpatialReference(4528))
- debugger
- console.log(point)
- var graphic = new Graphic(evt.geometry, symbol);
- map.graphics.add(graphic);
- }
- });
- </script>
- </head>
- <body class=“nihilo”>
- <div id=“mainWindow” data-dojo-type=“dijit/layout/BorderContainer” data-dojo-props=“design:’headline'”>
- <div id=“header” data-dojo-type=“dijit/layout/ContentPane” data-dojo-props=“region:’top'”>
- <!– <button data-dojo-type=“dijit/form/Button”>Point</button>
- <button data-dojo-type=“dijit/form/Button”>Multi Point</button>
- <button data-dojo-type=“dijit/form/Button”>Line</button>
- <button data-dojo-type=“dijit/form/Button”>Polyline</button>
- <button data-dojo-type=“dijit/form/Button”>Polygon</button>
- <button data-dojo-type=“dijit/form/Button”>Freehand Polyline</button>
- <button data-dojo-type=“dijit/form/Button”>Freehand Polygon</button>
- <button data-dojo-type=“dijit/form/Button”>Arrow</button>
- <button data-dojo-type=“dijit/form/Button”>Triangle</button>
- <button data-dojo-type=“dijit/form/Button”>Circle</button>
- <button data-dojo-type=“dijit/form/Button”>Ellipse</button> –>
- <button data-dojo-type=“dijit/form/Button” data-s=“Polygon”>标注</button>
- </div>
- <div id=“map” data-dojo-type=“dijit/layout/ContentPane” data-dojo-props=“region:’center'”></div>
- </div>
- </body>
- </html>
本文链接地址: ArcGIS 绘制多边形拖拽编辑旋转