[OpenLayers-Trac] [OpenLayers] #3622: ModifyFeature fails if styleMap has max/minScaleDenominator

OpenLayers trac-20090302 at openlayers.org
Thu Feb 16 07:47:29 EST 2012


#3622: ModifyFeature fails if styleMap has max/minScaleDenominator
-----------------------------------+----------------------------------------
 Reporter:  josnic                 |       Owner:  tschaub     
     Type:  feature                |      Status:  new         
 Priority:  minor                  |   Milestone:  2.12 Release
Component:  Control.ModifyFeature  |     Version:  2.11        
 Keywords:                         |       State:              
-----------------------------------+----------------------------------------
 OpenLayers.Control.ModifyFeature fails to initialize if the layer has a
 styleMap with max/minScaleDenominator values set.

 The cause seems to be that ModifyFeature needs to create another style in
 it's initialize method. This is done by a the call
 this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent).
 This creates a new feature without a layer attached to it.
 This will in turn call [Style].createSymbolizer(), this will check rules
 and eventually call [Rule].evaluate method. The evaluate method will check
 for max/minScaleDenominator and tries to use the layer to the feature,
 which is null.

 My workaround has been to create another ModifyFeature class and create a
 feature with a layer before calling createSymbolizer() method.

 Example to recreate bug:
 {{{
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>ModifyFeature and Style Rules min/maxScaleDenominator</title>
 <script type="text/javascript"
 src="http://openlayers.org/api/OpenLayers.js"></script>
 <script type="text/javascript">
         function demo() {
                 var ruleLow = new OpenLayers.Rule({
                         "minScaleDenominator": 40000,
                         symbolizer :
 OpenLayers.Util.applyDefaults({},OpenLayers.Feature.Vector.style["default"])});

                 var ruleHigh = new OpenLayers.Rule({
                         "maxScaleDenominator": 40000,
                         symbolizer :
 OpenLayers.Util.applyDefaults({},OpenLayers.Feature.Vector.style["selected"])});
                 var style = new OpenLayers.Style(null, {
                         rules:[ruleLow,ruleHigh]
                 });
                 var map = new OpenLayers.Map("map");
                 var vector = new OpenLayers.Layer.Vector("Vector layer", {
                         styleMap: new OpenLayers.StyleMap(style)
                 });
                 map.addLayer(vector);
                 // Get exception here !
                 var modifyControl = new
 OpenLayers.Control.ModifyFeature(vector);
         }
 </script>
 </head>
 <body onload="demo()">
         <div id="map"></div>
 </body>
 </html>
 }}}

-- 
Ticket URL: <http://trac.openlayers.org/ticket/3622>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list