localwiki / localwiki-backend-server

Primary LocalWiki backend server environment
GNU General Public License v2.0
48 stars 16 forks source link

Small items on map should turn into points #69

Open philipn opened 9 years ago

philipn commented 9 years ago

From @philipn on September 4, 2012 20:57

At a certain zoom level, small items on the map should turn into points.

Not sure how to do this - maybe an OpenLayers Strategy?

Copied from original issue: localwiki/localwiki#334

philipn commented 9 years ago

From @wildintellect on September 4, 2012 23:46

Generally this is called scale dependent rendering. It all depends on if you're trying to do it from one layer or can call the same data twice as 2 layers. In the 2 layer scenario you can turn on/off each layer depending on zoom level and each can have 100% independent styling. What's the data source format for the layer in question, geojson?

philipn commented 9 years ago

Two layers would be fine. The data is WKT or GeoJSON. It looks like the scale dependent layer display stuff (this? http://dev.openlayers.org/releases/OpenLayers-2.12/examples/label-scale.html) is based more on the scale of the map zoom rather than the size of the object. What we want is to allow for, say, a really long street to appear as a linestring but turn into a point of its bbox is smaller than a certain size. Any ideas?

philipn commented 9 years ago

From @wildintellect on September 10, 2012 16:53

So, what I mean - at a given scale, for objects smaller than x, render like rule y else render as rule z. I know how to do this with QGIS rendering rules and assume it's also possible with Mapnik. I'm not so sure about a pure openlayers implementation. It's going to take a little more research.

The partial work around is in Django the page returns different json at different zooms, one being regular style the other being things Django/Postgis says are smaller than the size you want so returned as points. The problem with this is on each scale change you have to decide if you want to query django again.

wildintellect commented 9 years ago

A pure openlayers solution (or even pure client based js) is probably not what you want. This is typically where most services make use of Tile Server (leverages Mapnik) or WMS, so that the render rules are applied before being passed to the page, and the results are cached. 1000+ vectors on a single page is a big performance blocker, which vector tiles aim to solve.

Now there is one way I can think of getting around this, when you do the initial Django Query or possibly on Save of features to the db. Calculate the length and width of the feature. Using a lookup table of zoom levels and max width/length, assign a zoom level to the object for when it should switch from point marker to real rendering. Now you have a fast compare for OpenLayers to work off (simple integer compare), or an easy way to filter on the django request.