1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.control');
|
4 | goog.require('ol.format.OSMXML');
|
5 | goog.require('ol.layer.Tile');
|
6 | goog.require('ol.layer.Vector');
|
7 | goog.require('ol.loadingstrategy');
|
8 | goog.require('ol.proj');
|
9 | goog.require('ol.source.BingMaps');
|
10 | goog.require('ol.source.Vector');
|
11 | goog.require('ol.style.Circle');
|
12 | goog.require('ol.style.Fill');
|
13 | goog.require('ol.style.Stroke');
|
14 | goog.require('ol.style.Style');
|
15 |
|
16 | var map;
|
17 |
|
18 | var styles = {
|
19 | 'amenity': {
|
20 | 'parking': new ol.style.Style({
|
21 | stroke: new ol.style.Stroke({
|
22 | color: 'rgba(170, 170, 170, 1.0)',
|
23 | width: 1
|
24 | }),
|
25 | fill: new ol.style.Fill({
|
26 | color: 'rgba(170, 170, 170, 0.3)'
|
27 | })
|
28 | })
|
29 | },
|
30 | 'building': {
|
31 | '.*': new ol.style.Style({
|
32 | zIndex: 100,
|
33 | stroke: new ol.style.Stroke({
|
34 | color: 'rgba(246, 99, 79, 1.0)',
|
35 | width: 1
|
36 | }),
|
37 | fill: new ol.style.Fill({
|
38 | color: 'rgba(246, 99, 79, 0.3)'
|
39 | })
|
40 | })
|
41 | },
|
42 | 'highway': {
|
43 | 'service': new ol.style.Style({
|
44 | stroke: new ol.style.Stroke({
|
45 | color: 'rgba(255, 255, 255, 1.0)',
|
46 | width: 2
|
47 | })
|
48 | }),
|
49 | '.*': new ol.style.Style({
|
50 | stroke: new ol.style.Stroke({
|
51 | color: 'rgba(255, 255, 255, 1.0)',
|
52 | width: 3
|
53 | })
|
54 | })
|
55 | },
|
56 | 'landuse': {
|
57 | 'forest|grass|allotments': new ol.style.Style({
|
58 | stroke: new ol.style.Stroke({
|
59 | color: 'rgba(140, 208, 95, 1.0)',
|
60 | width: 1
|
61 | }),
|
62 | fill: new ol.style.Fill({
|
63 | color: 'rgba(140, 208, 95, 0.3)'
|
64 | })
|
65 | })
|
66 | },
|
67 | 'natural': {
|
68 | 'tree': new ol.style.Style({
|
69 | image: new ol.style.Circle({
|
70 | radius: 2,
|
71 | fill: new ol.style.Fill({
|
72 | color: 'rgba(140, 208, 95, 1.0)'
|
73 | }),
|
74 | stroke: null
|
75 | })
|
76 | })
|
77 | }
|
78 | };
|
79 |
|
80 | var vectorSource = new ol.source.Vector({
|
81 | format: new ol.format.OSMXML(),
|
82 | loader: function(extent, resolution, projection) {
|
83 | var epsg4326Extent =
|
84 | ol.proj.transformExtent(extent, projection, 'EPSG:4326');
|
85 | var client = new XMLHttpRequest();
|
86 | client.open('POST', 'https://overpass-api.de/api/interpreter');
|
87 | client.addEventListener('load', function() {
|
88 | var features = new ol.format.OSMXML().readFeatures(client.responseText, {
|
89 | featureProjection: map.getView().getProjection()
|
90 | });
|
91 | vectorSource.addFeatures(features);
|
92 | });
|
93 | var query = '(node(' +
|
94 | epsg4326Extent[1] + ',' + epsg4326Extent[0] + ',' +
|
95 | epsg4326Extent[3] + ',' + epsg4326Extent[2] +
|
96 | ');rel(bn)->.foo;way(bn);node(w)->.foo;rel(bw););out meta;';
|
97 | client.send(query);
|
98 | },
|
99 | strategy: ol.loadingstrategy.bbox
|
100 | });
|
101 |
|
102 | var vector = new ol.layer.Vector({
|
103 | source: vectorSource,
|
104 | style: function(feature) {
|
105 | for (var key in styles) {
|
106 | var value = feature.get(key);
|
107 | if (value !== undefined) {
|
108 | for (var regexp in styles[key]) {
|
109 | if (new RegExp(regexp).test(value)) {
|
110 | return styles[key][regexp];
|
111 | }
|
112 | }
|
113 | }
|
114 | }
|
115 | return null;
|
116 | }
|
117 | });
|
118 |
|
119 | var raster = new ol.layer.Tile({
|
120 | source: new ol.source.BingMaps({
|
121 | imagerySet: 'Aerial',
|
122 | key: 'As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5'
|
123 | })
|
124 | });
|
125 |
|
126 | map = new ol.Map({
|
127 | layers: [raster, vector],
|
128 | target: document.getElementById('map'),
|
129 | controls: ol.control.defaults({
|
130 | attributionOptions: {
|
131 | collapsible: false
|
132 | }
|
133 | }),
|
134 | view: new ol.View({
|
135 | center: [739218, 5906096],
|
136 | maxZoom: 19,
|
137 | zoom: 17
|
138 | })
|
139 | });
|