[OpenLayers-Dev] Re: SVG2 and 2.11

Andreas Hocevar ahocevar at opengeo.org
Wed Apr 13 05:33:34 EDT 2011


Thanks for the example Slawomir. You are right, currently the NG renderers (which SVG2 is a subclass of) don't recalculate styles on zoom change. I created a ticket (http://trac.osgeo.org/openlayers/ticket/3257). If fixed wisely, the performance impact of recalculating the styles on zoom level changes will be minimal.

Andreas.

On Apr 13, 2011, at 09:55 , Slawomir Messner wrote:

> Sure,
> last time I wanted to post code here it was too long so I don't try to send our style map and shorten it this time.
> Our projection is 900913. The "mapObject" is our map-controller so you should replace it by your way to find the map.
> 
> var defaultStyle = new OpenLayers.Style({
>            'pointRadius': '1',
>            'fillColor': '#008700',
>            'fillOpacity': '0.6',
>            'stroke': 'True',
>            'strokeColor': '#21007E',
>            'strokeOpacity': '0.9',
>            'strokeWidth': '1',
>            'strokeDashstyle': 'solid',
>            'label': '${labelText}',
>            'fontSize': '${getLabelFontSize}',
>            'labelXOffset': '3',
>            'labelYOffset': '3',
>            'fontFamily': 'Arial',
>            'labelAlign': 'lb',
>            'display': ''
>        });
> 
>        defaultREDEStyle = new OpenLayers.Style({
>            'pointRadius': '1',
>            'fillColor': '#008700',
>            'fillOpacity': '0.6',
>            'stroke': 'True',
>            'strokeColor': '#21007E',
>            'strokeOpacity': '0.9',
>            'strokeWidth': '1',
>            'strokeDashstyle': 'solid',
>            'label': '',
>            'fontSize': '6px',
>            'labelXOffset': '3',
>            'labelYOffset': '3',
>            'fontFamily': 'Arial',
>            'labelAlign': 'lb',
>            'display': ''
>        });
> var defaultStyleMap = new OpenLayers.StyleMap({ 'default': defaultStyle, 'redeDefault':defaultREDEStyle });
> 
> defaultStyleMap.styles["default"].context =
> {    getLabelFontSize: function (feature) {
>        var fontSize = (feature.attributes.style != null && feature.attributes.style.fontSize != null && feature.attributes.style.fontSize)
>            || (feature.layer && feature.layer.styleMap.styles["redeDefault"].defaultStyle.fontSize);
> 
>        return Math.min(25, Math.max(5, parseInt(fontSize) * 6000 / feature.layer.map.getResolution())) + "px";
>    },
>    labelText:function(feature){
> if(feature.attributes.style != null && feature.attributes.style.label != null) {
>            return feature.attributes.style.label.length > 0 ? feature.attributes.style.label : '';
>        } else if(feature.layer) {
>            return feature.layer.styleMap.styles["redeDefault"].defaultStyle.label;
>        } else {
>            return '';
>        }}
> 
> }
> 
> var layer = new OpenLayers.Layer.Vector("test", {styleMap:defaultStyleMap,renderers : ["SVG"]});
> layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(893208.5127734,6940239.5448242),{style:{label:"test1",fontSize:"20px"
> }}));
> layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1143208.5127734,6910239.5448242),{style:{label:"test1"}}));
> layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1403208.5127734,6910239.5448242),{style:{label:"test1"}}));
> layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1108208.5127734,6605239.5448242),{style:{label:"test1"}}));
> mapObject.map.addLayer(layer);
> var layer2 = new OpenLayers.Layer.Vector("test2", {styleMap:defaultStyleMap,renderers : ["SVG2"]});
> layer2.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(893208.5127734,6940239.5448242),{style:{label:"test1",fontSize:"20px"
> }}));
> layer2.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1143208.5127734,6910239.5448242),{style:{label:"test1"}}));
> layer2.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1403208.5127734,6910239.5448242),{style:{label:"test1"}}));
> layer2.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1108208.5127734,6605239.5448242),{style:{label:"test1"}}));
> mapObject.map.addLayer(layer2);
> 
> Regards,
> Slawomir
> 
> Am 13.04.2011 09:25, schrieb Andreas Hocevar:
>> Hey Slawomir,
>> 
>> thanks for the feedback. Can you please provide a working example so we can reproduce and fix the issue?
>> 
>> Thanks,
>> Andreas.
>> 
>> On Apr 13, 2011, at 08:14 , Slawomir Messner wrote:
>> 
>>> Hi,
>>> would like to use it too but we use a style map with context so that labels and graphics change size on zoom but the functions are not called with SVG2 when zoomed only with SVG so the things stay at initial size dependent on the zoom level at loading. I hope this is not the reason for performance boost. Is it normal that SVG2 doesn't call the functions of context/symbolizers?
>>> Best regards,
>>> Slawomir
>>> 
>>> Am 12.04.2011 17:34, schrieb mortac8:
>>>> This is amazing.  I can draw 10,000 features in Opera and zoom in/out in
>>>> <500ms on the provided timer.
>>>> 
>>>> --
>>>> View this message in context: http://osgeo-org.1803224.n2.nabble.com/SVG2-and-2-11-tp6251101p6265597.html
>>>> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> Dev mailing list
>>>> Dev at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>>>> 
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>> 
>> 
> 
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Dev mailing list