MultiPolygonFeature on VectorLayer Shifting on Zooming out using EPSG:3857

33 views
Skip to first unread message

ED

unread,
Aug 12, 2013, 6:33:55 PM8/12/13
to opensca...@googlegroups.com
The MultiPolygonFeature class' executeDrawing method becomes unusably slow when plotting a large amount of shapes (eg All US Counties, 3100+polygons) because it's redraw is triggered too frequently as the map pans and zooms. To work around this performance issue, I have commented out the "|| mapReloadCache" from the following conditional statements so that a full draw only happens on the first initialization and subsequent "redraws" are used to scale and move the layer.

This approach has worked well and has been a huge performance boost, whereas before, it was completely unusable as it took tens of seconds to redraw each time as the map panned and zoomed. The problem that I am encountering now, is say I'm zoomed in by default on San Diego at a close zoom level (neighborhood-level) and I render the US by County MultiPolygon Feature. As I zoom back out to a country-level and pan the map, the shapes lose their correct anchor point as shown in the image attached. The layer does not ever correct itself after this has happened. However, if I render the shapes while the map is zoomed out at a higher level (country level) and I subsequently zoom in and out to the min and max resolutions and also pan the map, the shapes anchor and track perfectly during the whole lifetime of the map session. So, it seems that this behavior is triggered by rendering the shapes when the initial zoom level is very close. The code below shows the changes ("// || mapReloadCache") I made to the VectorLayer class in the case where the feature being drawn is a MultiPolygonFeature. As for projection, I am using EPSG:3857 across the entire map and all of its layers.

Does anyone have a ballpark idea of why and where the problem of my shape vector layers getting anchored incorrectly may be occurring? I know the issue is visible when running in the if (resolutionChangedCache) and if (centerChangedCache) statements, however I'm not sure where to begin looking for the root of the problem.

                                                                                if (fullRedraw)// || mapReloadCache)
{
this.clear();
}
if (!this._initialized || fullRedraw)//  || mapReloadCache)
{
this.x = 0;
this.y = 0;
this.scaleX = 1;
this.scaleY = 1;
this._lastReloadedCenter = this.map.center.clone();
this._lastReloadedResolution = this.map.resolution;
this.draw();
this._previousResolution = this.map.resolution;
this._previousCenter = this.map.center.clone();
this._initialized = true;
return;
}
if (resolutionChangedCache)
{
if (!this._previousResolution)
{
this._previousResolution = this.map.resolution;
}
this.cacheAsBitmap = false;
var ratio:Number = this._previousResolution.value / this.map.resolution.value;
this.scaleLayer(ratio, new Pixel(this.map.size.w/2, this.map.size.h/2));
this._previousResolution = this.map.resolution;
resolutionChangedCache = false;
this.cacheAsBitmap = true;
}
if (centerChangedCache)
{
if (!this._previousCenter)
{
this._previousCenter = this.map.center.clone();
}
var deltaLon:Number = this.map.center.lon - this._previousCenter.lon;
var deltaLat:Number = this.map.center.lat - this._previousCenter.lat;
var deltaX:Number = deltaLon/this.map.resolution.value;
var deltaY:Number = deltaLat/this.map.resolution.value;
this.x = this.x - deltaX;
this.y = this.y + deltaY;
this._previousCenter = this.map.center.clone();
centerChangedCache = false;
}
FloridaOffset.PNG
Reply all
Reply to author
Forward
0 new messages