提出的解決方案由喬恩·斯奈德與一般的想法提供給我們,但並沒有進行到底(特別是延伸OpenLayers.Layer.Vector
工作充分WASN」這是基於OpenLayers 2.1x的任務所必需的)。
我們創建了一個類YourApp.Handler.EndPointsPath
(擴展OpenLayers.Handler.Path
),其中函數geometryClone()
返回類型爲YourApp.Geometry.EndPointsPath
的新幾何。
然後我們在OpenLayers.Renderer.Elements
修補的功能drawGeometry()
得出這個新的幾何形狀:
OpenLayers.Util.extend(OpenLayers.Renderer.Elements.prototype, {
drawGeometry: function (geometry, style, featureId) {
var cl = geometry.CLASS_NAME;
var rendered = true,
i, len;
if ((cl === "OpenLayers.Geometry.Collection") ||
(cl === "OpenLayers.Geometry.MultiPoint") ||
(cl === "OpenLayers.Geometry.MultiLineString") ||
(cl === "OpenLayers.Geometry.MultiPolygon") ||
(cl === "YourApp.Geometry.EndPointsPath")) {
// Iterate over all Geometry components and draw each individually
for (i = 0, len = geometry.components.length; i < len; i++) {
// Is there a style for each of the components?
if (OpenLayers.Util.isArray(style)) {
// Draw Geometry with own style
rendered = this.drawGeometry(geometry.components[i], style[i], featureId) && rendered;
} else {
// Draw Geometry with common style
rendered = this.drawGeometry(geometry.components[i], style, featureId) && rendered;
}
}
return rendered;
}
// (...standard code...)
},
eraseGeometry: function (geometry, featureId) {
var cl = geometry.CLASS_NAME,
i, len;
if ((cl === "OpenLayers.Geometry.MultiPoint") ||
(cl === "OpenLayers.Geometry.MultiLineString") ||
(cl === "OpenLayers.Geometry.MultiPolygon") ||
(cl === "YourApp.Geometry.EndPointsPath") ||
(cl === "OpenLayers.Geometry.Collection")) {
for (i = 0, len = geometry.components.length; i < len; i++) {
this.eraseGeometry(geometry.components[i], featureId);
}
// (...standard code...)
}
}
});
我正要做這樣的事情,但只是想確認有沒有更簡單,更耗時的工作方案。謝謝! – gregorej 2010-12-01 07:57:36