1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| <template> <div id="home"> <el-breadcrumb separator-class="el-icon-arrow-right"> <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item> <el-breadcrumb-item>Map</el-breadcrumb-item> <el-breadcrumb-item>Geometry</el-breadcrumb-item> </el-breadcrumb> <div id="map"></div> <el-row style="position: absolute; top: 100px; left: 300px; width: 1200px;"> <el-button plain>简单点</el-button> <el-button plain>图片点</el-button> <el-button plain>基本线</el-button> <el-button plain>箭头线</el-button> <el-button plain>面样式1</el-button> <el-button plain>面样式2</el-button> <el-button plain>绘制多点</el-button> <el-button plain>自由线</el-button> <el-button plain>自由面</el-button> <el-button plain>圆</el-button> <el-button plain>矩形</el-button> </el-row> </div> </template>
<script> import * as esriLoader from 'esri-loader'
export default { data() { return {} }, mounted() { esriLoader.setDefaultOptions({ version: '3.31' }) this.createMap() }, methods: { createMap: function () { esriLoader.loadModules(['esri/map', 'dojo/dom', 'dojo/on', 'esri/layers/ArcGISDynamicMapServiceLayer', 'esri/geometry/Point', 'esri/geometry/Polyline', 'esri/graphic', 'esri/Color', 'esri/symbols/SimpleMarkerSymbol', 'esri/symbols/SimpleLineSymbol', 'esri/symbols/SimpleFillSymbol', 'esri/symbols/PictureMarkerSymbol', 'esri/renderers/SimpleRenderer', 'dojo/query', 'esri/toolbars/draw', 'esri/SpatialReference', 'dojo/domReady!'], { css: true }) .then(([Map, dom, on, ArcGISDynamicMapServiceLayer, Point, Polyline, Graphic, Color, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol, SimpleRenderer, query, Draw, SpatialReferenc]) => { var map = new Map('map', { center: [108.934518, 34.35333], zoom: 7, logo: false, basemap: 'oceans' }) map.on('load', () => { var toolbar = new Draw(map, { showTooltips: true }) var smpPoint = true var smpLine = true var smpPloy = true
query('button').on('click', function (event) { var value = this.innerHTML console.log(value) value = value.replace(new RegExp('^\\' + '<!----><!----><span>' + '+', 'g'), '') value = value.replace(new RegExp('\\' + '</span>' + '+$', 'g'), '') console.log(value) switch (value) { case '简单点': { toolbar.activate(Draw.POINT, { showTooltips: true }) smpPoint = true break } case '图片点': { toolbar.activate(Draw.POINT, { showTooltips: true }) smpPoint = false break } case '基本线': { toolbar.activate(Draw.POLYLINE, { showTooltips: true }) smpLine = true break } case '箭头线': { toolbar.activate(Draw.POLYLINE, { showTooltips: true }) smpLine = false break } case '面样式1': { toolbar.activate(Draw.POLYGON, { showTooltips: true }) smpPloy = true break } case '面样式2': { toolbar.activate(Draw.POLYGON, { showTooltips: true }) smpPloy = false break } case '绘制多点': { toolbar.activate(Draw.MULTI_POINT, { showTooltips: true }) break } case '自由线': { toolbar.activate(Draw.FREEHAND_POLYLINE, { showTooltips: true }) break } case '自由面': { toolbar.activate(Draw.FREEHAND_POLYGON, { showTooltips: true }) break } case '圆': { toolbar.activate(Draw.CIRCLE, { showTooltips: true }) break } case '矩形': { toolbar.activate(Draw.RECTANGLE, { showTooltips: true }) break } }
var lineSymbol1 = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new Color([0, 25, 0]), 1) var lineSymbol2 = new SimpleLineSymbol(SimpleLineSymbol.STYLE_LONGDASHDOT, new Color([225, 0, 0]), 1)
var outLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOTDOT, new Color([235, 235, 5]), 3) var marker = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, lineSymbol1, new Color([215, 224, 203])) var fill1 = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, outLineSymbol, new Color([48, 190, 144, 0.5])) var fill2 = new SimpleFillSymbol(SimpleFillSymbol.STYLE_DIAGONAL_CROSS, lineSymbol1, new Color([48, 190, 144]))
var pictureMarkerSymbol = new PictureMarkerSymbol('https://gtms04.alicdn.com/tps/i4/TB1_oz6GVXXXXaFXpXXJDFnIXXX-64-64.ico', 20, 20)
lineSymbol2.setMarker({ style: 'arrow', placement: 'end' })
on(toolbar, 'draw-complete', function (result) { var geometry = result.geometry var type = geometry.type var graphic switch (type) { case 'point': if (smpPoint) graphic = new Graphic(geometry, marker) else graphic = new Graphic(geometry, pictureMarkerSymbol) break case 'polyline': if (smpLine) graphic = new Graphic(geometry, lineSymbol1) else graphic = new Graphic(geometry, lineSymbol2) break case 'polygon': if (smpPloy) graphic = new Graphic(geometry, fill1) else graphic = new Graphic(geometry, fill2) break case 'multipoint': graphic = new Graphic(geometry, marker) break } console.log(map.graphics.renderer) map.graphics.add(graphic) toolbar.deactivate() }) }) }) }) } } } </script>
|