<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>Re: [OpenLayers-Users] Markers with dymamically changing appearance</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Regarding the first question:<BR>
<BR>
i did something like this in order to create a rectangle of a given<BR>
pixel size centered on a coordinate on the map (to make a print tool)..<BR>
the relevant code parts are:<BR>
<BR>
first i set up some choices for paper sizes<BR>
<BR>
&nbsp; //the available paper sizes<BR>
&nbsp;&nbsp;&nbsp;&nbsp; papers: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;a4_landscape&quot;:{<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 3507,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 2481,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; box: &quot;landscape&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;a4_portrait&quot;: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name: &quot;A4 St\345ende&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 2481,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 3507,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; box: &quot;portrait&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selected: true<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;a3_landscape&quot;:{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name: &quot;A3 Liggende&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 4962,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 3507,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; box: &quot;landscape&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;a3_portrait&quot;: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name: &quot;A3 St\345ende&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 3507,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 4962,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; box: &quot;portrait&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; sizes: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;portrait&quot;: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 496,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 700<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;landscape&quot;: {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 700,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 496<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
then i start off with setting the paper, which finds the width and<BR>
height based on the given paper (this could probably be simplified a<BR>
lot, not finished yet), finds the map center and gets the pixel value<BR>
for that, and then either creates or moves the polygon<BR>
<BR>
&nbsp;&nbsp;&nbsp; setPaper: function(paper) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.paper = paper;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the boxSize<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.boxSize = {};<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.boxSize.width = this.sizes[this.papers[this.paper].box].width;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.boxSize.height =<BR>
this.sizes[this.papers[this.paper].box].height;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //find the center pixel for the box<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create or move the polygon to the center of the map<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!this.feature) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.addPolygon(this.paper, centerPx);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.lastCenter = this.feature.geometry.getCentroid();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.addPolygon(this.paper, centerPx);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.movePolygon();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
&nbsp;&nbsp;&nbsp; //add the print area polygon<BR>
&nbsp;&nbsp;&nbsp;&nbsp; addPolygon: function(paper, centerPx) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //remove previous feature<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.mylayer.destroyFeatures();<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //calculate the extent of the box<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var addX = this.boxSize.width / 2;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var addY = this.boxSize.height / 2;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var center = this.map.getLonLatFromPixel(new<BR>
OpenLayers.Pixel(centerPx.x,centerPx.y));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var leftBottom = this.map.getLonLatFromPixel(new<BR>
OpenLayers.Pixel(centerPx.x-addX, centerPx.y+addY));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var rightTop = this.map.getLonLatFromPixel(new<BR>
OpenLayers.Pixel(centerPx.x+addX, centerPx.y-addY));<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create the polygon, the feature and add to the layer<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var poly = new OpenLayers.Geometry.Polygon(<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new OpenLayers.Geometry.LinearRing([<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new OpenLayers.Geometry.Point(leftBottom.lon,<BR>
leftBottom.lat),<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new OpenLayers.Geometry.Point(leftBottom.lon,<BR>
rightTop.lat),<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new OpenLayers.Geometry.Point(rightTop.lon,<BR>
rightTop.lat),<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new OpenLayers.Geometry.Point(rightTop.lon,<BR>
leftBottom.lat)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ])<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.feature = new OpenLayers.Feature.Vector(poly);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.mylayer.addFeatures([this.feature]);<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; movePolygon: function() {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pixel = this.map.getPixelFromLonLat(new<BR>
OpenLayers.LonLat(this.lastCenter.x, this.lastCenter.y));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var lastPixel = this.map.getPixelFromLonLat(this.map.getCenter());<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var res = this.map.getResolution();<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.feature.geometry.move(res * (pixel.x - lastPixel.x),<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res * (lastPixel.y - pixel.y));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.mylayer.drawFeature(this.feature);<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
and then a listener for zoomend this.map.events.register(&quot;zoomend&quot;,<BR>
this, this.scaleChanged);<BR>
<BR>
which calls:<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; //scale of map changed<BR>
&nbsp;&nbsp;&nbsp;&nbsp; scaleChanged: function() {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.addPolygon(this.paper, centerPx);<BR>
&nbsp;&nbsp;&nbsp;&nbsp; },<BR>
<BR>
to redraw the polygon<BR>
<BR>
<BR>
hope this helps somewhat<BR>
<BR>
-atle<BR>
<BR>
On 08/11/2010 10:00 AM, Bart van den Eijnden (OSGIS) wrote:<BR>
&gt; Hi,<BR>
&gt;<BR>
&gt; please always cc the list, since I don't know all the answers and people<BR>
&gt; with similar issues can find it in the e-mail archives later on.<BR>
&gt;<BR>
&gt; Your first question: I don't know.<BR>
&gt;<BR>
&gt; Redrawing can be done using:<BR>
&gt;<BR>
&gt; feature.layer.drawFeature(feature);<BR>
&gt;<BR>
&gt; <A HREF="http://dev.openlayers.org/docs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.drawFeature">http://dev.openlayers.org/docs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.drawFeature</A><BR>
&gt;<BR>
&gt; Best regards,<BR>
&gt; Bart<BR>
&gt;<BR>
&gt;&nbsp;&nbsp;&nbsp;<BR>
&gt;&gt; On Aug 11, 2010, at 0:16 , Bart van den Eijnden (OSGIS) wrote:<BR>
&gt;&gt;<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt;&gt;&gt; please check out:<BR>
&gt;&gt;&gt;<BR>
&gt;&gt;&gt; <A HREF="http://docs.openlayers.org/library/feature_styling.html">http://docs.openlayers.org/library/feature_styling.html</A><BR>
&gt;&gt;&gt;<BR>
&gt;&gt;&gt; Labels can be drawn as well with vector features, see e.g.:<BR>
&gt;&gt;&gt;<BR>
&gt;&gt;&gt; <A HREF="http://openlayers.org/dev/examples/vector-features-with-text.html">http://openlayers.org/dev/examples/vector-features-with-text.html</A><BR>
&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt;&gt; Thanks.<BR>
&gt;&gt;<BR>
&gt;&gt; Two more questions:<BR>
&gt;&gt;<BR>
&gt;&gt; - how do I draw in screen coordinates (I need to draw a polygon starting<BR>
&gt;&gt; from a latlong, then draw 2em up and to the right etc), and have it stay<BR>
&gt;&gt; the same size on-screen when the user zooms (ie make markers)?<BR>
&gt;&gt; - how do I redraw these things? Just erase them and draw new ones, or do I<BR>
&gt;&gt; replace their graphics properties?<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt;<BR>
&gt;&nbsp;&nbsp;&nbsp;<BR>
<BR>
<BR>
--<BR>
Atle Frenvik Sveen<BR>
Utvikler<BR>
Geomatikk IKT AS<BR>
tlf: 45 27 86 89<BR>
atle.frenvik.sveen@geomatikk.no<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>