Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I know that in OpenLayers you can add Features to a Vector Layer which each have image but then they will not scale (i.e. their size stays the same independent of the current zoom) or at least I do not know how to make them scale. For example:

            var vectorLayer = new OpenLayers.Layer.Vector("Overlay");
            var feature = new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(0,0)
            .transform(projWGS84, map.getProjectionObject()), 
            {some:'data'},
            {externalGraphic: 'http://www.gatesms.eu/img/loga/java.png', graphicHeight: 30,graphicWidth: 30});
            var feature2 = new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(1,1)
            .transform(projWGS84, map.getProjectionObject()), 
            {some:'data'},
            {externalGraphic: 'http://blog.tiger.com.pl/wp-content/uploads/2012/02/Duke256.png', graphicHeight: 30,graphicWidth: 30});
            vectorLayer.addFeatures([feature,feature2]);
            map.addLayer(vectorLayer);

On the other hand the scaling of image works fine if you set an image for an Image Layer but then you can have only a single image in a layer.

            var options = {   
                opacity: 1.0, 
                isBaseLayer: false,
                numZoomLevels: 20,
                transparent: 'true'
            };
            var extent = new OpenLayers.Bounds(WEST,SOUTH,EAST,NORTH)
                .transform(projWGS84, map.getProjectionObject());                    
            var gO = new OpenLayers.Layer.Image('Image',
                'http://www.gatesms.eu/img/loga/java.png',
                extent,
                new OpenLayers.Size(1,1),
                options);  
            map.addLayer(gO);

My question is: How to have, in OpenLayers, many images on a single layer that will scale as in the above case?

share|improve this question
add comment

1 Answer

I would use style's context object which calculates graphicWidth and graphicHeight depending on current map resolution. It applies to you first option (Vector layer).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.