ol2 icon indicating copy to clipboard operation
ol2 copied to clipboard

SVG.js and Canvas.js - style.labelSelect = true - No cursor change over label

Open DonaldKerr opened this issue 12 years ago • 4 comments

With style.labelSelect = true and a different cursor specified for the select style, the drawtext method in bot SVG.js and Canvas.js do not show the changed cursor over a style.label.

DonaldKerr avatar Mar 28 '12 17:03 DonaldKerr

This is true for both 2.11 and 2.12-rc1. VML.js works fine.

DonaldKerr avatar Mar 28 '12 17:03 DonaldKerr

<!DOCTYPE HTML>
<head>
<title>OpenLayers Highlight (Cursor Change) Example</title>

<style type="text/css">
    #map {
    width: 500px;
    height: 300px;
}

</style>

<script type="text/javascript" src="OpenLayers-2.11/lib/OpenLayers.js"></script>

<script type="text/javascript">

var map;
var vectorLayer;
var alignment = "lb";

function init(){
    map = new OpenLayers.Map('map');

    var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
        "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
    map.addLayer(layer);

    // allow testing of specific renderers via "?renderer=Canvas", etc
    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

    var defaultStyle = {
        pointRadius: "10",
        fillColor: "#ffcc66",
        strokeColor: "#ff9933",
        strokeWidth: 2,
        cursor: 'default',
        label: "Various Occupiers",
        labelAlign: "${getLabelAlign}",
        fontColor: "black",
        fontSize: "22px",
        fontFamily: "'Times New Roman'",
        fontWeight: "bold",
        labelSelect: true
//        labelOutlineColor: "#FFFFC0",
//        labelOutlineWidth: 3
    };

    var selectStyle = {
        cursor: 'pointer'
    };

    var context = {
        getLabelAlign: function(feature) {
            return alignment;
        },
    };

    var myStyle = new OpenLayers.Style(defaultStyle, {context: context});
    var myStyleSelect = new OpenLayers.Style(selectStyle);

    vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
        styleMap: new OpenLayers.StyleMap({'default': myStyle, 'select': myStyleSelect}),
        renderers: renderer
    });
    map.addLayer(vectorLayer);

    map.setCenter(new OpenLayers.LonLat(-109.370078125, 43.39484375), 4);

    var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
    var pointFeature = new OpenLayers.Feature.Vector(point);            
    vectorLayer.addFeatures(pointFeature);

    highlightControl = new OpenLayers.Control.SelectFeature([vectorLayer], {
        hover: true,
        highlightOnly: true
    });
    map.addControl(highlightControl);
    highlightControl.activate();
}

</script>

</head>

<body onload="init()">

<h1 id="title">OpenLayers Highlight (Cursor Change) Example</h1>

<div id="map"></div>

<p>Mouseover point and label - Cursor should change to Pointer from default</p>

<ul>
<li>VML.js - Working
<li>SVG.js - Working on point only - Not working on label
<li>Canvas.js - Not working on either point or label
</ul>

</body>
</html>

DonaldKerr avatar Mar 29 '12 16:03 DonaldKerr

I tested this with 2.14-dev and it is still an issue. the mouse pointer does not change when you use a Canvas renderer.

batje avatar Mar 03 '15 13:03 batje

This is because cursors are set using DOM styles for VML and SVG. This is not possible for Canvas, because it is not based on DOM elements. To achieve this, hit detection would need to be used.

ahocevar avatar Mar 03 '15 14:03 ahocevar