質問編集履歴

4

現在のマップ状態を添付

2019/04/08 11:08

投稿

southern_flavor
southern_flavor

スコア70

test CHANGED
File without changes
test CHANGED
@@ -440,6 +440,10 @@
440
440
 
441
441
  詳細にお伝えすると以下のようなhtmlしか読み込まれていないです。
442
442
 
443
+
444
+
445
+ ![現在のマップ状態](7b81032f0fe239d0bd9fa1377e23968e.png)
446
+
443
447
  ```
444
448
 
445
449
  <div id="map" style="width: 600px; height: 500px; position: relative;" class="leaflet-container leaflet-touch leaflet-fade-anim leaflet-grab leaflet-touch-drag leaflet-touch-zoom" tabindex="0"><div class="leaflet-pane leaflet-map-pane" style="transform: translate3d(0px, 0px, 0px);"><div class="leaflet-pane leaflet-tile-pane"></div><div class="leaflet-pane leaflet-shadow-pane"></div><div class="leaflet-pane leaflet-overlay-pane"></div><div class="leaflet-pane leaflet-marker-pane"></div><div class="leaflet-pane leaflet-tooltip-pane"></div><div class="leaflet-pane leaflet-popup-pane"></div><div class="leaflet-proxy leaflet-zoom-animated"></div></div><div class="leaflet-control-container"><div class="leaflet-top leaflet-left"><div class="leaflet-control-zoom leaflet-bar leaflet-control"><a class="leaflet-control-zoom-in" href="#" title="Zoom in" role="button" aria-label="Zoom in">+</a><a class="leaflet-control-zoom-out" href="#" title="Zoom out" role="button" aria-label="Zoom out">−</a></div></div><div class="leaflet-top leaflet-right"></div><div class="leaflet-bottom leaflet-left"></div><div class="leaflet-bottom leaflet-right"><div class="leaflet-control-attribution leaflet-control"><a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a></div></div></div></div>

3

エラーの詳細について

2019/04/08 11:07

投稿

southern_flavor
southern_flavor

スコア70

test CHANGED
File without changes
test CHANGED
@@ -427,3 +427,49 @@
427
427
  }
428
428
 
429
429
  ```
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+ ### 現在のエラー
438
+
439
+ マップはグレーアウトした状態で表示され、画像が読み込めていない状態です。
440
+
441
+ 詳細にお伝えすると以下のようなhtmlしか読み込まれていないです。
442
+
443
+ ```
444
+
445
+ <div id="map" style="width: 600px; height: 500px; position: relative;" class="leaflet-container leaflet-touch leaflet-fade-anim leaflet-grab leaflet-touch-drag leaflet-touch-zoom" tabindex="0"><div class="leaflet-pane leaflet-map-pane" style="transform: translate3d(0px, 0px, 0px);"><div class="leaflet-pane leaflet-tile-pane"></div><div class="leaflet-pane leaflet-shadow-pane"></div><div class="leaflet-pane leaflet-overlay-pane"></div><div class="leaflet-pane leaflet-marker-pane"></div><div class="leaflet-pane leaflet-tooltip-pane"></div><div class="leaflet-pane leaflet-popup-pane"></div><div class="leaflet-proxy leaflet-zoom-animated"></div></div><div class="leaflet-control-container"><div class="leaflet-top leaflet-left"><div class="leaflet-control-zoom leaflet-bar leaflet-control"><a class="leaflet-control-zoom-in" href="#" title="Zoom in" role="button" aria-label="Zoom in">+</a><a class="leaflet-control-zoom-out" href="#" title="Zoom out" role="button" aria-label="Zoom out">−</a></div></div><div class="leaflet-top leaflet-right"></div><div class="leaflet-bottom leaflet-left"></div><div class="leaflet-bottom leaflet-right"><div class="leaflet-control-attribution leaflet-control"><a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a></div></div></div></div>
446
+
447
+ ```
448
+
449
+
450
+
451
+ ズームマークをクリックすると以下のようなコンソールエラーがでます。
452
+
453
+ ```
454
+
455
+ leaflet.js:5 Uncaught Error: Set map center and zoom first.
456
+
457
+ at e._checkIfLoaded (leaflet.js:5)
458
+
459
+ at e.getCenter (leaflet.js:5)
460
+
461
+ at e.<anonymous> (leaflet.js:5)
462
+
463
+ at e.fire (leaflet.js:5)
464
+
465
+ at e._onPanTransitionEnd (leaflet.js:5)
466
+
467
+ at e.fire (leaflet.js:5)
468
+
469
+ at e._complete (leaflet.js:5)
470
+
471
+ at e._step (leaflet.js:5)
472
+
473
+ at e._animate (leaflet.js:5)
474
+
475
+ ```

2

外部読み込みされない問題について

2019/04/08 09:28

投稿

southern_flavor
southern_flavor

スコア70

test CHANGED
@@ -1 +1 @@
1
- Leaflet.jsにて外部GeoJSONの変数部分をとり、polyline(線)を表示せた
1
+ Leafletにてgeojsonが外部読み込みれな
test CHANGED
@@ -1,10 +1,158 @@
1
1
  ### やりたいこと
2
2
 
3
- 二つあります。
3
+
4
-
5
-
6
-
4
+
7
- 1.現状のソースコードに書いたGeoJSONファイルの「var geoJsonData =」部分取り除いて、外部から読み込めるようにしたいです
5
+ 現状のソースコードに書いたhoge.geojsonをjQueryなしで外部読み込みさせたいですが、
6
+
7
+ うまくいきません。
8
+
9
+ なにか解決策はご存知でしょうか?
10
+
11
+
12
+
13
+ ###現状のソースコード
14
+
15
+
16
+
17
+ ```HTML
18
+
19
+ <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
20
+
21
+ integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
22
+
23
+ crossorigin=""/>
24
+
25
+ <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
26
+
27
+ <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
28
+
29
+ <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
30
+
31
+ integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
32
+
33
+ crossorigin=""></script>
34
+
35
+ <script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
36
+
37
+
38
+
39
+ <div id="map" style="width: 600px;height: 500px"></div>
40
+
41
+ ```
42
+
43
+
44
+
45
+ ```JavaScript
46
+
47
+ <script>
48
+
49
+ var tiles = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
50
+
51
+ maxZoom: 14,
52
+
53
+ attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
54
+
55
+ });
56
+
57
+
58
+
59
+ var map = L.map('map')
60
+
61
+ .addLayer(tiles);
62
+
63
+
64
+
65
+ var markers = L.markerClusterGroup({
66
+
67
+ showCoverageOnHover: true,
68
+
69
+ spiderfyOnMaxZoom: false,
70
+
71
+ removeOutsideVisibleBounds: true,
72
+
73
+ disableClusteringAtZoom: 8
74
+
75
+ }
76
+
77
+ );
78
+
79
+
80
+
81
+ httpObj = new XMLHttpRequest();
82
+
83
+ httpObj.open("get", "hoge.geojson", function(data){
84
+
85
+ GeoJSON.parse(data);
86
+
87
+
88
+
89
+ var geoJsonLayer = L.geoJson(data, {
90
+
91
+ onEachFeature: function (feature, layer) {
92
+
93
+ layer.bindPopup(feature.properties.popup);
94
+
95
+ },
96
+
97
+ pointToLayer: function(feature, latlng) {
98
+
99
+ var iconChange = L.icon({
100
+
101
+ iconUrl: '<?php echo get_stylesheet_directory_uri(); ?>/'+ feature.properties.pcp +'.png',
102
+
103
+ iconRetinaUrl: '<?php echo get_stylesheet_directory_uri(); ?>/'+ feature.properties.pcp2x +'.png',
104
+
105
+ iconSize: [25, 41]
106
+
107
+ //iconAnchor: [12.5, -20],
108
+
109
+ //popupAnchor: [0, 20],
110
+
111
+ });
112
+
113
+ return L.marker(latlng, {icon: iconChange});
114
+
115
+ return L.polyline(latlng);
116
+
117
+ },
118
+
119
+ style: function (feature) {
120
+
121
+ return {
122
+
123
+ color: feature.properties['stroke'],
124
+
125
+ weight: feature.properties['stroke-width'],
126
+
127
+ opacity: feature.properties['stroke-opacity']
128
+
129
+ };
130
+
131
+ }
132
+
133
+ });
134
+
135
+ markers.addLayer(geoJsonLayer);
136
+
137
+ map.addLayer(markers);
138
+
139
+ map.fitBounds(markers.getBounds());
140
+
141
+ map.setView([35.156, 136.890], 8);
142
+
143
+
144
+
145
+ httpObj.send(null);
146
+
147
+ });
148
+
149
+ </script>
150
+
151
+ ```
152
+
153
+
154
+
155
+
8
156
 
9
157
  ```geojson
10
158
 
@@ -24,416 +172,258 @@
24
172
 
25
173
  "marker-size": "medium",
26
174
 
175
+ "marker-symbol": "",
176
+
177
+ "popup": "<a href=\"hoge.jpg\" target=\"_blank\">あああ</a>"
178
+
179
+ },
180
+
27
- "marker-sy
181
+ "geometry": {
182
+
28
-
183
+ "type": "Point",
184
+
185
+ "coordinates": [
186
+
187
+ 138.787242,
188
+
189
+ 37.664411
190
+
191
+ ]
192
+
193
+ }
194
+
29
- ・・・
195
+ },
196
+
197
+ {
198
+
199
+ "type": "Feature",
200
+
201
+ "properties": {
202
+
203
+ "marker-color": "#7e7e7e",
204
+
205
+ "marker-size": "medium",
206
+
207
+ "marker-symbol": "",
208
+
209
+ "popup": "あああああああ"
210
+
211
+ },
212
+
213
+ "geometry": {
214
+
215
+ "type": "Point",
216
+
217
+ "coordinates": [
218
+
219
+ 138.78552,
220
+
221
+ 37.663027
222
+
223
+ ]
224
+
225
+ }
226
+
227
+ },
228
+
229
+ {
230
+
231
+ "type": "Feature",
232
+
233
+ "properties": {},
234
+
235
+ "geometry": {
236
+
237
+ "type": "Point",
238
+
239
+ "coordinates": [
240
+
241
+ 138.802069,
242
+
243
+ 37.653211
244
+
245
+ ]
246
+
247
+ }
248
+
249
+ },
250
+
251
+ {
252
+
253
+ "type": "Feature",
254
+
255
+ "properties": {},
256
+
257
+ "geometry": {
258
+
259
+ "type": "Point",
260
+
261
+ "coordinates": [
262
+
263
+ 138.819922,
264
+
265
+ 37.64502
266
+
267
+ ]
268
+
269
+ }
270
+
271
+ },
272
+
273
+ {
274
+
275
+ "type": "Feature",
276
+
277
+ "properties": {},
278
+
279
+ "geometry": {
280
+
281
+ "type": "Point",
282
+
283
+ "coordinates": [
284
+
285
+ 138.826511,
286
+
287
+ 37.636968
288
+
289
+ ]
290
+
291
+ }
292
+
293
+ },
294
+
295
+ {
296
+
297
+ "type": "Feature",
298
+
299
+ "properties": {},
300
+
301
+ "geometry": {
302
+
303
+ "type": "Point",
304
+
305
+ "coordinates": [
306
+
307
+ 138.826649,
308
+
309
+ 37.626823
310
+
311
+ ]
312
+
313
+ }
314
+
315
+ },
316
+
317
+ {
318
+
319
+ "type": "Feature",
320
+
321
+ "properties": {},
322
+
323
+ "geometry": {
324
+
325
+ "type": "Point",
326
+
327
+ "coordinates": [
328
+
329
+ 138.834801,
330
+
331
+ 37.626811
332
+
333
+ ]
334
+
335
+ }
336
+
337
+ },
338
+
339
+ {
340
+
341
+ "type": "Feature",
342
+
343
+ "properties": {},
344
+
345
+ "geometry": {
346
+
347
+ "type": "Point",
348
+
349
+ "coordinates": [
350
+
351
+ 138.83981,
352
+
353
+ 37.61816
354
+
355
+ ]
356
+
357
+ }
358
+
359
+ },
360
+
361
+ {
362
+
363
+ "type": "Feature",
364
+
365
+ "properties": {},
366
+
367
+ "geometry": {
368
+
369
+ "type": "Point",
370
+
371
+ "coordinates": [
372
+
373
+ 138.832363,
374
+
375
+ 37.6159
376
+
377
+ ]
378
+
379
+ }
380
+
381
+ },
382
+
383
+ {
384
+
385
+ "type": "Feature",
386
+
387
+ "properties": {
388
+
389
+ "stroke": "#d10004",
390
+
391
+ "stroke-width": 10,
392
+
393
+ "stroke-opacity": 1
394
+
395
+ },
396
+
397
+ "geometry": {
398
+
399
+ "type": "LineString",
400
+
401
+ "coordinates": [
402
+
403
+ [
404
+
405
+ 138.77723693847656,
406
+
407
+ 37.66670097960347
408
+
409
+ ],
410
+
411
+ [
412
+
413
+ 138.78976821899414,
414
+
415
+ 37.662488471331706
416
+
417
+ ]
418
+
419
+ ]
420
+
421
+ }
422
+
423
+ }
424
+
425
+ ]
426
+
427
+ }
30
428
 
31
429
  ```
32
-
33
- 上記のような状態で外部GeoJSONを読み込めるようにしたのですが、可能でしょうか?
34
-
35
-
36
-
37
- 2.polylineを表示させたいです。
38
-
39
-
40
-
41
- 現状のソースコードでは、1.の変数部分をとると外部から読み込めなくなります。
42
-
43
- JQueryの$.getJSON() も試してみたのですが、うまくいきませんでした。
44
-
45
-
46
-
47
- polylineについては、http://geojson.io/で作成したpolylineです。
48
-
49
- いろいろ試しましたが、表示されないです。
50
-
51
-
52
-
53
- #現在の仕様
54
-
55
- leaflet.jsにmarkercluster.jsも入れています。
56
-
57
- オリジナルのマーカーも設定し、問題なく表示されています。
58
-
59
- polylineが表示されないだけで、外部読み込みは成功しています(「var geojsondata」がついているため)。
60
-
61
-
62
-
63
- ###現状のソースコード
64
-
65
-
66
-
67
- ```HTML
68
-
69
- <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
70
-
71
- integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
72
-
73
- crossorigin=""/>
74
-
75
- <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
76
-
77
- <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
78
-
79
- <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
80
-
81
- integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
82
-
83
- crossorigin=""></script>
84
-
85
- <script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
86
-
87
-
88
-
89
- <script src="hoge.geojson"></script>
90
-
91
- <div id="map" style="width: 600px;height: 500px"></div>
92
-
93
- ```
94
-
95
-
96
-
97
- ```JavaScript
98
-
99
- <script>
100
-
101
- var iconChange = L.icon({
102
-
103
- iconUrl: 'fugaicon.png',
104
-
105
- iconSize: [25, 40],
106
-
107
- });
108
-
109
-
110
-
111
- var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
112
-
113
- maxZoom: 18,
114
-
115
- attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
116
-
117
- });
118
-
119
-
120
-
121
- var map = L.map('map')
122
-
123
- .addLayer(tiles);
124
-
125
-
126
-
127
- var markers = L.markerClusterGroup();
128
-
129
-
130
-
131
- var geoJsonLayer = L.geoJson(geoJsonData, {
132
-
133
- onEachFeature: function (feature, layer) {
134
-
135
- layer.polyline(geometry.LineString);
136
-
137
- layer.bindPopup(feature.properties.popup);
138
-
139
- layer.setIcon(iconChange);
140
-
141
- }
142
-
143
- });
144
-
145
- var polyline = L.polyline(geoJsonData).addTo(map);
146
-
147
- map.addLayer(polyline);
148
-
149
-
150
-
151
- markers.addLayer(geoJsonLayer);
152
-
153
- map.addLayer(markers);
154
-
155
- map.fitBounds(markers.getBounds());
156
-
157
- map.setView([35.156, 136.890], 8);
158
-
159
- </script>
160
-
161
- ```
162
-
163
-
164
-
165
-
166
-
167
- ```geojson
168
-
169
- var geoJsonData = {
170
-
171
- "type": "FeatureCollection",
172
-
173
- "features": [
174
-
175
- {
176
-
177
- "type": "Feature",
178
-
179
- "properties": {
180
-
181
- "marker-color": "#7e7e7e",
182
-
183
- "marker-size": "medium",
184
-
185
- "marker-symbol": "",
186
-
187
- "popup": "<a href=\"hoge.jpg\" target=\"_blank\">あああ</a>"
188
-
189
- },
190
-
191
- "geometry": {
192
-
193
- "type": "Point",
194
-
195
- "coordinates": [
196
-
197
- 138.787242,
198
-
199
- 37.664411
200
-
201
- ]
202
-
203
- }
204
-
205
- },
206
-
207
- {
208
-
209
- "type": "Feature",
210
-
211
- "properties": {
212
-
213
- "marker-color": "#7e7e7e",
214
-
215
- "marker-size": "medium",
216
-
217
- "marker-symbol": "",
218
-
219
- "popup": "あああああああ"
220
-
221
- },
222
-
223
- "geometry": {
224
-
225
- "type": "Point",
226
-
227
- "coordinates": [
228
-
229
- 138.78552,
230
-
231
- 37.663027
232
-
233
- ]
234
-
235
- }
236
-
237
- },
238
-
239
- {
240
-
241
- "type": "Feature",
242
-
243
- "properties": {},
244
-
245
- "geometry": {
246
-
247
- "type": "Point",
248
-
249
- "coordinates": [
250
-
251
- 138.802069,
252
-
253
- 37.653211
254
-
255
- ]
256
-
257
- }
258
-
259
- },
260
-
261
- {
262
-
263
- "type": "Feature",
264
-
265
- "properties": {},
266
-
267
- "geometry": {
268
-
269
- "type": "Point",
270
-
271
- "coordinates": [
272
-
273
- 138.819922,
274
-
275
- 37.64502
276
-
277
- ]
278
-
279
- }
280
-
281
- },
282
-
283
- {
284
-
285
- "type": "Feature",
286
-
287
- "properties": {},
288
-
289
- "geometry": {
290
-
291
- "type": "Point",
292
-
293
- "coordinates": [
294
-
295
- 138.826511,
296
-
297
- 37.636968
298
-
299
- ]
300
-
301
- }
302
-
303
- },
304
-
305
- {
306
-
307
- "type": "Feature",
308
-
309
- "properties": {},
310
-
311
- "geometry": {
312
-
313
- "type": "Point",
314
-
315
- "coordinates": [
316
-
317
- 138.826649,
318
-
319
- 37.626823
320
-
321
- ]
322
-
323
- }
324
-
325
- },
326
-
327
- {
328
-
329
- "type": "Feature",
330
-
331
- "properties": {},
332
-
333
- "geometry": {
334
-
335
- "type": "Point",
336
-
337
- "coordinates": [
338
-
339
- 138.834801,
340
-
341
- 37.626811
342
-
343
- ]
344
-
345
- }
346
-
347
- },
348
-
349
- {
350
-
351
- "type": "Feature",
352
-
353
- "properties": {},
354
-
355
- "geometry": {
356
-
357
- "type": "Point",
358
-
359
- "coordinates": [
360
-
361
- 138.83981,
362
-
363
- 37.61816
364
-
365
- ]
366
-
367
- }
368
-
369
- },
370
-
371
- {
372
-
373
- "type": "Feature",
374
-
375
- "properties": {},
376
-
377
- "geometry": {
378
-
379
- "type": "Point",
380
-
381
- "coordinates": [
382
-
383
- 138.832363,
384
-
385
- 37.6159
386
-
387
- ]
388
-
389
- }
390
-
391
- },
392
-
393
- {
394
-
395
- "type": "Feature",
396
-
397
- "properties": {
398
-
399
- "stroke": "#d10004",
400
-
401
- "stroke-width": 10,
402
-
403
- "stroke-opacity": 1
404
-
405
- },
406
-
407
- "geometry": {
408
-
409
- "type": "LineString",
410
-
411
- "coordinates": [
412
-
413
- [
414
-
415
- 138.77723693847656,
416
-
417
- 37.66670097960347
418
-
419
- ],
420
-
421
- [
422
-
423
- 138.78976821899414,
424
-
425
- 37.662488471331706
426
-
427
- ]
428
-
429
- ]
430
-
431
- }
432
-
433
- }
434
-
435
- ]
436
-
437
- }
438
-
439
- ```

1

タイトルにLeaflet.jsと記載

2019/04/08 06:57

投稿

southern_flavor
southern_flavor

スコア70

test CHANGED
@@ -1 +1 @@
1
- 外部GeoJSONの変数部分をとり、polylineを表示させたい
1
+ Leaflet.jsにて外部GeoJSONの変数部分をとり、polyline(線)を表示させたい
test CHANGED
File without changes