1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| import GeoJSON from 'ol/format/GeoJSON.js'; import Map from 'ol/Map.js'; import MultiPoint from 'ol/geom/MultiPoint.js'; import VectorLayer from 'ol/layer/Vector.js'; import VectorSource from 'ol/source/Vector.js'; import View from 'ol/View.js'; import {Circle as CircleStyle, Fill, Stroke, Style} from 'ol/style.js';
const styles = [
new Style({ stroke: new Stroke({ color: 'blue', width: 3, }), fill: new Fill({ color: 'rgba(0, 0, 255, 0.1)', }), }), new Style({ image: new CircleStyle({ radius: 5, fill: new Fill({ color: 'orange', }), }), geometry: function (feature) { const coordinates = feature.getGeometry().getCoordinates()[0]; return new MultiPoint(coordinates); }, }), ];
const geojsonObject = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:3857', }, }, 'features': [ { 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': [ [ [-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6], [-3e6, 6e6], [-5e6, 6e6], ], ], }, }, { 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': [ [ [-2e6, 6e6], [-2e6, 8e6], [0, 8e6], [0, 6e6], [-2e6, 6e6], ], ], }, }, { 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': [ [ [1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6], [1e6, 6e6], ], ], }, }, { 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': [ [ [-2e6, -1e6], [-1e6, 1e6], [0, -1e6], [-2e6, -1e6], ], ], }, }, ], };
const source = new VectorSource({ features: new GeoJSON().readFeatures(geojsonObject), });
const layer = new VectorLayer({ source: source, style: styles, });
const map = new Map({ layers: [layer], target: 'map', view: new View({ center: [0, 3000000], zoom: 2, }), });
|