{"id":234,"date":"2015-01-12T13:10:59","date_gmt":"2015-01-12T12:10:59","guid":{"rendered":"http:\/\/blog.datashine.org.uk\/?p=234"},"modified":"2015-02-11T18:35:40","modified_gmt":"2015-02-11T17:35:40","slug":"openlayers-3","status":"publish","type":"post","link":"https:\/\/blog.datashine.org.uk\/2015\/01\/openlayers-3\/","title":{"rendered":"OpenLayers 3"},"content":{"rendered":"
<\/p>\n
This post is cross-posted from oobrien.com<\/a>.<\/i><\/p>\n OpenLayers is a powerful web mapping API that DataShine uses to display full-page “slippy” maps. DataShine: Census<\/a> has recently been upgraded to use OpenLayers 3<\/a>. Previously it was powered by OpenLayers 2, so it doesn’t sound like a major change, but OL3 is a major rewrite and as such it was quite an effort to migrate to it. In due course, we plan to migrate the other DataShine websites to OpenLayers 3 too, although each website is quite different under the covers so will prove a challenege too.<\/p>\n Here are some new features, now in DataShine<\/a>, which are made possible by the move to OpenLayers 3.<\/p>\n One of the nicest new features of OL3 is drag-and-dropping of KMLs<\/a>, GeoJSONs<\/a> and other geo-data files onto the map (simple example<\/a>). This adds the features pans and zooms the map to the appropriate area. This is likely most useful for showing political\/administrative boundaries, allowing for easier visual comparisons. For example, download and drag this file<\/a> onto DataShine<\/a> to see the GLA boundary appear. New buttons at the bottom allow for removal or opacity variation of the overlay files. If the added features include a “name” tag this appears on the key on the left, as you “mouse over” them. I modified the simple example to keep track of files added in this way, in an ol.layer.Group<\/i>, initially empty when added to the map during initialisation. Note: The file you drag on should be in WGS84 lat\/lon format (aka EPSG:4326) or WebMercator (aka ESPG:900913 or EPSG:3857). It will not work with the British National Grid projection (aka EPSG:27700).<\/p>\n Another key feature of OL3 that I was keen to make use of is much better looking printing of the map. With the updated library, this required only a few tweaks to CSS. Choosing the “background colours” option when printing is recommended. Printing also hides a couple of the panels you see on the website.<\/p>\n OL3 also has much smoother zooming, and nicer looking controls. Try moving the slider on the bottom right up and down, to see the smooth zooming effect. The scale control also changes smoothly. Finally, data attributes and credits are now contained in an expandable control on the bottom left.<\/p>\n A bonus update, unrelated to OL3, is that I’ve recreated the placename labels with the same font as the DataShine UI, Cabin Condensed. The previous font I was using was a bit ugly.<\/p>\n For notes on UTF Grids and Permalinks, both of which required a lot of work to reimplement so that DataShine with OL3 behaves like the version with OL2, see the developer blog post<\/a>.<\/p>\n <\/p>\n Above: GeoJSON-format datafiles for tube lines and stations (both in blue), added onto a DataShine map of commuters (% by tube) in south London.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":" This post is cross-posted from oobrien.com. OpenLayers is a powerful web mapping API that DataShine uses to display full-page “slippy” maps. DataShine: Census has recently been upgraded to use OpenLayers 3. Previously it was powered by OpenLayers 2, so it doesn’t sound like a major change, but OL3 is a major rewrite and as such … Continue reading OpenLayers 3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/posts\/234"}],"collection":[{"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":7,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/posts\/234\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/media?parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/categories?post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.datashine.org.uk\/wp-json\/wp\/v2\/tags?post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Drag-and-drop shapes<\/h4>\n
Nice printing<\/h4>\n
Better looking controls and smoother zooming<\/h4>\n