ArcGIS 10, JSAPI 2.0, FeatureLayer, How do I catch the OnMouseUp Event?

2418
3
07-28-2010 05:22 AM
RobDunfey
Occasional Contributor
Hi,

I'm trying to modify an ESRI sample:

http://resources.esri.com/help/webapi/javascript/arcgis/demos/featurelayer/fl_hover.html

I use the OnMouseOver event to hightlight the feature, then I want to use the onMouseUp or onClick to open a hyperlink (stored as a value in an attribuite field in a new window).  I can't get the OnMouseUp event to fire?  I understand that this should be inherited from the Graphics Layer class?

Any ideas appreciated,

Rob


      function init() {
        var startExtent = new esri.geometry.Extent(-160, -60, 170, 75, new esri.SpatialReference({wkid:4326}));
        //create map
        var map = new esri.Map("mapDiv",{extent:startExtent});
        dojo.connect(map, "onLoad", function() {
          //listen for when map.graphics onMouseOut event is fired and then clear the highlight graphic
          //and hide the info window
          dojo.connect(map.graphics, "onMouseOut", function(evt) {
            map.graphics.clear();
            map.infoWindow.hide();
          });
        });
        //create and add new layer
        var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
        map.addLayer(layer);

        var southCarolinaCounties = new esri.layers.FeatureLayer("http://myserver.com/ArcGIS/rest/services/Countries/FeatureServer/1", {
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
          outFields: ["CNTRY_NAME", "SITE_URL_1"]
        });
        southCarolinaCounties.setDefinitionExpression("1=1");

        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,215,0,0.35]), 1),new dojo.Color([255,215,0,0.10]));
        southCarolinaCounties.setRenderer(new esri.renderer.SimpleRenderer(symbol));
        map.addLayer(southCarolinaCounties);

        var infoTemplate = new esri.InfoTemplate();
        infoTemplate.setTitle("${CNTRY_NAME}");
        infoTemplate.setContent("<b>2000 Population: </b>${SITE_URL_1}<br/>");
        map.infoWindow.resize(245,125);

        var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([205, 38, 38]), 3), new dojo.Color([255,215,0, 0.35]));
        //listen for when the onMouseOver event fires on the countiesGraphicsLayer
        //when fired, create a new graphic with the geometry from the event.graphic and add it to the maps graphics layer
        dojo.connect(southCarolinaCounties, "onMouseDown", function(evt) {

            //This alert isnt being fired???
            alert('hello');

            //Open New Window with URL from attribute field
            //window.open(evt.graphic.attributes.SITE_URL_1, "blank")

        });

        dojo.connect(southCarolinaCounties, "onMouseOver", function(evt) {
       
        //This all fires fine?
        map.graphics.clear();
        var highlightGraphic = new esri.Graphic(evt.graphic.geometry, highlightSymbol);
        map.graphics.add(highlightGraphic);

        });
0 Kudos
3 Replies
__Rich_
Occasional Contributor III
Only had a quick glance at the code - the FeatureLayer layer that you've connected to is being 'masked' by the highlight graphic that's added when the mouseover occurs.

var highlightGraphic = new esri.Graphic(evt.graphic.geometry,highlightSymbol);
map.graphics.add(highlightGraphic);  //Comment out this line to see what I mean!


Why not make the hyperlink an infoWindow item, since the infoWindow is already popped-up for you by the mouseover event? 🙂

HTH
0 Kudos
RobDunfey
Occasional Contributor
Only had a quick glance at the code - the FeatureLayer layer that you've connected to is being 'masked' by the highlight graphic that's added when the mouseover occurs.

var highlightGraphic = new esri.Graphic(evt.graphic.geometry,highlightSymbol);
map.graphics.add(highlightGraphic);  //Comment out this line to see what I mean!


Why not make the hyperlink an infoWindow item, since the infoWindow is already popped-up for you by the mouseover event? 🙂

HTH


Thanks, that helped.  In the end I took a different approach, and used a feature layer, make a selection on mouseover.  Thanks.

Rob
0 Kudos
KevinGooss
Occasional Contributor
wouldn't a hyperlink in a popup on hover be unclickable because when the user goes to click it they are no longer hovering over the feature so the infowindow will go away?
0 Kudos