[OpenLayers-Users] externalGraphic rotation in a vector layer

Andreas Hocevar andreas.hocevar at gmail.com
Sat May 24 03:00:59 EDT 2008


Hey,

your code does not seem correct. At the time you request the extent, 
there is no extent yet. And you do not add the feature to the layer. The 
following code works for me (tested on FF2, IE6, IE7, Opera9 and Safari3 
with both png and gif images):

map = new OpenLayers.Map('map');
var ol_wms = new OpenLayers.Layer.WMS( "Metacarta Basic Layer",
                                             
"http://labs.metacarta.com/wms/vmap0",
                                             {layers: 'basic'} );
ol_wms.maxExtent = new OpenLayers.Bounds(-125, 17.84, -59, 52.55);
ol_wms.displayOutsideMaxExtent = true;
var planes=new OpenLayers.Layer.Vector("Planes",
             {
             styleMap: new OpenLayers.StyleMap({
                        "default": {
                                     externalGraphic: "../img/marker.png",
                                     graphicWidth: 24,
                                     graphicHeight: 28,
                                     graphicYOffset: 0,
                                     rotation: "${angle}",
                                     fillOpacity: "${opacity}"
                                    }
                        })
             });

map.addLayers([ ol_wms , planes ]);
map.zoomToMaxExtent();

var extent = planes.map.getExtent();
var yspan = extent.getHeight();
var xspan = extent.getWidth();
var x = extent.left + xspan * Math.random();
var y = extent.top - yspan * Math.random();
var planeangle = Math.floor(Math.random() * 360);
var feature=new OpenLayers.Feature.Vector(
    new OpenLayers.Geometry.Point(x, y), {
        "angle": planeangle,
        opacity: 100
    });
planes.addFeatures([feature]);


Regards,
Andreas.

Chander Ganesan wrote:
> Hi,
>
> Give some advice by crschmidt on #openlayers, I tried to apply the patch 
> specified in ticket #1433 to my installation of OpenLayer, and then 
> tried to create a point with an externalGraphic and rotation angle.  
> Unfortunately, this doesn't seem to work.  Here's the code that I used:
>
> map = new OpenLayers.Map('map');
> var ol_wms = new OpenLayers.Layer.WMS( "Metacarta Basic Layer",
>                                              "http://labs.metacarta.com/wms/vmap0",
>                                              {layers: 'basic'} );
> ol_wms.maxExtent = new OpenLayers.Bounds(-125, 17.84, -59, 52.55);
> ol_wms.displayOutsideMaxExtent = true;
> var planes=new OpenLayers.Layer.Vector("Planes",
>              {
>              styleMap: new OpenLayers.StyleMap({ 
>                         "default": { 
>                                      externalGraphic: "airplane.gif", 
>                                      graphicWidth: 24, 
>                                      graphicHeight: 28, 
>                                      graphicYOffset: 0, 
>                                      rotation: "${angle}", 
>                                      fillOpacity: "${opacity}" 
>                                     }
>                         })
>              });
>
> var extent = planes.map.getExtent();
> var yspan = extent.getHeight();
> var xspan = extent.getWidth();
> var x = extent.left + xspan * Math.random();
> var y = extent.top - yspan * Math.random();
> var planeangle = Math.floor(Math.random() * 360);
> var feature=new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(x, y), {"angle": planeangle, 
>                                                                                  opacity: 100 });
> map.addLayers([ ol_wms , planes ]);
> map.zoomToMaxExtent();
>
>
> This code causes the layer to draw with the US map underneath, and the 
> plane image to appear on the layer, but the image is not rotated.  Any 
> ideas/thoughts?
>
> thanks
>
> chander
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   




More information about the Users mailing list