ESRI Javascript API获取范围中的功能
解决了…我正在尝试获取分组图形的几何图形,如果不将graphic.attributes.baseGraphic添加到我必须创建的新图形中,我似乎无法获取x和y。有问题的代码具有“***”字符,用于定义有问题的部分ESRI Javascript API获取范围中的功能,javascript,esri,arcgis-js-api,Javascript,Esri,Arcgis Js Api,解决了…我正在尝试获取分组图形的几何图形,如果不将graphic.attributes.baseGraphic添加到我必须创建的新图形中,我似乎无法获取x和y。有问题的代码具有“***”字符,用于定义有问题的部分 handleMouseOver: function(evt) { var graphic = evt.graphic; var latlon = evt.graphic.geometry; //alert('x =' + latlon.x
handleMouseOver: function(evt) {
var graphic = evt.graphic;
var latlon = evt.graphic.geometry;
//alert('x =' + latlon.x + 'y =' + latlon.y);
if (graphic.symbol.type == 'textsymbol' || graphic.symbol.type == 'simplelinesymbol') {
if (graphic.attributes) {
if (graphic.attributes.baseGraphic && graphic.attributes.baseGraphic.task) {
graphic.attributes.baseGraphic.task.cancel();
}
}
//return;
}
if (graphic.attributes.isCluster) { //cluster mouse over
if (graphic.attributes.clustered) {
for (var i = 0; i < graphic.attributes.clusterSize; i++)
{
x = graphic.attributes[i].baseGraphic.geometry.x;
y = graphic.attributes[i].baseGraphic.geometry.y;
//alert('x=' + x + 'y=' + y);
}
if (graphic.task) {
graphic.task.cancel();
}
//return;
}
} else { //single marker or cluster flare mouse over
if (graphic.attributes.baseGraphic) { //cluster flare
graphic.attributes.baseGraphic.task.cancel();
}
this.showInfoWindow(graphic);
//return;
}
graphic.clusterGraphics = [];
//alert('x =' + latlon.x + 'y =' + latlon.y);
var cSize = graphic.attributes.clusterSize;
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0, 1]), 1);
//polyline used to "tie" flare to cluster
//set up initially with the center pt of the cluster as the first point and a dummy point @ 0,0 for a placeholder
var line = new esri.geometry.Polyline(map.spatialReference);
line.addPath([graphic.geometry, new esri.geometry.Point(0, 0)]);
//polyline graphic
var lineGraphic = new esri.Graphic(line, lineSymbol);
//creating a circle to evenly distribute our flare graphics around
if (cSize > 1 && cSize <= this._flareLimit) { //cSize > 1 may not be needed
//takes the number of points (flares) for the cluster
var numPoints = graphic.attributes.clusterSize;
//takes the pixel distance from the center of the graphic to flare out the graphics
var bufferDistance = this.getPixelDistanceFromCenter(graphic.geometry);
//center of cluster graphic
var centerPoint = graphic.geometry;
//variables used to plot points evenly around the cluster
var dblSinus, dblCosinus, x, y, pt, ptGraphic, p, l;
***for (var i = 0; i < graphic.attributes.clusterSize; i++) {
//constructing the flare graphic point
//pt = new esri.geometry.Point(x, y, this._map.spatialReference)
//ptGraphic = new esri.Graphic(pt, this.symbolBank.single, dojo.mixin(graphic.attributes[i], { baseGraphic: graphic }), this._infoTemplate);
x = graphic.attributes[i].baseGraphic.geometry.x;
y = graphic.attributes[i].baseGraphic.geometry.y;***
//constructing the flare graphic point
//pt = new esri.geometry.Point(x, y, this._map.spatialReference)
//ptGraphic = new esri.Graphic(pt, this.symbolBank.single, dojo.mixin(graphic.attributes[i], { baseGraphic: graphic }), this._infoTemplate);
//alert('pt.x=' + pt.x + 'pt.y=' + pt.y )
//try to always bring flare graphic to front of everything else
p = this.add(ptGraphic);
//p.getDojoShape().moveToFront();
//reset our 0,0 placeholder point in line to the actual point of the recently created flare graphic
line.setPoint(0, 1, pt);
lineGraphic = new esri.Graphic(line, lineSymbol, { baseGraphic: graphic });
//try to always have connector line behind everything else
l = this.add(lineGraphic);
//l.getDojoShape().moveToBack();
//store flare graphic and connector graphic
graphic.clusterGraphics.push(p);
graphic.clusterGraphics.push(l);
}
//set "clustered" flag
graphic.attributes.clustered = true;
}
},
handleMouseOver:功能(evt){
var图形=evt图形;
var latlon=evt.graphic.geometry;
//警报('x='+latlon.x+'y='+latlon.y);
if(graphic.symbol.type='textsymble'| | graphic.symbol.type==''simplelinesymbol'){
if(图形属性){
if(graphic.attributes.baseGraphic&&graphic.attributes.baseGraphic.task){
graphic.attributes.baseGraphic.task.cancel();
}
}
//返回;
}
如果(graphic.attributes.isCluster){//cluster鼠标悬停
if(graphic.attributes.clustered){
对于(var i=0;i1&&cSize 1可能不需要
//获取簇的点数(光斑)
var numPoints=graphic.attributes.clusterSize;
//从图形中心获取像素距离以展开图形
var bufferDistance=此.getPixelDistanceFromCenter(graphic.geometry);
//聚类中心图
var centerPoint=graphic.geometry;
//用于在簇周围均匀绘制点的变量
胸椎静脉窦,胸椎静脉窦,x,y,pt,ptGraphic,p,l;
***对于(var i=0;i
基于上述“有限问题”的这一部分:
“我正在尝试获取分组图形的几何图形”
我假设您正在使用esri ClusterLayer,如下所述:
如果是这样的话,我们现在开始:
鼠标悬停根本不理想,原因是群集图像只是PictureMarkerSymbol,在不同的断点处针对新的esri.renderer.ClassBreaksRenderer进行设置,例如:
var renderer = new esri.renderer.ClassBreaksRenderer(mapManager.pointFeatureSymbol, "clusterCount");
var blue = new esri.symbol.PictureMarkerSymbol("images/BluePin1LargeB.png", 32, 32).setOffset(0, 15);
var green = new esri.symbol.PictureMarkerSymbol("images/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
var red = new esri.symbol.PictureMarkerSymbol("images/RedPin1LargeB.png", 72, 72).setOffset(0, 15);
renderer.addBreak(0, 2, blue);
renderer.addBreak(2, 200, green);
renderer.addBreak(200, 1001, red);
您可以单击图像,而不是通过执行以下操作来获取图像:
现在假设您在某处有一个集群层对象:假设var clusterLayer=newclusterlayer
您可以附加一个事件
dojo.connect(map, "onClick", function (evt)
{
var mp = evt.mapPoint;
var cl= map.getLayer("Points");
for (var g in cl.graphics)
{
var graphic = cl.graphics[g];
if (graphic.geometry != null && graphic.geometry.type == "point")
{
var toleranceInPixel = 10;
// now create a buffer around the current graphic and basically build a polygon for it and get its extent
var extentPoly = pointToPolygon(graphic.geometry, toleranceInPixel);
// then see if this buffered point polygon contans the mp
if (extentPoly .contains(mp))
{
// add all points that are within your buffered polygon to some array and access their geometries from there
}
}
}
});
方法从点构建多边形-注意,可能有更新的esri库具有此内置功能
function pointToPolygon (point, toleranceInPixel)
{
//calculate map coords represented per pixel
var pixelWidth = mapManager.map.extent.getWidth() / mapManager.map.width;
//calculate map coords for tolerance in pixel
var toleraceInMapCoords = toleranceInPixel * pixelWidth;
//calculate & return computed extent
var extent = esri.geometry.Extent(point.x - toleraceInMapCoords,
point.y - toleraceInMapCoords,
point.x + toleraceInMapCoords,
point.y + toleraceInMapCoords,
map.spatialReference);
return (convertExtentToPolygon(extent, map.spatialReference));
}
function convertExtentToPolygon (extent, spatialRef)
{
var xmin = extent.xmin;
var xmax = extent.xmax;
var ymin = extent.ymin;
var ymax = extent.ymax;
var topLeft = new esri.geometry.Point(xmin, ymax, spatialRef);
var topRight = new esri.geometry.Point(xmax, ymax, spatialRef);
var bottomRight = new esri.geometry.Point(xmax, ymin, spatialRef);
var bottomLeft = new esri.geometry.Point(xmin, ymin, spatialRef);
var rings = new Array(topLeft, topRight, bottomRight, bottomLeft, topLeft);
var newPolygon = new esri.geometry.Polygon(spatialRef);
newPolygon.addRing(rings);
return newPolygon;
}
方法从多边形生成数据块-注意,可能有更新的esri库具有此内置内容
function pointToPolygon (point, toleranceInPixel)
{
//calculate map coords represented per pixel
var pixelWidth = mapManager.map.extent.getWidth() / mapManager.map.width;
//calculate map coords for tolerance in pixel
var toleraceInMapCoords = toleranceInPixel * pixelWidth;
//calculate & return computed extent
var extent = esri.geometry.Extent(point.x - toleraceInMapCoords,
point.y - toleraceInMapCoords,
point.x + toleraceInMapCoords,
point.y + toleraceInMapCoords,
map.spatialReference);
return (convertExtentToPolygon(extent, map.spatialReference));
}
function convertExtentToPolygon (extent, spatialRef)
{
var xmin = extent.xmin;
var xmax = extent.xmax;
var ymin = extent.ymin;
var ymax = extent.ymax;
var topLeft = new esri.geometry.Point(xmin, ymax, spatialRef);
var topRight = new esri.geometry.Point(xmax, ymax, spatialRef);
var bottomRight = new esri.geometry.Point(xmax, ymin, spatialRef);
var bottomLeft = new esri.geometry.Point(xmin, ymin, spatialRef);
var rings = new Array(topLeft, topRight, bottomRight, bottomLeft, topLeft);
var newPolygon = new esri.geometry.Polygon(spatialRef);
newPolygon.addRing(rings);
return newPolygon;
}
您可以根据需要调整公差-可能有更新的esri库可以更好地做到这一点,但这与前一段时间使用的类似。…您的实际问题是什么?您在您说有问题的部分中有很多注释掉的代码,这使我们很难确定哪些代码有效或无效。谢谢。