Ticket #736: externalGraphic.2.diff
| File externalGraphic.2.diff, 8.9 kB (added by ahocevar, 1 year ago) |
|---|
-
/mnt/d/eclipse/workspace/openlayers/examples/vector-features.html
old new 7 7 border: 1px solid black; 8 8 } 9 9 </style> 10 <script src="../lib/OpenLayers.js" ></script>10 <script src="../lib/OpenLayers.js" type="text/javascript"></script> 11 11 <script type="text/javascript"> 12 12 <!-- 13 13 var map; … … 21 21 var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 22 22 style_blue.strokeColor = "blue"; 23 23 style_blue.fillColor = "blue"; 24 style_blue.externalGraphic = "../img/marker.png"; 25 26 // each of the three lines below means the same, if only one of 27 // them is active: the image will have a size of 24px, and the 28 // aspect ratio will be kept 29 style_blue.pointRadius = 12; 30 //style_blue.graphicWidth = 24; 31 //style_blue.graphicHeight = 24; 32 33 style_blue.fillOpacity = 1; 24 34 var style_green = { 25 35 strokeColor: "#00FF00", 26 36 strokeOpacity: 1, … … 28 38 pointRadius: 6, 29 39 pointerEvents: "visiblePainted" 30 40 }; 41 var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 42 43 // if graphicWidth and graphicHeight are both set, the aspect ratio 44 // of the image will be ignored 45 style_mark.graphicWidth = 24; 46 style_mark.graphicHeight = 20; 47 48 style_mark.externalGraphic = "../img/marker.png"; 31 49 32 50 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry"); 33 51 … … 34 52 // create a point feature 35 53 var point = new OpenLayers.Geometry.Point(-111.04, 45.68); 36 54 var pointFeature = new OpenLayers.Feature.Vector(point,null,style_blue); 55 var point2 = new OpenLayers.Geometry.Point(-105.04, 49.68); 56 var pointFeature2 = new OpenLayers.Feature.Vector(point2,null,style_green); 57 var point3 = new OpenLayers.Geometry.Point(-105.04, 49.68); 58 var pointFeature3 = new OpenLayers.Feature.Vector(point3,null,style_mark); 37 59 38 60 // create a line feature from a list of points 39 61 var pointList = []; … … 64 86 65 87 map.addLayer(vectorLayer); 66 88 map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5); 67 vectorLayer.addFeatures([pointFeature, lineFeature, polygonFeature]);89 vectorLayer.addFeatures([pointFeature, pointFeature3, pointFeature2, lineFeature, polygonFeature]); 68 90 } 69 91 // --> 70 92 </script> … … 75 97 in different styles, created 'manually', by constructing the entire style 76 98 object, via 'copy', extending the default style object, and by 77 99 inheriting the default style from the layer.</p> 100 <p>It also shows how to use external graphic files for point features 101 and how to set their size: If either graphicWidth or graphicHeight is set, 102 the aspect ratio of the image will be respected. If both graphicWidth and 103 graphicHeight are set, it will be ignored. Alternatively, if graphicWidth 104 and graphicHeight are omitted, pointRadius will be used to set the size 105 of the image, which will then be twice the value of pointRadius with the 106 original aspect ratio.</p> 78 107 </body> 79 108 </html> -
/mnt/d/eclipse/workspace/openlayers/lib/OpenLayers/Renderer/SVG.js
old new 165 165 options = options || node._options; 166 166 167 167 if (node._geometryClass == "OpenLayers.Geometry.Point") { 168 node.setAttributeNS(null, "r", style.pointRadius); 168 if (style.externalGraphic) { 169 // remove old node 170 var id = node.getAttributeNS(null, "id"); 171 var x = node.getAttributeNS(null, "cx"); 172 var y = node.getAttributeNS(null, "cy"); 173 var _featureId = node._featureId; 174 var _geometryClass = node._geometryClass; 175 var _style = node._style; 176 this.root.removeChild(node); 177 178 // create new image node 179 var node = this.createNode("image", id); 180 node._featureId = _featureId; 181 node._geometryClass = _geometryClass; 182 node._style = _style; 183 this.root.appendChild(node); 184 185 // now style the new node 186 if (style.graphicWidth && style.graphicHeight) { 187 node.setAttributeNS(null, "preserveAspectRatio", "none"); 188 } 189 var width = style.graphicWidth || style.graphicHeight; 190 var height = style.graphicHeight || style.graphicWidth; 191 width = width ? width : style.pointRadius*2; 192 height = height ? height : style.pointRadius*2; 193 194 node.setAttributeNS(null, "x", x-(.5*width).toFixed()); 195 node.setAttributeNS(null, "y", -y-(.5*height).toFixed()); 196 node.setAttributeNS(null, "width", width); 197 node.setAttributeNS(null, "height", height); 198 node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); 199 node.setAttributeNS(null, "transform", "scale(1,-1)"); 200 node.setAttributeNS(null, "style", "opacity: "+style.fillOpacity); 201 } else { 202 node.setAttributeNS(null, "r", style.pointRadius); 203 } 169 204 } 170 205 171 206 if (options.isFilled) { -
/mnt/d/eclipse/workspace/openlayers/lib/OpenLayers/Renderer/VML.js
old new 129 129 options = options || node._options; 130 130 131 131 if (node._geometryClass == "OpenLayers.Geometry.Point") { 132 this.drawCircle(node, geometry, style.pointRadius); 132 if (style.externalGraphic) { 133 // remove old node 134 var id = node.id; 135 var _featureId = node._featureId; 136 var _geometryClass = node._geometryClass; 137 var _style = node._style; 138 this.root.removeChild(node); 139 140 // create new image node 141 var node = this.createNode("v:rect", id); 142 var fill = this.createNode("v:fill", id+"_image"); 143 node.appendChild(fill); 144 node._featureId = _featureId; 145 node._geometryClass = _geometryClass; 146 node._style = _style; 147 this.root.appendChild(node); 148 149 fill.src = style.externalGraphic; 150 fill.type = "frame"; 151 node.style.flip = "y"; 152 153 if (!(style.graphicWidth && style.graphicHeight)) { 154 fill.aspect = "atmost"; 155 } 156 157 // now style the new node 158 var width = style.graphicWidth || style.graphicHeight; 159 var height = style.graphicHeight || style.graphicWidth; 160 width = width ? width : style.pointRadius*2; 161 height = height ? height : style.pointRadius*2; 162 var resolution = this.getResolution(); 163 node.style.left = (geometry.x/resolution-.5*width).toFixed(); 164 node.style.top = (geometry.y/resolution-.5*height).toFixed(); 165 node.style.width = width; 166 node.style.height = height; 167 168 // modify fill style for rect styling below 169 style.fillColor = "none"; 170 style.strokeColor = "none"; 171 172 } else { 173 this.drawCircle(node, geometry, style.pointRadius); 174 } 133 175 } 134 176 135 177 //fill … … 146 188 fill = this.createNode('v:fill', node.id + "_fill"); 147 189 node.appendChild(fill); 148 190 } 149 fill.setAttribute("opacity", style.fillOpacity); 191 if (style.fillOpacity) { 192 fill.setAttribute("opacity", style.fillOpacity); 193 } 150 194 } 151 195 152 196
