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