171 lines
3.6 KiB
JavaScript
171 lines
3.6 KiB
JavaScript
import Map from 'ol/Map.js';
|
|
import View from 'ol/View.js';
|
|
import {defaults as defaultControls, Attribution as AttributionControl} from 'ol/control.js';
|
|
import {all as allStrategy} from 'ol/loadingstrategy';
|
|
import {bbox as bboxStrategy} from 'ol/loadingstrategy.js';
|
|
import TileLayer from 'ol/layer/Tile';
|
|
import OSM from 'ol/source/OSM.js';
|
|
import XYZ from 'ol/source/XYZ';
|
|
import {fromLonLat} from 'ol/proj.js';
|
|
import VectorLayer from 'ol/layer/Vector.js';
|
|
import VectorSource from 'ol/source/Vector.js';
|
|
import VectorTileLayer from 'ol/layer/VectorTile.js';
|
|
import VectorTileSource from 'ol/source/VectorTile.js';
|
|
import OSMXML from 'ol/format/OSMXML.js';
|
|
import {Circle as CircleStyle, Fill, Stroke, Style, Text} from 'ol/style.js';
|
|
|
|
|
|
const coordinate_cccamp19 = fromLonLat([13.30735, 53.03127]);
|
|
|
|
|
|
var styles = {
|
|
'amenity': {
|
|
'parking': new Style({
|
|
stroke: new Stroke({
|
|
color: 'rgba(170, 170, 170, 1.0)',
|
|
width: 1
|
|
}),
|
|
fill: new Fill({
|
|
color: 'rgba(170, 170, 170, 0.3)'
|
|
})
|
|
})
|
|
},
|
|
'building': {
|
|
'.*': new Style({
|
|
zIndex: 100,
|
|
stroke: new Stroke({
|
|
color: 'rgba(246, 99, 79, 1.0)',
|
|
width: 1
|
|
}),
|
|
fill: new Fill({
|
|
color: 'rgba(246, 99, 79, 0.3)'
|
|
}),
|
|
text: new Text({
|
|
font: '12px Calibri,sans-serif',
|
|
fill: new Fill({
|
|
color: '#000'
|
|
}),
|
|
stroke: new Stroke({
|
|
color: '#fff',
|
|
width: 3
|
|
})
|
|
})
|
|
})
|
|
},
|
|
'highway': {
|
|
'service': new Style({
|
|
stroke: new Stroke({
|
|
color: 'rgba(255, 255, 255, 1.0)',
|
|
width: 2
|
|
})
|
|
}),
|
|
'.*': new Style({
|
|
stroke: new Stroke({
|
|
color: 'rgba(255, 255, 255, 1.0)',
|
|
width: 3
|
|
})
|
|
})
|
|
},
|
|
'landuse': {
|
|
'forest|grass|allotments': new Style({
|
|
stroke: new Stroke({
|
|
color: 'rgba(0, 0, 170, 1.0)',
|
|
width: 1
|
|
}),
|
|
fill: new Fill({
|
|
color: 'rgba(0, 0, 170, 0.3)'
|
|
}),
|
|
text: new Text({
|
|
font: '12px Calibri,sans-serif',
|
|
fill: new Fill({
|
|
color: '#000'
|
|
}),
|
|
stroke: new Stroke({
|
|
color: '#fff',
|
|
width: 3
|
|
})
|
|
})
|
|
})
|
|
},
|
|
'natural': {
|
|
'tree': new Style({
|
|
image: new CircleStyle({
|
|
radius: 2,
|
|
fill: new Fill({
|
|
color: 'rgba(140, 208, 95, 1.0)'
|
|
}),
|
|
stroke: null
|
|
})
|
|
})
|
|
},
|
|
'name': {
|
|
'.*': new Style({
|
|
text: new Text({
|
|
font: '12px Calibri,sans-serif',
|
|
fill: new Fill({
|
|
color: '#000'
|
|
}),
|
|
stroke: new Stroke({
|
|
color: '#fff',
|
|
width: 3
|
|
})
|
|
})
|
|
})
|
|
}
|
|
};
|
|
|
|
var vectorSource = new VectorSource({
|
|
format: new OSMXML(),
|
|
url: 'https://seafile.milliways.info/f/688170149668429f9598/?dl=1',
|
|
strategy: allStrategy
|
|
})
|
|
|
|
var map = new Map({
|
|
target: 'map',
|
|
controls: defaultControls().extend([
|
|
]),
|
|
numZoomLevels: 19,
|
|
units: 'm',
|
|
layers: [
|
|
new TileLayer({
|
|
source: new OSM()
|
|
}),
|
|
new VectorLayer({
|
|
source: vectorSource,
|
|
style: function(feature) {
|
|
for (var key in styles) {
|
|
var value = feature.get(key);
|
|
if (value !== undefined) {
|
|
for (var regexp in styles[key]) {
|
|
if (new RegExp(regexp).test(value)) {
|
|
var style = styles[key][regexp];
|
|
var text = feature.get('name');
|
|
if(text !== undefined ) {
|
|
if(feature.get('size') !== undefined) {
|
|
text += '\n' + feature.get('size');
|
|
}
|
|
}
|
|
style.getText().setText(text);
|
|
return style;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
})
|
|
],
|
|
view: new View({
|
|
center: coordinate_cccamp19,
|
|
zoom: 17
|
|
})
|
|
});
|
|
|
|
|
|
|
|
document.map = map;
|
|
|
|
module.export= {
|
|
mapa: map
|
|
}
|