-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadkml.js
268 lines (238 loc) · 7.09 KB
/
loadkml.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
var styleCache = {}
var styleFunction = function(feature, resolution) {
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
// standards-violating <magnitude> tag in each Placemark. We extract it from
// the Placemark's name instead.
var name = feature.get('name');
var magnitude = parseFloat(name.substr(2));
var radius = 5 + 20 * (magnitude - 5);
// 不同的等级,计算不同radius..如果已有style,就不重新赋值style。
var style = styleCache[radius];
if (!style) {
style = [new ol.style.Style({
image: new ol.style.Circle({
radius: radius,
fill: new ol.style.Fill({
// color: 'rbga(255,204,51,0.5)'
color: 'rgba(255, 204, 51, 0.6)'
}),
stroke: new ol.style.Stroke({
color: 'rgba(255, 204, 0, 0.2)',
width: 0
})
})
})];
styleCache[radius] = style;
}
return style;
}
// var roadstyle =
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'examples/data/kml/2012_Earthquakes_Mag5.kml',
format: new ol.format.KML({
extractStyles:false
}),
wrapX:false
}),
style:styleFunction,
title:"earthquake",
name:'11'
});
// test layer.Image and layer.Vector
var shroad = new ol.layer.Vector({
source: new ol.source.Vector({
url:'shroad.json',
format: new ol.format.EsriJSON({
})
}),
visible: false,
title: "shanghai_road",
style: new ol.style.Style({
fill: new ol.style.Fill(
{
color: '#aa10'
}),
stroke : new ol.style.Stroke({
color: 'rgba(218,185,249,0.70)',
width: 3
})
})
});
//$.ajax({"url":"12.ashx","success":function(data){ ol.Geometry();ol.Feature(ol.Geometry);ol.source.addFeature(*) }})
var extent = [120.78489, 30.68767, 121.95649, 31.58687];
// var projection = new ol.proj.Projection({
// code: 'xkcd-image',
// units: 'pixels',
// extent: extent
// });
var sh_img = new ol.layer.Image({
source: new ol.source.ImageStatic({
// attributions: [
// new ol.Attribution({
// })
// ],
// url: 'http://imgs.xkcd.com/comics/online_communities.png',
url:'GMap at zoom 12.png',
projection: ol.proj.get("EPSG:3857"),
imageExtent: ol.proj.transformExtent(extent,"EPSG:4326","EPSG:3857")
}),
title:"上海遥感影像"
});
// // this example uses d3 for which we don't have an externs file.
// // Histgram has 10 bins.
// var minVgi = 0;
// var maxVgi = 0.25;
// var bins = 10;
// function vgi(pixel) {
// var r = pixel[0] / 255;
// var g = pixel[1] / 255;
// var b = pixel[2] / 255;
// return (2 * g - r - b) / (2 * g + r + b);
// }
// /**
// * Summarize values for a histogram.
// * @param {numver} value A VGI value.
// * @param {Object} counts An object for keeping track of VGI counts.
// */
// function summarize(value, counts) {
// var min = counts.min;
// var max = counts.max;
// var num = counts.values.length;
// if (value < min) {
// // do nothing
// } else if (value >= max) {
// counts.values[num - 1] += 1;
// } else {
// var index = Math.floor((value - min) / counts.delta);
// counts.values[index] += 1;
// }
// }
// var imgsource = sh_img.getSource();
// // create a raster source
// var raster = new ol.source.Raster({
// source: [imgsource],
// /**
// * Run calculations on pixel data.
// * @param {Array} pixels :List of pixels (one per source).
// * @param {Object} data :User data object.
// * @return {Array} The output pixel.
// */
// operation: function(pixels,data){
// var pixel = pixels[0];
// var value = vgi(pixel);
// summarize(value, data.counts);
// if(value >= data.threshold) {
// pixel[0] = 0;
// pixel[1] = 255;
// pixel[2] = 0;
// pixel[3] = 128;
// } else {
// pixel[3] = 0;
// }
// return pixel;
// },
// lib:{
// vgi:vgi,
// summarize:summarize
// }
// });
// raster.set('threshold', 0.1);
// function createCounts(min, max, num) {
// var values = new Array(num);
// for (var i = 0; i < num; ++i) {
// values[i] = 0;
// }
// return {
// min: min,
// max: max,
// values: values,
// delta: (max - min) / num
// };
// }
// raster.on('beforeoperations', function(event) {
// event.data.counts = createCounts(minVgi, maxVgi, bins);
// event.data.threshold = raster.get('threshold');
// });
// raster.on('afteroperations', function(event) {
// schedulePlot(event.resolution, event.data.counts, event.data.threshold);
// });
// var map = new ol.Map({
// layers: [
// new ol.layer.Tile({
// source: bing
// }),
// new ol.layer.Image({
// source: raster
// })
// ],
// target: 'map',
// view: new ol.View({
// center: [-9651695, 4937351],
// zoom: 13,
// minZoom: 12,
// maxZoom: 19
// })
// });
// var timer = null;
// function schedulePlot(resolution, counts, threshold) {
// if (timer) {
// clearTimeout(timer);
// timer = null;
// }
// timer = setTimeout(plot.bind(null, resolution, counts, threshold), 1000 / 60);
// }
// var barWidth = 15;
// var plotHeight = 150;
// var chart = d3.select('#plot').append('svg')
// .attr('width', barWidth * bins)
// .attr('height', plotHeight);
// var chartRect = chart[0][0].getBoundingClientRect();
// var tip = d3.select(document.body).append('div')
// .attr('class', 'tip');
// function plot(resolution, counts, threshold) {
// var yScale = d3.scale.linear()
// .domain([0, d3.max(counts.values)])
// .range([0, plotHeight]);
// var bar = chart.selectAll('rect').data(counts.values);
// bar.enter().append('rect');
// bar.attr('class', function(count, index) {
// var value = counts.min + (index * counts.delta);
// return 'bar' + (value >= threshold ? ' selected' : '');
// })
// .attr('width', barWidth - 2);
// bar.transition().attr('transform', function(value, index) {
// return 'translate(' + (index * barWidth) + ', ' +
// (plotHeight - yScale(value)) + ')';
// })
// .attr('height', yScale);
// bar.on('mousemove', function(count, index) {
// var threshold = counts.min + (index * counts.delta);
// if (raster.get('threshold') !== threshold) {
// raster.set('threshold', threshold);
// raster.changed();
// }
// });
// bar.on('mouseover', function(count, index) {
// var area = 0;
// for (var i = counts.values.length - 1; i >= index; --i) {
// area += resolution * resolution * counts.values[i];
// }
// tip.html(message(counts.min + (index * counts.delta), area));
// tip.style('display', 'block');
// tip.transition().style({
// left: (chartRect.left + (index * barWidth) + (barWidth / 2)) + 'px',
// top: (d3.event.y - 60) + 'px',
// opacity: 1
// });
// });
// bar.on('mouseout', function() {
// tip.transition().style('opacity', 0).each('end', function() {
// tip.style('display', 'none');
// });
// });
// }
// function message(value, area) {
// var acres = (area / 4046.86).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
// return acres + ' acres at<br>' + value.toFixed(2) + ' VGI or above';
// }