回答編集履歴

1

修正

2019/04/09 08:12

投稿

annderber
annderber

スコア98

test CHANGED
@@ -1,4 +1,4 @@
1
- コード量が長くなるので、こちらに記述いたしま
1
+ 再度修正しました
2
2
 
3
3
 
4
4
 
@@ -38,285 +38,51 @@
38
38
 
39
39
  <div id="map" style="width: 600px;height: 500px"></div>
40
40
 
41
+
42
+
41
43
  <script>
42
44
 
43
- var tiles = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
45
+ var tiles = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
44
46
 
45
- maxZoom: 14,
47
+ maxZoom: 14,
46
48
 
47
- attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
49
+ attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
48
50
 
49
- });
51
+ });
50
52
 
51
53
 
52
54
 
53
- var map = L.map('map')
55
+ var map = L.map('map')
54
56
 
55
- .addLayer(tiles);
57
+ .addLayer(tiles);
56
58
 
57
59
 
58
60
 
59
- var markers = L.markerClusterGroup({
61
+ var markers = L.markerClusterGroup({
60
62
 
61
- showCoverageOnHover: true,
63
+ showCoverageOnHover: true,
62
64
 
63
- spiderfyOnMaxZoom: false,
65
+ spiderfyOnMaxZoom: false,
64
66
 
65
- removeOutsideVisibleBounds: true,
67
+ removeOutsideVisibleBounds: true,
66
68
 
67
- disableClusteringAtZoom: 8
69
+ disableClusteringAtZoom: 8
68
70
 
69
- }
71
+ }
70
72
 
71
- );
73
+ );
72
-
73
- const data = {
74
-
75
- "type": "FeatureCollection",
76
-
77
- "features": [
78
-
79
- {
80
-
81
- "type": "Feature",
82
-
83
- "properties": {
84
-
85
- "marker-color": "#7e7e7e",
86
-
87
- "marker-size": "medium",
88
-
89
- "marker-symbol": "",
90
-
91
- "popup": "あああああああ"
92
-
93
- },
94
-
95
- "geometry": {
96
-
97
- "type": "Point",
98
-
99
- "coordinates": [
100
-
101
- 138.78552,
102
-
103
- 37.663027
104
-
105
- ]
106
-
107
- }
108
-
109
- },
110
-
111
- {
112
-
113
- "type": "Feature",
114
-
115
- "properties": {},
116
-
117
- "geometry": {
118
-
119
- "type": "Point",
120
-
121
- "coordinates": [
122
-
123
- 138.802069,
124
-
125
- 37.653211
126
-
127
- ]
128
-
129
- }
130
-
131
- },
132
-
133
- {
134
-
135
- "type": "Feature",
136
-
137
- "properties": {},
138
-
139
- "geometry": {
140
-
141
- "type": "Point",
142
-
143
- "coordinates": [
144
-
145
- 138.819922,
146
-
147
- 37.64502
148
-
149
- ]
150
-
151
- }
152
-
153
- },
154
-
155
- {
156
-
157
- "type": "Feature",
158
-
159
- "properties": {},
160
-
161
- "geometry": {
162
-
163
- "type": "Point",
164
-
165
- "coordinates": [
166
-
167
- 138.826511,
168
-
169
- 37.636968
170
-
171
- ]
172
-
173
- }
174
-
175
- },
176
-
177
- {
178
-
179
- "type": "Feature",
180
-
181
- "properties": {},
182
-
183
- "geometry": {
184
-
185
- "type": "Point",
186
-
187
- "coordinates": [
188
-
189
- 138.826649,
190
-
191
- 37.626823
192
-
193
- ]
194
-
195
- }
196
-
197
- },
198
-
199
- {
200
-
201
- "type": "Feature",
202
-
203
- "properties": {},
204
-
205
- "geometry": {
206
-
207
- "type": "Point",
208
-
209
- "coordinates": [
210
-
211
- 138.834801,
212
-
213
- 37.626811
214
-
215
- ]
216
-
217
- }
218
-
219
- },
220
-
221
- {
222
-
223
- "type": "Feature",
224
-
225
- "properties": {},
226
-
227
- "geometry": {
228
-
229
- "type": "Point",
230
-
231
- "coordinates": [
232
-
233
- 138.83981,
234
-
235
- 37.61816
236
-
237
- ]
238
-
239
- }
240
-
241
- },
242
-
243
- {
244
-
245
- "type": "Feature",
246
-
247
- "properties": {},
248
-
249
- "geometry": {
250
-
251
- "type": "Point",
252
-
253
- "coordinates": [
254
-
255
- 138.832363,
256
-
257
- 37.6159
258
-
259
- ]
260
-
261
- }
262
-
263
- },
264
-
265
- {
266
-
267
- "type": "Feature",
268
-
269
- "properties": {
270
-
271
- "stroke": "#d10004",
272
-
273
- "stroke-width": 10,
274
-
275
- "stroke-opacity": 1
276
-
277
- },
278
-
279
- "geometry": {
280
-
281
- "type": "LineString",
282
-
283
- "coordinates": [
284
-
285
- [
286
-
287
- 138.77723693847656,
288
-
289
- 37.66670097960347
290
-
291
- ],
292
-
293
- [
294
-
295
- 138.78976821899414,
296
-
297
- 37.662488471331706
298
-
299
- ]
300
-
301
- ]
302
-
303
- }
304
-
305
- }
306
-
307
- ]
308
-
309
- };
310
-
311
- // httpObj = new XMLHttpRequest();
312
-
313
- // httpObj.open("get", "hoge.geojson", function(data){
314
-
315
- // GeoJSON.parse(data);
316
74
 
317
75
 
318
76
 
77
+ httpObj = new XMLHttpRequest();
78
+
79
+ httpObj.open("GET", "hoge.json", true);
80
+
81
+ httpObj.addEventListener('load', function(res){
82
+
83
+ const data = JSON.parse(res.currentTarget.response);
84
+
319
- var geoJsonLayer = L.geoJson(data, {
85
+ var geoJsonLayer = L.geoJson(data, {
320
86
 
321
87
  onEachFeature: function (feature, layer) {
322
88
 
@@ -372,11 +138,11 @@
372
138
 
373
139
 
374
140
 
375
- // httpObj.send(null);
376
-
377
- // });
141
+ });
378
142
 
379
143
 
144
+
145
+ httpObj.send(null)
380
146
 
381
147
  </script>
382
148
 
@@ -388,10 +154,4 @@
388
154
 
389
155
 
390
156
 
391
-
392
-
393
- 投稿者様のスクリプトにjsonデータをそのままコピペして、XMLHttpRequestの部分をコメントアウトしています
157
+ XMLHttpRequestを行った場合で処理で編集直しました。ファイルのパスは変更しください。
394
-
395
- 恐らくこのままコピペすれば表示されると思います。
396
-
397
- なので、取得の部分で躓いているのでは無いかと思いますがいかがでしょうか