1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
15
* @requires OpenLayers/Feature.js
16
* @requires OpenLayers/Util.js
20
* Class: OpenLayers.Feature.Vector
21
* Vector features use the OpenLayers.Geometry classes as geometry description.
22
* They have an 'attributes' property, which is the data object, and a 'style'
23
* property, the default values of which are defined in the
24
* <OpenLayers.Feature.Vector.style> objects.
27
* - <OpenLayers.Feature>
29
OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
38
* APIProperty: geometry
39
* {<OpenLayers.Geometry>}
44
* APIProperty: attributes
45
* {Object} This object holds arbitrary properties that describe the
63
* Property: renderIntent
64
* {String} rendering intent currently being used
66
renderIntent: "default",
69
* Constructor: OpenLayers.Feature.Vector
70
* Create a vector feature.
73
* geometry - {<OpenLayers.Geometry>} The geometry that this feature
75
* attributes - {Object} An optional object that will be mapped to the
76
* <attributes> property.
77
* style - {Object} An optional style object.
79
initialize: function(geometry, attributes, style) {
80
OpenLayers.Feature.prototype.initialize.apply(this,
81
[null, null, attributes]);
83
this.geometry = geometry ? geometry : null;
87
this.attributes = OpenLayers.Util.extend(this.attributes,
90
this.style = style ? style : null;
95
* nullify references to prevent circular references and memory leaks
99
this.layer.removeFeatures(this);
103
this.geometry = null;
104
OpenLayers.Feature.prototype.destroy.apply(this, arguments);
109
* Create a clone of this vector feature. Does not set any non-standard
113
* {<OpenLayers.Feature.Vector>} An exact clone of this vector feature.
116
return new OpenLayers.Feature.Vector(
117
this.geometry ? this.geometry.clone() : null,
124
* Determine whether the feature is within the map viewport. This method
125
* tests for an intersection between the geometry and the viewport
126
* bounds. If a more effecient but less precise geometry bounds
127
* intersection is desired, call the method with the boundsOnly
131
* boundsOnly - {Boolean} Only test whether a feature's bounds intersects
132
* the viewport bounds. Default is false. If false, the feature's
133
* geometry must intersect the viewport for onScreen to return true.
136
* {Boolean} The feature is currently visible on screen (optionally
137
* based on its bounds if boundsOnly is true).
139
onScreen:function(boundsOnly) {
140
var onScreen = false;
141
if(this.layer && this.layer.map) {
142
var screenBounds = this.layer.map.getExtent();
144
var featureBounds = this.geometry.getBounds();
145
onScreen = screenBounds.intersectsBounds(featureBounds);
147
var screenPoly = screenBounds.toGeometry();
148
onScreen = screenPoly.intersects(this.geometry);
155
* Method: createMarker
156
* HACK - we need to decide if all vector features should be able to
160
* {<OpenLayers.Marker>} For now just returns null
162
createMarker: function() {
167
* Method: destroyMarker
168
* HACK - we need to decide if all vector features should be able to
171
* If user overrides the createMarker() function, s/he should be able
172
* to also specify an alternative function for destroying it
174
destroyMarker: function() {
179
* Method: createPopup
180
* HACK - we need to decide if all vector features should be able to
184
* {<OpenLayers.Popup>} For now just returns null
186
createPopup: function() {
192
* Determins whether the feature intersects with the specified location.
195
* lonlat - {<OpenLayers.LonLat>}
196
* toleranceLon - {float} Optional tolerance in Geometric Coords
197
* toleranceLat - {float} Optional tolerance in Geographic Coords
200
* {Boolean} Whether or not the feature is at the specified location
202
atPoint: function(lonlat, toleranceLon, toleranceLat) {
205
atPoint = this.geometry.atPoint(lonlat, toleranceLon,
212
* Method: destroyPopup
213
* HACK - we need to decide if all vector features should be able to
216
destroyPopup: function() {
222
* Moves the feature and redraws it at its new location
225
* state - {OpenLayers.LonLat or OpenLayers.Pixel} the
226
* location to which to move the feature.
228
move: function(location) {
230
if(!this.layer || !this.geometry.move){
231
//do nothing if no layer or immoveable geometry
236
if (location.CLASS_NAME == "OpenLayers.LonLat") {
237
pixel = this.layer.getViewPortPxFromLonLat(location);
242
var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat());
243
var res = this.layer.map.getResolution();
244
this.geometry.move(res * (pixel.x - lastPixel.x),
245
res * (lastPixel.y - pixel.y));
246
this.layer.drawFeature(this);
257
toState: function(state) {
258
if (state == OpenLayers.State.UPDATE) {
259
switch (this.state) {
260
case OpenLayers.State.UNKNOWN:
261
case OpenLayers.State.DELETE:
264
case OpenLayers.State.UPDATE:
265
case OpenLayers.State.INSERT:
268
} else if (state == OpenLayers.State.INSERT) {
269
switch (this.state) {
270
case OpenLayers.State.UNKNOWN:
276
} else if (state == OpenLayers.State.DELETE) {
277
switch (this.state) {
278
case OpenLayers.State.INSERT:
279
// the feature should be destroyed
281
case OpenLayers.State.DELETE:
283
case OpenLayers.State.UNKNOWN:
284
case OpenLayers.State.UPDATE:
288
} else if (state == OpenLayers.State.UNKNOWN) {
293
CLASS_NAME: "OpenLayers.Feature.Vector"
298
* Constant: OpenLayers.Feature.Vector.style
299
* OpenLayers features can have a number of style attributes. The 'default'
300
* style will typically be used if no other style is specified.
302
* Default style properties:
304
* - fillColor: "#ee9900",
305
* - fillOpacity: 0.4,
306
* - hoverFillColor: "white",
307
* - hoverFillOpacity: 0.8,
308
* - strokeColor: "#ee9900",
309
* - strokeOpacity: 1,
311
* - strokeLinecap: "round", [butt | round | square]
312
* - strokeDashstyle: "solid", [dot | dash | dashdot | longdash | longdashdot | solid]
313
* - hoverStrokeColor: "red",
314
* - hoverStrokeOpacity: 1,
315
* - hoverStrokeWidth: 0.2,
317
* - hoverPointRadius: 1,
318
* - hoverPointUnit: "%",
319
* - pointerEvents: "visiblePainted"
322
* Other style properties that have no default values:
333
OpenLayers.Feature.Vector.style = {
335
fillColor: "#ee9900",
337
hoverFillColor: "white",
338
hoverFillOpacity: 0.8,
339
strokeColor: "#ee9900",
342
strokeLinecap: "round",
343
strokeDashstyle: "solid",
344
hoverStrokeColor: "red",
345
hoverStrokeOpacity: 1,
346
hoverStrokeWidth: 0.2,
350
pointerEvents: "visiblePainted",
356
hoverFillColor: "white",
357
hoverFillOpacity: 0.8,
361
strokeLinecap: "round",
362
strokeDashstyle: "solid",
363
hoverStrokeColor: "red",
364
hoverStrokeOpacity: 1,
365
hoverStrokeWidth: 0.2,
369
pointerEvents: "visiblePainted",
375
hoverFillColor: "white",
376
hoverFillOpacity: 0.8,
377
strokeColor: "yellow",
379
strokeLinecap: "round",
381
strokeDashstyle: "solid",
382
hoverStrokeColor: "red",
383
hoverStrokeOpacity: 1,
384
hoverStrokeWidth: 0.2,
388
pointerEvents: "visiblePainted",