Update geojson-vt example
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
#map {
|
|
||||||
background: #1a2b39;
|
|
||||||
}
|
|
||||||
@@ -22,6 +22,7 @@ const map = new Map({
|
|||||||
layers: [
|
layers: [
|
||||||
new VectorLayer({
|
new VectorLayer({
|
||||||
source: vectorSource,
|
source: vectorSource,
|
||||||
|
background: '#1a2b39',
|
||||||
style: function (feature) {
|
style: function (feature) {
|
||||||
const color = feature.get('COLOR_BIO') || '#eeeeee';
|
const color = feature.get('COLOR_BIO') || '#eeeeee';
|
||||||
style.getFill().setColor(color);
|
style.getFill().setColor(color);
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
||||||
import Map from '../src/ol/Map.js';
|
import Map from '../src/ol/Map.js';
|
||||||
import OSM from '../src/ol/source/OSM.js';
|
|
||||||
import Projection from '../src/ol/proj/Projection.js';
|
import Projection from '../src/ol/proj/Projection.js';
|
||||||
|
import VectorTileLayer from '../src/ol/layer/VectorTile.js';
|
||||||
import VectorTileSource from '../src/ol/source/VectorTile.js';
|
import VectorTileSource from '../src/ol/source/VectorTile.js';
|
||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import {
|
import {Fill, Style} from '../src/ol/style.js';
|
||||||
Tile as TileLayer,
|
|
||||||
VectorTile as VectorTileLayer,
|
|
||||||
} from '../src/ol/layer.js';
|
|
||||||
|
|
||||||
// Converts geojson-vt data to GeoJSON
|
// Converts geojson-vt data to GeoJSON
|
||||||
const replacer = function (key, value) {
|
const replacer = function (key, value) {
|
||||||
if (value.geometry) {
|
if (!value || !value.geometry) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
let type;
|
let type;
|
||||||
const rawType = value.type;
|
const rawType = value.type;
|
||||||
let geometry = value.geometry;
|
let geometry = value.geometry;
|
||||||
|
|
||||||
if (rawType === 1) {
|
if (rawType === 1) {
|
||||||
type = 'MultiPoint';
|
type = 'MultiPoint';
|
||||||
if (geometry.length == 1) {
|
if (geometry.length == 1) {
|
||||||
@@ -44,17 +43,25 @@ const replacer = function (key, value) {
|
|||||||
},
|
},
|
||||||
'properties': value.tags,
|
'properties': value.tags,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const map = new Map({
|
const style = new Style({
|
||||||
layers: [
|
fill: new Fill({
|
||||||
new TileLayer({
|
color: '#eeeeee',
|
||||||
source: new OSM(),
|
|
||||||
}),
|
}),
|
||||||
],
|
});
|
||||||
|
|
||||||
|
const layer = new VectorTileLayer({
|
||||||
|
background: '#1a2b39',
|
||||||
|
style: function (feature) {
|
||||||
|
const color = feature.get('COLOR') || '#eeeeee';
|
||||||
|
style.getFill().setColor(color);
|
||||||
|
return style;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const map = new Map({
|
||||||
|
layers: [layer],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new View({
|
view: new View({
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
@@ -62,7 +69,7 @@ const map = new Map({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const url = 'data/geojson/countries.geojson';
|
const url = 'https://openlayers.org/data/vector/ecoregions.json';
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
@@ -106,8 +113,5 @@ fetch(url)
|
|||||||
tile.setFeatures(features);
|
tile.setFeatures(features);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const vectorLayer = new VectorTileLayer({
|
layer.setSource(vectorSource);
|
||||||
source: vectorSource,
|
|
||||||
});
|
|
||||||
map.addLayer(vectorLayer);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
#map {
|
|
||||||
background: #1a2b39;
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,7 @@ const style = new Style({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const vectorLayer = new VectorLayer({
|
const vectorLayer = new VectorLayer({
|
||||||
|
background: '#1a2b39',
|
||||||
source: new VectorSource({
|
source: new VectorSource({
|
||||||
url: 'https://openlayers.org/data/vector/ecoregions.json',
|
url: 'https://openlayers.org/data/vector/ecoregions.json',
|
||||||
format: new GeoJSON(),
|
format: new GeoJSON(),
|
||||||
|
|||||||
Reference in New Issue
Block a user