bsancho

Icrease esri.geometry.Point tolerance

Discussion created by bsancho on May 29, 2012
Hi all,

I need to increase the tolerance of my map points. Before I use icons and there is no problem with event control, but now i need to use text. I tried solutions like http://forums.esri.com/Thread.asp?c=158&f=2396&t=261892 but i think this is not useful for me because i don't use rest services.

I show my code


       //call method

 var geo = new esri.geometry.Point(xPos,yPos,new esri.SpatialReference({ wkid: 25830 }));
 var ip = new esri.Graphic(geo, null);
 var attr = {"xPos":xPos,"yPos":yPos,"id":id,"tactica":tactica,"estado":estado,"areaOp":areaOp,"fecha":fecha,"tipo":"incidente"};
 ip.setAttributes(attr);

        myInfoWindowXY(ip,icon);

        .....


function myInfoWindowXY(elemento,icono){
 try{
  var imageSymbol = new Image();
  imageSymbol.setAttribute('width', '16px');
  imageSymbol.setAttribute('height', '16px'); 
  imageSymbol.src = icono;
  
  //Seleccionamos, en funcion del tipo de punto, la capa sobre la que vamos a trabajar
  //si la capa no existe, la creamos
  if(elemento.attributes.tipo == "incidente"){
   if (gvdiDefaultMap.getLayer("IncidentPointsGraphicsLayer") == undefined){
    var incidentsLayer = new esri.layers.GraphicsLayer({id:"IncidentPointsGraphicsLayer"});
    gvdiDefaultMap.addLayer(incidentsLayer);
   }
   gvdiCurrentGraphicsLayer =  gvdiDefaultMap.getLayer("IncidentPointsGraphicsLayer");
      
  }else if (elemento.attributes.tipo == "llamadaSimple"){
   if (gvdiDefaultMap.getLayer("AlertPointsGraphicsLayer") == undefined){
    var alertsLayer = new esri.layers.GraphicsLayer({id:"AlertPointsGraphicsLayer"});
    gvdiDefaultMap.addLayer(alertsLayer);
   }
   gvdiCurrentGraphicsLayer =  gvdiDefaultMap.getLayer("AlertPointsGraphicsLayer");
   
  }else if (elemento.attributes.tipo == "recurso"){
   if (gvdiDefaultMap.getLayer("ResourcesPointsGraphicsLayer") == undefined){
    var resourcesLayer = new esri.layers.GraphicsLayer({id:"ResourcesPointsGraphicsLayer"});
    gvdiDefaultMap.addLayer(resourcesLayer);
   }
   gvdiCurrentGraphicsLayer =  gvdiDefaultMap.getLayer("ResourcesPointsGraphicsLayer");
   
  }else if (elemento.attributes.tipo == "llamadaMovil"){
   if (gvdiDefaultMap.getLayer("MobilePointsGraphicsLayer") == undefined){
    var mobileLayer = new esri.layers.GraphicsLayer({id:"MobilePointsGraphicsLayer"});
    gvdiDefaultMap.addLayer(mobileLayer);
   }
   gvdiCurrentGraphicsLayer =  gvdiDefaultMap.getLayer("MobilePointsGraphicsLayer");
  }
  
  //Añadimos el punto de geolocalizacion con su grafico asociado a la capa pertinente
  
  var displayText = elemento.attributes.tactica;
  var font = new esri.symbol.Font("7pt",esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL,esri.symbol.Font.WEIGHT_BOLD,"Helvetica");       
  var textSymbol;
   textSymbol = new esri.symbol.TextSymbol(displayText,font,new dojo.Color("#FE2E2E"));

  gvdiCurrentGraphicsLayer.add(elemento.setSymbol(textSymbol)); 
  
  //gvdiCurrentGraphicsLayer.add(elemento.setSymbol(esri.symbol.PictureMarkerSymbol(icono,imageSymbol.width,imageSymbol.height)));
  

  //Generamos los eventos correspondientes a los clics de raton
  dojo.connect(gvdiCurrentGraphicsLayer, "onMouseDown", onMouseDownFunction);
  
  //Generamos el evento correspondiente a un doble clic del raton
  dojo.connect(gvdiCurrentGraphicsLayer, "onDblClick", onDblClickFunction);

  //Generamos el evento correspondiente a situar el raton sobre un punto. 
  //Se muestra la cabecera de infoWindow solo mientras el raton este situado sobre este  
  dojo.connect(gvdiCurrentGraphicsLayer, "onMouseMove", onMouseMoveFunction);
  
  //Generamos el evento correspondiente a dejar de situar el raton sobre un punto.
  //Desaparece la cabecera de infoWindow 
  dojo.connect(gvdiCurrentGraphicsLayer, "onMouseOut", function() {
   if(gvdiDefaultMap.infoWindow.getMouseOver() && !gvdiDefaultMap.infoWindow.getMouseClick()){
    gvdiDefaultMap.infoWindow.hide();
    gvdiDefaultMap.infoWindow.mostrarReducido();
    isFirst=0;
    isInfoWindowShowing=0;
   } 
   isInfoWindowShowing=0;
  } );
 }catch(error){
  mostrarError("myInfoWindowXY: "+error);
 }
}


function onMouseDownFunction(evt) {
 desactivarToolbar(drawToolbar);
 desactivarToolbar(navToolbar);
   var g = evt.graphic;
   
/*   Not working
  //INCREASE TOLERENCE
      //var centerPoint = new esri.geometry.Point(evt.mapPoint.x, evt.mapPoint.y, evt.mapPoint.spatialReference);
      var mapWidth = gvdiDefaultMap.extent.getWidth();

      //Divide width in map units by width in pixels
      var pixelWidth = mapWidth / gvdiDefaultMap.width;

      //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
      var tolerance = 100 * pixelWidth;
      var query = new esri.tasks.Query();
      //Build tolerance envelope and set it as the query geometry
      var queryExtent = new esri.geometry.Extent(1, 1, tolerance, tolerance, evt.mapPoint.spatialReference);
      query.geometry = queryExtent.centerAt(g);
   
   */
   
   gvdiDefaultMap.infoWindow.setMouseOver(false);
   gvdiDefaultMap.infoWindow.setMouseClick(true);
   if(isFirst==0) 
   {
  if(dojo.mouseButtons.isLeft(evt))
  {
   if(g.attributes != undefined)
   {
    //Generamos el evento correspondiente a un solo clic del boton izquierdo
    gvdiDefaultMap.infoWindow.setContent(getInfoWindowContent(g));
    gvdiDefaultMap.infoWindow.mostrarExtendido();
    gvdiDefaultMap.infoWindow.show(evt.screenPoint,gvdiDefaultMap.getInfoWindowAnchor(evt.screenPoint)); 
   }
   
  }else if (dojo.mouseButtons.isRight(evt)){
                          ......   

   }
  }
  
  isFirst=1;
   }
   isInfoWindowShowing=0;
}




Please, help me, im new in esri and dojo and im a little bit lost in this new world!!

Thanks a lot!!!

Outcomes