teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

ソースコード、エラー文の記述を致しました

2020/09/30 10:12

投稿

okiron9619
okiron9619

スコア5

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,10 @@
8
8
  どのようにすればいいか教えていただきたいです。
9
9
  L.Circleでは、mで指定できるようです、、、
10
10
 
11
+ Lhankor_Mhy様に回答を頂いた後、該当ソースコードを変更→その後発生したエラー
12
+ Error: Invalid LatLng object: (35.0155833957335, NaN)
11
13
  ### 該当のソースコード
14
+ Lhankor_Mhy様に回答していただき、ソースコードを調整いたしました。
12
15
  ```views_models.py(geojsonを形成しているpythonファイル)
13
16
  from math import cos, sqrt
14
17
  import numpy as np
@@ -26,24 +29,28 @@
26
29
  #戻り地はm
27
30
  return 111.138 * sqrt(x*x + y*y) * 1000
28
31
  return {
32
+ "type": "FeatureCollection",
33
+ "features": [
34
+ {
29
- 'type': 'Feature',
35
+ "type": "Feature",
30
- 'properties': {
36
+ "properties": {
31
- 'node': {
37
+ 'node': {
32
- 'node_id': node1.node_id,
38
+ 'node_id': node1.node_id,
39
+ },
40
+ 'popupContent': 'これは'+ str(node1.node_id) + '番目です。',
41
+ "distance": qick_distance(node1.latlng.x,node1.latlng.y,node2.latlng.x,node2.latlng.y),
42
+ },
43
+ "geometry": {
44
+ "type": "Point",
45
+ "coordinates": [node1.latlng.x,node1.latlng.y],
46
+ },
33
47
  },
34
- 'popupContent': 'これは'+ str(node1.node_id) + '番目です。',
35
- 'distance':qick_distance(node1.latlng.x,node1.latlng.y,node2.latlng.x,node2.latlng.y),
36
- },
37
- 'geometry': {
38
- 'type': 'Point',
39
- 'coordinates': [node1.latlng.x,node1.latlng.y],
40
- },
41
- }
48
+ ]}
42
49
  ```
43
50
  ```canvas.jsの一部
44
51
  V.showNodesLayer = function(geojson) {
45
52
  var Marker = function(feature, latlng) {
46
- return new L.CircleMarker(latlng, {
53
+ return new L.Circle(latlng, {
47
54
  radius: 3,
48
55
  color: "#00ff00",
49
56
  fillColor: '#00ff00',

1

ソースコードについて、変更いたしました。

2020/09/30 10:11

投稿

okiron9619
okiron9619

スコア5

title CHANGED
File without changes
body CHANGED
@@ -9,8 +9,39 @@
9
9
  L.Circleでは、mで指定できるようです、、、
10
10
 
11
11
  ### 該当のソースコード
12
-
12
+ ```views_models.py(geojsonを形成しているpythonファイル)
13
+ from math import cos, sqrt
14
+ import numpy as np
15
+ class NodeLatlngMapper:
16
+ """ノードマッパー"""
17
+ def as_dict(self, node1, node2):
18
+ def qick_distance(Lat1, Long1, Lat2, Long2):
19
+ #degreeからradianへ
20
+ Lat1 = np.deg2rad(Lat1)
21
+ Lat2 = np.deg2rad(Lat2)
22
+ Long1 = np.deg2rad(Long1)
23
+ Long2 = np.deg2rad(Long2)
24
+ x = Lat2 - Lat1
25
+ y = (Long2 - Long1) * cos((Lat2 + Lat1)*0.00872664626)
26
+ #戻り地はm
27
+ return 111.138 * sqrt(x*x + y*y) * 1000
28
+ return {
29
+ 'type': 'Feature',
30
+ 'properties': {
31
+ 'node': {
32
+ 'node_id': node1.node_id,
33
+ },
34
+ 'popupContent': 'これは'+ str(node1.node_id) + '番目です。',
35
+ 'distance':qick_distance(node1.latlng.x,node1.latlng.y,node2.latlng.x,node2.latlng.y),
36
+ },
37
+ 'geometry': {
38
+ 'type': 'Point',
39
+ 'coordinates': [node1.latlng.x,node1.latlng.y],
40
+ },
41
+ }
42
+ ```
13
- ```対象javasciptファイルの一部
43
+ ```canvas.jsの一部
44
+ V.showNodesLayer = function(geojson) {
14
45
  var Marker = function(feature, latlng) {
15
46
  return new L.CircleMarker(latlng, {
16
47
  radius: 3,
@@ -19,6 +50,16 @@
19
50
  fillOpacity: 0.2,
20
51
  })
21
52
  };
53
+ L.geoJson(geojson, {pointToLayer: Marker},).addTo(map).on( 'click', function(e) { clickEvt(e); });
54
+ function onEachFeature(feature, layer) {
55
+ if (feature.properties && feature.properties.popupContent) {
56
+ layer.bindPopup(feature.properties.popupContent);
57
+ }
58
+ }
59
+ function clickEvt(e){
60
+ alert('HelloWorld');
61
+ }
62
+ }
22
63
  ```
23
64
 
24
65
  ### 試したこと