a47564643532514ecdd300f86f2bdf91029481f9.svn-base
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Renderer/Elements.js
*/
/**
* Class: OpenLayers.Renderer.NG
*
* Inherits from:
* - <OpenLayers.Renderer.Elements>
*/
OpenLayers.Renderer.NG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
/**
* Constant: labelNodeType
* {String} The node type for text label containers. To be defined by
* subclasses.
*/
labelNodeType: null,
/**
* Constructor: OpenLayers.Renderer.NG
*
* Parameters:
* containerID - {String}
* options - {Object} options for this renderer. Supported options are:
* * yOrdering - {Boolean} Whether to use y-ordering
* * zIndexing - {Boolean} Whether to use z-indexing. Will be ignored
* if yOrdering is set to true.
*/
/**
* Method: updateDimensions
* To be extended by subclasses - here we set positioning related styles
* on HTML elements, subclasses have to do the same for renderer specific
* elements (e.g. viewBox, width and height of the rendererRoot)
*
* Parameters:
* zoomChanged - {Boolean} Has the zoom changed? If so, subclasses may have
* to update feature styles/dimensions.
*/
updateDimensions: function(zoomChanged) {
var mapExtent = this.map.getExtent();
var renderExtent = mapExtent.scale(3);
this.setExtent(renderExtent, true);
var res = this.getResolution();
var div = this.rendererRoot.parentNode;
var layerLeft = parseFloat(div.parentNode.style.left);
var layerTop = parseFloat(div.parentNode.style.top);
div.style.left = ((renderExtent.left - mapExtent.left) / res - layerLeft) + "px";
div.style.top = ((mapExtent.top - renderExtent.top) / res - layerTop) + "px";
},
/**
* Method: resize
*/
setSize: function() {
this.map.getExtent() && this.updateDimensions();
},
/**
* Method: drawFeature
* Draw the feature. The optional style argument can be used
* to override the feature's own style. This method should only
* be called from layer.drawFeature().
*
* Parameters:
* feature - {<OpenLayers.Feature.Vector>}
* style - {<Object>}
*
* Returns:
* {Boolean} true if the feature has been drawn completely, false if not,
* undefined if the feature had no geometry
*/
drawFeature: function(feature, style) {
if(style == null) {
style = feature.style;
}
if (feature.geometry) {
var rendered = this.drawGeometry(feature.geometry, style, feature.id);
if(rendered !== false && style.label) {
var location = feature.geometry.getCentroid();
this.drawText(feature.id, style, location);
} else {
this.removeText(feature.id);
}
return rendered;
}
},
/**
* Method: drawText
* Function for drawing text labels.
* This method is only called by the renderer itself.
*
* Parameters:
* featureId - {String|DOMElement}
* style - {Object}
* location - {<OpenLayers.Geometry.Point>}, will be modified inline
*
* Returns:
* {DOMElement} container holding the text label (to be populated by
* subclasses)
*/
drawText: function(featureId, style, location) {
var label;
if (typeof featureId !== "string") {
label = featureId;
} else {
label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX, this.labelNodeType);
label._featureId = featureId;
}
label._style = style;
label._x = location.x;
label._y = location.y;
if(style.labelXOffset || style.labelYOffset) {
var xOffset = isNaN(style.labelXOffset) ? 0 : style.labelXOffset;
var yOffset = isNaN(style.labelYOffset) ? 0 : style.labelYOffset;
var res = this.getResolution();
location.move(xOffset*res, yOffset*res);
}
if(label.parentNode !== this.textRoot) {
this.textRoot.appendChild(label);
}
return label;
},
CLASS_NAME: "OpenLayers.Renderer.NG"
});