|
52 | 52 | <div id="popup-content"></div>
|
53 | 53 | </div>
|
54 | 54 | <script type="text/javascript">
|
55 |
| - var url = (window.isLocal ? document.location.host : "http://support.supermap.com.cn:8090") + "/iserver/services/map-china400/rest/maps/China_4326"; |
| 55 | + var url = (window.isLocal ? document.location.host : "http://support.supermap.com.cn:8090") + "/iserver/services/map-china400/rest/maps/ChinaDark"; |
| 56 | + |
| 57 | + var map; |
56 | 58 | var colorCount = 10;
|
57 | 59 | var colors = getRandomColors(colorCount);
|
58 |
| - new ol.supermap.MapService(url).getMapInfo(function (serviceResult) { |
59 |
| - var mapJSONObj = serviceResult.result; |
60 |
| - var container = document.getElementById('popup'); |
61 |
| - var content = document.getElementById('popup-content'); |
62 |
| - var overlay = new ol.Overlay(({ |
63 |
| - element: container, |
64 |
| - autoPan: true, |
65 |
| - autoPanAnimation: { |
66 |
| - duration: 250 |
67 |
| - } |
68 |
| - })); |
69 |
| - var map = new ol.Map({ |
70 |
| - target: 'map', |
71 |
| - controls: ol.control.defaults({attributionOptions: {collapsed: false}}) |
72 |
| - .extend([new ol.supermap.control.Logo()]), |
73 |
| - view: new ol.View({ |
74 |
| - center: [0, 0], |
75 |
| - zoom: 2, |
76 |
| - projection: 'EPSG:4326' |
77 |
| - }), |
78 |
| - overlays: [overlay], |
79 |
| - renderer: ['canvas'] |
80 |
| - }); |
81 |
| - var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj); |
82 |
| - var layer = new ol.layer.Tile({ |
83 |
| - source: new ol.source.TileSuperMapRest(options) |
84 |
| - }); |
85 |
| - map.addLayer(layer); |
86 | 60 |
|
87 |
| - var randomCircleStyles = []; |
88 |
| - for (var i = 0; i < colorCount; i++) { |
89 |
| - randomCircleStyles.push(new ol.style.RegularShape({ |
90 |
| - radius: Math.floor(Math.random() * 15 + 1), |
91 |
| - fill: new ol.style.Fill({ |
92 |
| - color: colors[i] |
93 |
| - }), |
94 |
| - stroke: new ol.style.Stroke({ |
95 |
| - color: colors[i] |
96 |
| - }), |
97 |
| - points: 3, |
| 61 | + $.get('../data/nyc_taxi.json', function (nycData) { |
| 62 | + new ol.supermap.MapService(url).getMapInfo(function (serviceResult) { |
| 63 | + var mapJSONObj = serviceResult.result; |
| 64 | + var container = document.getElementById('popup'); |
| 65 | + var content = document.getElementById('popup-content'); |
| 66 | + var overlay = new ol.Overlay(({ |
| 67 | + element: container, |
| 68 | + autoPan: true, |
| 69 | + autoPanAnimation: { |
| 70 | + duration: 250 |
| 71 | + } |
98 | 72 | }));
|
99 |
| - } |
| 73 | + map = new ol.Map({ |
| 74 | + target: 'map', |
| 75 | + controls: ol.control.defaults({attributionOptions: {collapsed: false}}) |
| 76 | + .extend([new ol.supermap.control.Logo()]), |
| 77 | + view: new ol.View({ |
| 78 | + center: ol.proj.transform([-73.9286, 40.75], 'EPSG:4326', 'EPSG:3857'), |
| 79 | + zoom: 12, |
| 80 | + projection: 'EPSG:3857' |
| 81 | + }), |
| 82 | + overlays: [overlay], |
| 83 | + renderer: ['canvas'] |
| 84 | + }); |
| 85 | + var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj); |
| 86 | + var layer = new ol.layer.Tile({ |
| 87 | + source: new ol.source.TileSuperMapRest(options) |
| 88 | + }); |
| 89 | + map.addLayer(layer); |
100 | 90 |
|
101 |
| - var count = 100000; //矢量点的个数 |
102 |
| - var graphics = new Array(count); |
103 |
| - var e = 45; |
104 |
| - for (var i = 0; i < count; ++i) { |
105 |
| - var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e]; |
106 |
| - graphics[i] = new ol.Graphic(new ol.geom.Point(coordinates)); |
107 |
| - graphics[i].setStyle(randomCircleStyles[Math.floor(Math.random() * colorCount)]); |
108 |
| - } |
109 |
| - map.once('postrender', function () { |
110 |
| - var graphicLayer = new ol.layer.Image({ |
111 |
| - source: new ol.source.Graphic({ |
112 |
| - graphics: graphics, |
113 |
| - map: map, |
114 |
| - onClick: function (graphic) { |
115 |
| - if (graphic) { |
116 |
| - var coords = graphic.getGeometry().getCoordinates(); |
117 |
| - content.innerHTML = resources.text_coordinate + ":[" + coords[0] + "," + coords[1] + "]"; |
118 |
| - overlay.setPosition(graphic.getGeometry().getCoordinates()); |
119 |
| - return; |
| 91 | + var randomCircleStyles = []; |
| 92 | + for (var i = 0; i < colorCount; i++) { |
| 93 | + randomCircleStyles.push(new ol.style.RegularShape({ |
| 94 | + radius: Math.floor(Math.random() * 10 + 1), |
| 95 | + fill: new ol.style.Fill({ |
| 96 | + color: colors[i] |
| 97 | + }), |
| 98 | + stroke: new ol.style.Stroke({ |
| 99 | + color: colors[i] |
| 100 | + }), |
| 101 | + points: 3, |
| 102 | + })); |
| 103 | + } |
| 104 | + |
| 105 | + var count = nycData.features.length; //矢量点的个数 |
| 106 | + var graphics = new Array(count); |
| 107 | + for (var i = 0; i < count; ++i) { |
| 108 | + var coordinates = nycData.features[i].geometry.coordinates; |
| 109 | + if (coordinates[0] === coordinates[1]) { |
| 110 | + continue; |
| 111 | + } |
| 112 | + coordinates = ol.proj.transform(coordinates, 'EPSG:4326', 'EPSG:3857'); |
| 113 | + graphics[i] = new ol.Graphic(new ol.geom.Point(coordinates)); |
| 114 | + graphics[i].setStyle(randomCircleStyles[Math.floor(Math.random() * colorCount)]); |
| 115 | + } |
| 116 | + map.once('postrender', function () { |
| 117 | + var graphicLayer = new ol.layer.Image({ |
| 118 | + source: new ol.source.Graphic({ |
| 119 | + graphics: graphics, |
| 120 | + map: map, |
| 121 | + onClick: function (graphic) { |
| 122 | + if (graphic) { |
| 123 | + var coords = graphic.getGeometry().getCoordinates(); |
| 124 | + content.innerHTML = resources.text_coordinate + ":[" + coords[0] + "," + coords[1] + "]"; |
| 125 | + overlay.setPosition(graphic.getGeometry().getCoordinates()); |
| 126 | + return; |
| 127 | + } |
| 128 | + overlay.setPosition(undefined); |
120 | 129 | }
|
121 |
| - overlay.setPosition(undefined); |
122 |
| - } |
123 |
| - }) |
124 |
| - }); |
125 |
| - map.addLayer(graphicLayer); |
126 |
| - }) |
127 |
| - }); |
| 130 | + }) |
| 131 | + }); |
| 132 | + map.addLayer(graphicLayer); |
| 133 | + }) |
| 134 | + }); |
128 | 135 |
|
| 136 | + |
| 137 | + }); |
129 | 138 | function getRandomColors(count) {
|
130 | 139 | return randomColor({
|
131 | 140 | luminosity: 'bright',
|
|
0 commit comments