Use static GeoJSON instead of Overpass query for faster loading
This commit is contained in:
1 parent
1249b46e5d
commit
0f29ea4f0e
3 files changed
+11
-21
No files matched your search
@@ -0,0 +1 @@
|
||||
{"type":"FeatureCollection","features":[{"type":"Feature","id":"483167828","geometry":{"type":"LineString","coordinates":[[16.4128982,48.21976249999997],[16.4139828,48.21894370000001]]},"properties":{"highway":"primary","is_in":"Austria,Vienna,Wien","lanes":"4","maxspeed":"50","name":"Handelskai","ref":"B14","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"5022444","geometry":{"type":"LineString","coordinates":[[16.4101713,48.2228049],[16.4103365,48.22268380000003],[16.410552,48.222525899999994],[16.4107283,48.22240790000001],[16.4110769,48.2221802],[16.4115313,48.221854500000035],[16.4118242,48.2216454],[16.4121066,48.221445399999965],[16.4128993,48.220839299999994],[16.413,48.220846300000005],[16.4131035,48.22082360000002],[16.4143181,48.21991569999997],[16.4143435,48.2198564],[16.4143063,48.21979640000001]]},"properties":{"foot":"yes","highway":"cycleway","name":"Praterlände","segregated":"no","surface":"paved"}},{"type":"Feature","id":"31352080","geometry":{"type":"LineString","coordinates":[[16.4120646,48.21940230000001],[16.412566,48.2197012],[16.4130734,48.22001080000001]]},"properties":{"bridge":"yes","foot":"designated","highway":"cycleway","layer":"1","lcn":"yes","name":"Kafkasteg","segregated":"yes"}},{"type":"Feature","id":"29222706","geometry":{"type":"LineString","coordinates":[[16.4120309,48.2192527],[16.4125033,48.21952910000002],[16.4126829,48.21963410000001],[16.4128982,48.21976249999997]]},"properties":{"highway":"residential","maxspeed":"50","name":"Kafkastraße","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"31352078","geometry":{"type":"LineString","coordinates":[[16.4120309,48.2192527],[16.4112722,48.21878480000001]]},"properties":{"highway":"residential","maxspeed":"50","name":"Kafkastraße","source:maxspeed":"AT:urban","surface":"asphalt"}},{"type":"Feature","id":"5020147","geometry":{"type":"LineString","coordinates":[[16.4065985,48.2204309],[16.4072965,48.22084100000001]]},"properties":{"cycleway":"opposite","highway":"residential","maxspeed":"50","name":"Hillerstraße","oneway":"yes","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"35383757","geometry":{"type":"LineString","coordinates":[[16.4059654,48.22091499999999],[16.4065985,48.2204309]]},"properties":{"highway":"tertiary","maxspeed":"50","name":"Vorgartenstraße","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"9289497","geometry":{"type":"LineString","coordinates":[[16.4065985,48.2204309],[16.4064863,48.22035979999998],[16.4058094,48.21996100000001],[16.4052407,48.219629]]},"properties":{"highway":"residential","maxspeed":"30","name":"Hillerstraße","source:maxspeed":"AT:zone:30"}},{"type":"Feature","id":"29303490","geometry":{"type":"LineString","coordinates":[[16.4094381,48.21999310000001],[16.4095157,48.22003810000001],[16.4097946,48.22021079999996]]},"properties":{"highway":"residential","maxspeed":"50","name":"Teuffenbachstraße","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"31642811","geometry":{"type":"LineString","coordinates":[[16.4074944,48.223803299999986],[16.4075946,48.223730700000004],[16.4080902,48.2233564],[16.4121661,48.220310600000005],[16.4128982,48.21976249999997]]},"properties":{"highway":"primary","is_in":"Austria,Vienna,Wien","lanes":"4","maxspeed":"50","name":"Handelskai","ref":"B14","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"317845493","geometry":{"type":"LineString","coordinates":[[16.4094381,48.21999310000001],[16.4088051,48.220435899999984],[16.4078839,48.22108270000001],[16.4078008,48.22113839999997]]},"properties":{"highway":"residential","maxspeed":"50","name":"Engerthstraße","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"31302830","geometry":{"type":"LineString","coordinates":[[16.4065985,48.2204309],[16.4069002,48.22019800000004],[16.4081559,48.21923589999997]]},"properties":{"highway":"tertiary","is_in":"Austria,Wien","maxspeed":"50","name":"Vorgartenstraße","source:maxspeed":"AT:urban"}},{"type":"Feature","id":"29100906","geometry":{"type":"LineString","coordinates":[[16.4050205,48.2187892],[16.4050295,48.21932559999999]]},"properties":{"cycleway":"opposite_lane","highway":"residential","maxspeed":"30","name":"Schrotzbergstraße","oneway":"yes","oneway:bicycle":"no","source:maxspeed":"AT:zone:30"}},{"type":"Feature","id":"483167827","geometry":{"type":"LineString","coordinates":[[16.4139828,48.21894370000001],[16.4148045,48.21833480000001]]},"properties":{"highway":"primary","is_in":"Austria,Vienna,Wien","lanes":"4","maxspeed":"50","name":"Handelskai","ref":"B14","source:maxspeed":"AT:urban","turn:lanes:backward":"left|through"}},{"type":"Feature","id":"141499898","geometry":{"type":"LineString","coordinates":[[16.4131749,48.21843160000003],[16.4131143,48.21847589999999],[16.4124106,48.21898139999999],[16.4120309,48.2192527]]},"properties":{"cycleway":"opposite_lane","highway":"residential","maxspeed":"50","name":"Wehlistraße","oneway":"yes","oneway:bicycle":"no","surface":"asphalt"}},{"type":"Feature","id":"317740946","geometry"Line truncated
|
||||
@@ -3,10 +3,10 @@ layout: example.html
|
||||
title: Street Labels
|
||||
shortdesc: Render street names with a custom render.
|
||||
docs: >
|
||||
Example showing the use of a custom renderer to render text along a path. [Labelgun](https://github.com/Geovation/labelgun) is used to avoid label collisions. [label-segment](https://github.com/ahocevar/label-segment) makes sure that labels are placed on suitable street segments. [textpath](https://github.com/ahocevar/textpath) arranges the letters of a label along the geometry. The data is fetched from OSM using the [Overpass API](https://overpass-api.de).
|
||||
tags: "vector, label, collision detection, labelgun, linelabel, overpass"
|
||||
Example showing the use of a custom renderer to render text along a path. [Labelgun](https://github.com/Geovation/labelgun) is used to avoid label collisions. [label-segment](https://github.com/ahocevar/label-segment) makes sure that labels are placed on suitable street segments. [textpath](https://github.com/ahocevar/textpath) arranges the letters of a label along the geometry.
|
||||
tags: "vector, label, collision detection, labelgun, linelabel"
|
||||
resources:
|
||||
- https://cdn.polyfill.io/v2/polyfill.min.js?features=Set"
|
||||
- https://cdn.polyfill.io/v2/polyfill.min.js?features=Set
|
||||
- https://unpkg.com/rbush@2.0.1/rbush.min.js
|
||||
- https://unpkg.com/labelgun@0.1.1/lib/labelgun.min.js
|
||||
- https://unpkg.com/textpath@1.0.1/dist/textpath.js
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.format.OSMXML');
|
||||
goog.require('ol.format.GeoJSON');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.BingMaps');
|
||||
@@ -25,8 +25,8 @@ function collectDrawData(letter, x, y, angle) {
|
||||
}
|
||||
|
||||
var style = new ol.style.Style({
|
||||
renderer: function(coords, context) {
|
||||
var feature = context.feature;
|
||||
renderer: function(coords, state) {
|
||||
var feature = state.feature;
|
||||
var text = feature.get('name');
|
||||
// Only create label when geometry has a long and straight segment
|
||||
var path = labelSegment(coords, Math.PI / 8, measureText(text));
|
||||
@@ -51,22 +51,11 @@ var rasterLayer = new ol.layer.Tile({
|
||||
})
|
||||
});
|
||||
|
||||
var source = new ol.source.Vector();
|
||||
// Request streets from OSM, using the Overpass API
|
||||
fetch('https://overpass-api.de/api/interpreter', {
|
||||
method: 'POST',
|
||||
body: '(way["highway"](48.19642,16.32580,48.22050,16.41986));(._;>;);out meta;'
|
||||
}).then(function(response) {
|
||||
return response.text();
|
||||
}).then(function(responseText) {
|
||||
var features = new ol.format.OSMXML().readFeatures(responseText, {
|
||||
featureProjection: 'EPSG:3857'
|
||||
});
|
||||
source.addFeatures(features);
|
||||
});
|
||||
|
||||
var vectorLayer = new ol.layer.Vector({
|
||||
source: source,
|
||||
source: new ol.source.Vector({
|
||||
format: new ol.format.GeoJSON(),
|
||||
url: 'data/geojson/vienna-streets.geojson'
|
||||
}),
|
||||
style: function(feature) {
|
||||
if (feature.getGeometry().getType() == 'LineString' && feature.get('name')) {
|
||||
return style;
|
||||
|
||||
Reference in new issue
Block a user