Discussion:
[Geoserver-users] Always Visible Labels in Polygons
FunkMonkey33
2017-05-12 16:27:25 UTC
Permalink
I'm currently able to zoom past the labels in my polygons.

I understand that this will happen with GWC.

It's also happening with WMS, when I set tiled=true. I'm thinking tiled
imagery, not caching, is preventing the labels from re-positioning
themselves to the center of the visible portion of the polygon.

Unfortunately, I'm using Google Maps, which doesn't seem to have an untiled
image overlay class. I may have to improvise there.

Thanks.

Aaron



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Always-Visible-Labels-in-Polygons-tp5320370.html
Sent from the GeoServer - User mailing list archive at Nabble.com.
FunkMonkey33
2017-06-29 21:08:05 UTC
Permalink
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
Andrea Aime
2017-06-30 07:31:24 UTC
Permalink
Hi,
the labelling and tiling topic has been beaten to death already in
countless discussions
on the net, search around on stackexchange and on google in general, and
look up meta-tiling settings, usage of the centroid function, and the like

Regards
Andrea


On Fri, May 12, 2017 at 6:27 PM, FunkMonkey33 <
Post by FunkMonkey33
I'm currently able to zoom past the labels in my polygons.
I understand that this will happen with GWC.
It's also happening with WMS, when I set tiled=true. I'm thinking tiled
imagery, not caching, is preventing the labels from re-positioning
themselves to the center of the visible portion of the polygon.
Unfortunately, I'm using Google Maps, which doesn't seem to have an untiled
image overlay class. I may have to improvise there.
Thanks.
Aaron
--
View this message in context: http://osgeo-org.1560.x6.
nabble.com/Always-Visible-Labels-in-Polygons-tp5320370.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
https://lists.sourceforge.net/lists/listinfo/geoserver-users
--
Regards,

Andrea Aime

==
GeoServer Professional Services from the experts! Visit http://goo.gl/it488V
for more information.
==

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054 Massarosa (LU)
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo Ú consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.
Loading...