OpenLayers OpenLayers

Ticket #628 (closed feature: fixed)

Opened 1 year ago

Last modified 1 year ago

you can't render a geometry

Reported by: tschaub Assigned to: tschaub
Priority: minor Milestone: 2.4 Release
Component: Geometry Version:
Keywords: Cc:
State:

Description

Ok, this will likely end up just being a documentation patch, but I want to eventually get us out of this geometry.feature dependence. Perhaps geometries will always have a reference to feature - I'd like to have this be an undocumented part of the API for now.

So, I'm going to add jsdoc @private stuff where I think it's appropriate. Don't want this to hold up 2.4, but I also don't want it to have to wait for 3.0.

Attachments

partial.patch (8.5 kB) - added by tschaub on 04/04/07 00:17:50.
just to get feedback
geometry.feature.patch (23.9 kB) - added by tschaub on 04/04/07 02:25:59.
conceal geometry.feature
no.more.geometry.feature.patch (53.2 kB) - added by tschaub on 04/04/07 16:38:29.
end of geometry.feature
no-more-feature-r3034.patch (53.2 kB) - added by crschmidt on 04/10/07 06:51:16.

Change History

04/03/07 19:23:58 changed by sderle

what was the justification for having a geometry.feature property in the first place?

04/03/07 20:22:46 changed by crschmidt

We use it in the SelectFeature control:

Control/SelectFeature.js:89: if(OpenLayers.Util.indexOf(this.layer.selectedFeatures, geometry.feature) > -1) { Control/SelectFeature.js:95: if(OpenLayers.Util.indexOf(this.layer.selectedFeatures, geometry.feature) > -1) { Control/SelectFeature.js:120: if(!(OpenLayers.Util.indexOf(this.layer.selectedFeatures, geometry.feature) > -1)) { Control/SelectFeature.js:147: if(geometry.feature.originalStyle == null) { Control/SelectFeature.js:148: geometry.feature.originalStyle = geometry.feature.style; Control/SelectFeature.js:150: this.layer.selectedFeatures.push(geometry.feature); Control/SelectFeature.js:162: if(geometry.feature.originalStyle == null) { Control/SelectFeature.js:163: geometry.feature.originalStyle = geometry.feature.style; Control/SelectFeature.js:165: this.layer.renderer.drawGeometry(geometry, geometry.feature.originalStyle); Control/SelectFeature.js:166: OpenLayers.Util.removeItem(this.layer.selectedFeatures, geometry.feature);

04/04/07 00:17:50 changed by tschaub

  • attachment partial.patch added.

just to get feedback

04/04/07 00:20:46 changed by tschaub

Just want to make sure this sounds like the right direction. For 2.4, renderers will still have drawGeometry and geometry.feature will still exist. Nobody else should know this.

If you want to render a feature, do layer.renderFeature(feature) and give an optional style arg if you want.

Also, vector layers get the default style when instantiated.

If this sounds reasonable, I'll continue with the handlers, a few controls, and other examples that rely on the old way.

04/04/07 02:25:59 changed by tschaub

  • attachment geometry.feature.patch added.

conceal geometry.feature

04/04/07 02:36:22 changed by tschaub

  • keywords set to review.

Ok, the gist of this is that the supported way to render a feature is

layer.drawFeature(feature); // with an optional style arg

This replaces constructs like

layer.renderer.drawGeometry(feature.geometry, feature.style);

Also, if you find the need to use geometry.feature, you're probably doing something wrong. This sort of referencing is limited to handlers and renderers at this point. If you're writing a control or customizing an application, you should stick with geometry, feature, and feature.geometry.

Other included bits:

1) feature._setGeometryFeatureReference() has been removed in favor of recursive calls to feature.setGeometry()

2) tests have been added to show that feature.setGeometry() works

3) the lock/unlock editing stuff has been removed from Layer.Vector

04/04/07 12:58:56 changed by tschaub

  • keywords deleted.

Ok, don't think anybody is looking at this right now - so I'm removing the review request. I've got a couple other ideas I'd like to try...

04/04/07 16:37:49 changed by tschaub

This one does it. With this patch, geometry.feature is gone. The only reference to drawGeometry is in the renderers, otherwise, it's all drawFeature.

Scrolling through the patch:

1) examples - mostly replacing things like

    feature.layer.renderer.drawGeometry(feature.geometry, feature.style);

with

    feature.layer.drawFeature(feature);

2) Control/SelectFeature.js now deals in features instead of geometries - all references to geometry.feature replaced with feature.

3) Feature/Vector.js had a couple setters that were not used and useless. In particular, the recursive setGeometry was only used to set geometry.feature.

4) Format/GML.js and KML.js now set geometry directly

5) Geometry.js - lose feature property

6) Handler/Feature.js now deals exclusively in features

7) Handler/Point.js, Path.js, and Polygon.js - all deal in features instead of geometries (with the exception of the callbacks to the control - these get geometries because that's what they deserve [no style or attributes in this context])

8) Layer/Vector.js - the editing flags are irrelevant - the layer.renderer.reproject() call did the exact same thing that the loop below does (draw each feature), so this has been removed - a vector layer now has a drawFeature method, this is the appropriate place to do drawing, instead of layer.renderer.drawSomething() - also layer.getFeatureFromEvent() is new, more on this below

9) Renderer.js and subclasses - the "public" method of interest here is drawFeature(), called by the layer - renderer.drawGeometry() is very private - if you are not a renderer and you are calling drawGeometry(), you are doing something wrong - nodes no longer have expando properties like geometry (circular references that lead to memory leaks) - nodes now know about things like _featureId - this is returned to the layer when getFeatureIdFromEvent is called - the layer finds the corresponding feature (since it already has a collection of those)

10) More on renderers - the two places that node.geometry was required were reprojectNode and setStyle for circles (VML) - reprojectNode was not required, and setStyle is now called with the geometry it needs

That's it. 10 small things. And some tests.

Examples and tests can be run from http://dev.openlayers.org/sandbox/tschaub/feature

04/04/07 16:38:29 changed by tschaub

  • attachment no.more.geometry.feature.patch added.

end of geometry.feature

04/04/07 16:39:14 changed by tschaub

  • keywords set to review.

please review

04/10/07 06:51:16 changed by crschmidt

  • attachment no-more-feature-r3034.patch added.

04/10/07 06:52:19 changed by crschmidt

Tim:

Applied, updated to trunk, re-diffed, reuploaded. This code is good, the change is smart, and thank you for your diligence on this. Please apply to trunk and send email to the dev list informing them of methods which are going away so that people know to switch away from them, then mark pullup.

04/10/07 12:08:29 changed by tschaub

  • keywords changed from review to pullup.

reolved with r3043

04/19/07 21:21:28 changed by crschmidt

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

Brought up to 2.4 branch for RC2 with r3088