I was able to get the behavior I want by (1) using WMS, not GWC, (2) Setting
tiled=false, (3) Subclassing the Google maps overlayView class, which is the
only way to get Google maps to show a custom WMS map without tiling it.
Here is my code for myGoogle Maps OverlayView extension, in case it helps
someone someday:
export class WsUntiledOverlay {
// wsMap is our class that has a reference both to the raw google.map
object, as well as the div which contains the map.
constructor(bounds, image, wsMap) {
this.bounds_ = bounds;
this.image_ = image;
this._wsMap = wsMap;
this.map_= wsMap._map;
this.div_ = null;
this.setMap(wsMap._map);
this.onAdd = function() {
let div = document.createElement('div');
div.style.position = 'absolute';
div.style.height = this._wsMap.mapCanvas.clientHeight + 'px';
div.style.width = this._wsMap.mapCanvas.clientWidth + 'px';
this._image = document.createElement('img');
this._image.src = this.image_;
this._image.style.width = '100%';
this._image.style.height = '100%';
this._image.style.position = 'absolute';
this._image.style.margin = '0px';
this._image.style.padding = '0px';
div.appendChild(this._image);
this.div_ = div;
let panes = this.getPanes();
panes.overlayLayer.appendChild(div);
this._dragEndListener = this.map_.addListener('idle', () => {
this.draw();
});
};
this.draw = function() {
this._image.style.display = 'none';
this._image.src = this.getImage();
this._image.style.display = 'block';
let overlayProjection = this.getProjection();
let bbox = this.map_.getBounds();
let SW = bbox.getSouthWest();
let NE = bbox.getNorthEast();
let sw = overlayProjection.fromLatLngToDivPixel(SW);
let ne = overlayProjection.fromLatLngToDivPixel(NE);
let div = this.div_;
div.style.left = sw.x + 'px';
// hack: this is compensating for a projection issue.
let yOffset = 0;
// hack: sometimes currentZoomLevel is a string!
let currentZoomLevel = this._wsMap.currentZoomLevel * 1;
if (currentZoomLevel === 5) {
yOffset = 40;
}
else if (currentZoomLevel === 6) {
yOffset = 20;
}
else if (currentZoomLevel === 7) {
yOffset = 10;
}
else {
yOffset = 0;
}
div.style.top = ne.y + yOffset + 'px';
div.style.width = (ne.x - sw.x) + 'px';
div.style.height = (sw.y - ne.y) + 'px';
};
this.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
google.maps.event.removeListener(this._dragEndListener);
this.div_ = null;
};
}
}
When you create an instance of this class, to add it to the map, you need to
define the getImage() function. We do something like this:
let untiledOverlay = new WsUntiledOverlay(bounds, url, this);
untiledOverlay.getImage = function() {
let width = mapCanvas.clientWidth;
let height = mapCanvas.clientHeight;
let zoom = map.getZoom();
let newBounds = map.getBounds();
let layerurl = wmsService.getUntiledGetMapUrl(newBounds,
layerName, zoom, style, width, height);
return layerurl;
};
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Always-Visible-Labels-in-Polygons-tp5320370p5326094.html
Sent from the GeoServer - User mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list
Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: http://geoserver.org/comm/userlist-guidelines.html
Geoserver-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users