如何正确响应ArcGIS JavaScript API中图形的鼠标事件
1个回答
展开全部
在使用ArcGIS JavaScript API编写程序的时候,程序员往往需要完成这样一个功能:点击地图上的图形,自动进行专题GIS数据查询,当在地图非图形区域上点击时,自动进行底图兴趣点查询。
由于专题GIS图形是叠加在底图上的,所以我们在处理地图的鼠标点击事件时,就需要根据实际点击的位置和内容来对不同的数据进行查询。
ArcGIS JavaScript API为编程人员分别提供了针对地图对象和图形的两个鼠标点击事件。
下面是示例代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Test Map</title>
<link rel="stylesheet" href="/arcgis_js_api/library/3.17/3.17/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="/arcgis_js_api/library/3.17/3.17/esri/css/esri.css" />
<style>
html, body, #ui-map-view {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<script src="/arcgis_js_api/library/3.17/3.17/init.js"></script>
<script>
var myMap;
require([
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/symbols/SimpleMarkerSymbol",
"esri/map",
"dojo/on",
"esri/graphic",
"esri/geometry/Point",
"dojo/domReady!"
], function ( TileLayer,SimpleMarkerSymbol, Map, on,Graphic,Point){
var layer = new TileLayer(
"/ags/rest/services/WorldBaseMap/MapServer"
);
myMap = new Map("ui-map-view",{
center: [-111.87, 40.57]
});
myMap.addLayer(layer);
//地图鼠标点击响应事件
on(myMap,"click",function(e){
alert("map clicked");
});
myMap.on("load", function() {//图形鼠标点击响应事件
myMap.graphics.on("click",function(e){
alert("graphic clicked");
e.stopPropagation();
});
var g=new Graphic();
g.setGeometry(new Point([-111.87, 40.57]));
var simpleMarkerSymbol = new SimpleMarkerSymbol();
g.setSymbol(simpleMarkerSymbol);
myMap.graphics.add(g);
});
});
</script>
</head>
<body class="claro">
<div id="ui-map-view"></div>
</body>
</html>
由于专题GIS图形是叠加在底图上的,所以我们在处理地图的鼠标点击事件时,就需要根据实际点击的位置和内容来对不同的数据进行查询。
ArcGIS JavaScript API为编程人员分别提供了针对地图对象和图形的两个鼠标点击事件。
下面是示例代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Test Map</title>
<link rel="stylesheet" href="/arcgis_js_api/library/3.17/3.17/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="/arcgis_js_api/library/3.17/3.17/esri/css/esri.css" />
<style>
html, body, #ui-map-view {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<script src="/arcgis_js_api/library/3.17/3.17/init.js"></script>
<script>
var myMap;
require([
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/symbols/SimpleMarkerSymbol",
"esri/map",
"dojo/on",
"esri/graphic",
"esri/geometry/Point",
"dojo/domReady!"
], function ( TileLayer,SimpleMarkerSymbol, Map, on,Graphic,Point){
var layer = new TileLayer(
"/ags/rest/services/WorldBaseMap/MapServer"
);
myMap = new Map("ui-map-view",{
center: [-111.87, 40.57]
});
myMap.addLayer(layer);
//地图鼠标点击响应事件
on(myMap,"click",function(e){
alert("map clicked");
});
myMap.on("load", function() {//图形鼠标点击响应事件
myMap.graphics.on("click",function(e){
alert("graphic clicked");
e.stopPropagation();
});
var g=new Graphic();
g.setGeometry(new Point([-111.87, 40.57]));
var simpleMarkerSymbol = new SimpleMarkerSymbol();
g.setSymbol(simpleMarkerSymbol);
myMap.graphics.add(g);
});
});
</script>
</head>
<body class="claro">
<div id="ui-map-view"></div>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
黄先生
2024-12-26 广告
2024-12-26 广告
矩阵切换器就是将一路或多路视音频信号分别传输给一个或者多个显示设备,如两台电脑主机要共用一个显示器,矩阵切换器可以将两台电脑主机上的内容renyi切换到同一个或多个显示器上;迈拓维矩矩阵切换器种类齐全,性价比高,支持多种控制方式,为工程商采...
点击进入详情页
本回答由黄先生提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询