请使用ArcGIS API for JavaScript编写一段网页代码,要求实现以鼠标点击为中心绘制不同半径的圆,用下拉框控制半径,绘制的圆要求空心。请给出网页代码
时间: 2024-03-12 22:46:28 浏览: 60
用代码实现ArcGIS中使用绘制的圆形选择要素
3星 · 编辑精心推荐
以下是一个使用ArcGIS API for JavaScript实现的网页代码,可以实现以鼠标点击为中心绘制不同半径的空心圆,同时使用下拉框控制圆的半径大小:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>ArcGIS API for JavaScript - Draw Circle</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.16/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#options {
position: absolute;
top: 20px;
left: 20px;
z-index: 1000;
background-color: white;
padding: 10px;
border-radius: 5px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/geometry/Circle",
"dojo/domReady!"
], function (Map, MapView, Graphic, GraphicsLayer, Circle) {
var map = new Map({
basemap: "gray-vector"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-122.4194, 37.7749],
zoom: 13
});
var graphicsLayer = new GraphicsLayer();
map.add(graphicsLayer);
var radiusSelect = document.getElementById("radiusSelect");
view.on("click", function (event) {
graphicsLayer.removeAll();
var radius = parseInt(radiusSelect.value);
var circle = new Circle({
center: event.mapPoint,
radius: radius
});
var circleGraphic = new Graphic({
geometry: circle,
symbol: {
type: "simple-fill",
style: "none",
outline: {
color: "red",
width: 2
}
}
});
graphicsLayer.add(circleGraphic);
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="options">
<label for="radiusSelect">Radius:</label>
<select id="radiusSelect">
<option value="100">100 meters</option>
<option value="500">500 meters</option>
<option value="1000">1 kilometer</option>
<option value="5000">5 kilometers</option>
<option value="10000">10 kilometers</option>
</select>
</div>
</body>
</html>
```
在这个网页代码中,我们创建了一个包含一个地图视图和一个下拉框的页面,通过下拉框可以选择不同的半径大小。当用户在地图上点击时,我们根据下拉框中选择的半径大小绘制一个圆,并添加到一个图形图层中。绘制的圆是空心的,使用红色线条作为边框。
阅读全文