# 给出引用

var chkMapView = false, chkSceneView = false;require([
"esri/Map", "esri/views/SceneView",  "esri/views/MapView",
"esri/layers/GraphicsLayer", "esri/Graphic",
"esri/symbols/SimpleMarkerSymbol","esri/symbols/SimpleFillSymbol",
"esri/geometry/geometryEngine",
"dojo/on",
"dojo/dom",
],
function(
Map,SceneView,MapView,
GraphicsLayer,Graphic,
SimpleMarkerSymbol,SimpleFillSymbol,
geometryEngine,
on, dom
){...}
);

# 骨架

function(...)
{
var map = new Map({...});
var view3d = new SceneView({...});
var view2d = new MapView({...});
var polySym = new SimpleFillSymbol({...});    var pointSym = new SimpleMarkSymbol({...});

var bufferLayer = new GraphicsLayer();
var pointLayer = new GraphicsLayer();

view2d.on('drag', function(evt){...});
view3d.on('drag', function(evt){...});
view2d.on("click", function(evt){...});
view3d.on('click', function(evt){...});

function bufferPoint(point){...}
function clearGraphics(){...}

on(dom.byId("chkBoxMap"), "click", function(evt){...});
on(dom.byId("chkBoxScene"), "click", function(evt){...});
}

//题外话：老外估计写这个demo也是交叉混写的，双引号和单引号随便用，同一章不同例子的函数参数名有时候也是随便写，可能是js的语言特性吧。

var polySym = new SimpleFillSymbol({
color: [140, 140, 222, 0.5],
outline: {
color: [0, 0, 0, 0.5],
width: 2
}
});

var pointSym = new SimpleMarkerSymbol({
color: [255, 0, 0],
outline: {
color: [255, 255, 255],
width: 1
},
size: 7
});

# 两个方法体：生成缓冲区与清理图层

function bufferPoint(point) {
clearGraphics();

geometry: point,
symbol: pointSym
}));

var buffer = geometryEngine.geodesicBuffer(point, 560, "kilometers");
geometry: buffer,
symbol: polySym
}));
}

function clearGraphics() {
pointLayer.removeAll();
bufferLayer.removeAll();
}

——————

on(dom.byId("chkBoxMap"), "click", function(evt) {
chkMapView = dom.byId("chkBoxMap").checked;
if (chkMapView) {
clearGraphics();
}
});

on(dom.byId("chkBoxScene"), "click", function(evt) {
chkSceneView = dom.byId("chkBoxScene").checked;
if (chkSceneView) {
clearGraphics();
}
});

view2d.on('drag', function(evt) {
if (!chkMapView) {
evt.stopPropagation();
var point = view2d.toMap({
x: evt.x,
y: evt.y
});
if (point) {
bufferPoint(point);
}
}
else if (chkMapView) {
clearGraphics();
}
});

view3d.on('drag', function(evt) {
if (!chkSceneView) {
evt.stopPropagation();
var point = view3d.toMap({
x: evt.x,
y: evt.y
});
if (point) {
point.hasZ = false;
point.z = undefined;
bufferPoint(point);
}
}
else if (chkSceneView) {
clearGraphics();
}
});
drag事件

view2d.on("click", function(evt) {
if (!chkMapView) {
if (evt.mapPoint) {
bufferPoint(evt.mapPoint);
}
}
else if (chkMapView) {
clearGraphics();
}
});

view3d.on('click', function(evt) {
if (!chkSceneView) {
if (evt.mapPoint) {
evt.mapPoint.hasZ = false;
evt.mapPoint.z = undefined;
bufferPoint(evt.mapPoint);
}
}
else if (chkSceneView) {
clearGraphics();
}
});
view的click事件

posted @ 2017-04-08 16:58  四季留歌  阅读(6207)  评论(2编辑  收藏  举报