「Widget:Custom map」の版間の差分
提供:メタファー リファンタジオ 攻略Wiki
ヘイグ運営用アカウント (トーク | 投稿記録) 編集の要約なし |
ヘイグ運営用アカウント (トーク | 投稿記録) 編集の要約なし |
||
25行目: | 25行目: | ||
// APIベースURLを定数として定義 | // APIベースURLを定数として定義 | ||
const API_BASE_URL = 'https://prd-h1g-elb-2067013247.ap-northeast-1.elb.amazonaws.com/metaphor_refantazio'; | const API_BASE_URL = 'https://prd-h1g-elb-2067013247.ap-northeast-1.elb.amazonaws.com/metaphor_refantazio'; | ||
/////////////// | |||
// loadPinsFromWikiPageのデバッグ用拡張関数 | |||
window.debugLoadPins = function() { | |||
console.group('=== LoadPinsFromWikiPage Debug ==='); | |||
// 1. 初期状態の確認 | |||
console.log('1. Initial State Check:'); | |||
console.log('Current drawnItems layer count:', drawnItems.getLayers().length); | |||
console.log('GeoJSON page name:', "<!--{$geojson}-->"); | |||
console.log('API Base URL:', API_BASE_URL); | |||
// 2. トークン取得プロセスのデバッグ | |||
console.log('\n2. Starting Token Request...'); | |||
getMwToken() | |||
.then(function(token) { | |||
console.log('✅ Token received:', token ? '【トークン文字列は安全のため非表示】' : 'No token received'); | |||
// 3. APIリクエストの詳細をログ | |||
const geojsonPage = "<!--{$geojson}-->"; | |||
const url = API_BASE_URL + '/api.php'; | |||
const params = { | |||
action: 'query', | |||
titles: geojsonPage, | |||
prop: 'revisions', | |||
rvprop: 'content', | |||
format: 'json', | |||
redirects: 0 | |||
}; | |||
console.log('\n3. Making API Request:'); | |||
console.log('URL:', url); | |||
console.log('Parameters:', params); | |||
return $.ajax({ | |||
type: "GET", | |||
url: url, | |||
data: params, | |||
headers: { | |||
'Authorization': 'Bearer ' + token | |||
} | |||
}); | |||
}) | |||
.then(function(response) { | |||
console.log('\n4. API Response Received:'); | |||
console.log('Raw response:', response); | |||
try { | |||
// レスポンスの構造を確認 | |||
if (!response.query) { | |||
throw new Error('No query in response'); | |||
} | |||
const pages = response.query.pages; | |||
const pageId = Object.keys(pages)[0]; | |||
console.log('\n5. Page Information:'); | |||
console.log('Page ID:', pageId); | |||
if (pageId === '-1') { | |||
console.error('❌ Error: Page does not exist'); | |||
return; | |||
} | |||
const page = pages[pageId]; | |||
console.log('Page exists:', !!page); | |||
console.log('Has revisions:', !!page.revisions); | |||
if (!page.revisions || !page.revisions[0]) { | |||
throw new Error('No revisions found'); | |||
} | |||
const content = page.revisions[0]['*']; | |||
console.log('\n6. Page Content:'); | |||
console.log('Content length:', content ? content.length : 0); | |||
console.log('Content preview:', content ? content.substring(0, 100) + '...' : 'No content'); | |||
try { | |||
const geoJSONData = JSON.parse(content); | |||
console.log('\n7. GeoJSON Validation:'); | |||
console.log('Valid JSON:', true); | |||
console.log('Type:', geoJSONData.type); | |||
console.log('Features count:', geoJSONData.features ? geoJSONData.features.length : 0); | |||
// 各フィーチャーの基本情報をログ | |||
if (geoJSONData.features) { | |||
console.log('\n8. Features Overview:'); | |||
geoJSONData.features.forEach((feature, index) => { | |||
console.log(`Feature ${index + 1}:`, { | |||
type: feature.type, | |||
geometryType: feature.geometry?.type, | |||
hasProperties: !!feature.properties, | |||
coordinates: feature.geometry?.coordinates | |||
}); | |||
}); | |||
} | |||
// processGeoJSONDataの呼び出しを監視 | |||
console.log('\n9. Processing GeoJSON...'); | |||
processGeoJSONData(geoJSONData); | |||
// 処理後の状態を確認 | |||
console.log('\n10. Final State:'); | |||
console.log('Drawn items after processing:', drawnItems.getLayers().length); | |||
} catch (jsonError) { | |||
console.error('❌ Error parsing GeoJSON:', jsonError); | |||
console.log('Raw content causing error:', content); | |||
} | |||
} catch (error) { | |||
console.error('❌ Error processing response:', error); | |||
console.error('Stack trace:', error.stack); | |||
} | |||
}) | |||
.catch(function(error) { | |||
console.error('\n❌ Process Failed:', { | |||
message: error.message, | |||
stack: error.stack, | |||
ajaxError: error.responseText | |||
}); | |||
}) | |||
.finally(function() { | |||
console.groupEnd(); | |||
}); | |||
}; | |||
// processGeoJSONDataのデバッグ拡張 | |||
const originalProcessGeoJSONData = processGeoJSONData; | |||
processGeoJSONData = function(geoJSON) { | |||
console.group('ProcessGeoJSONData Debug'); | |||
try { | |||
console.log('Starting to process GeoJSON data'); | |||
console.log('Input features count:', geoJSON.features.length); | |||
const previousLayers = drawnItems.getLayers().length; | |||
drawnItems.clearLayers(); | |||
console.log('Cleared previous layers:', previousLayers); | |||
const addedLayers = []; | |||
// オリジナルの処理を実行 | |||
originalProcessGeoJSONData(geoJSON); | |||
console.log('Processing complete'); | |||
console.log('New layers added:', drawnItems.getLayers().length); | |||
// 追加されたレイヤーの検証 | |||
drawnItems.eachLayer(layer => { | |||
console.log('Layer details:', { | |||
type: layer instanceof L.Marker ? 'Marker' : 'Other', | |||
hasPopup: !!layer.getPopup(), | |||
position: layer.getLatLng ? layer.getLatLng() : 'N/A', | |||
popupContent: layer.getPopup ? layer.getPopup()?.getContent() : 'N/A' | |||
}); | |||
}); | |||
} catch (error) { | |||
console.error('Error in processGeoJSONData:', error); | |||
console.error('Stack trace:', error.stack); | |||
} finally { | |||
console.groupEnd(); | |||
} | |||
}; | |||
// ヘルプ機能 | |||
window.showLoadPinsHelp = function() { | |||
console.log(` | |||
LoadPinsFromWikiPage Debugging Help: | |||
--------------------------------- | |||
1. Run 'debugLoadPins()' to start debugging | |||
2. Check the console for detailed step-by-step information | |||
3. Look for any red error messages | |||
4. Verify that: | |||
- Token is received | |||
- API request is successful | |||
- Page exists and has content | |||
- GeoJSON is valid | |||
- Features are processed correctly | |||
- Markers are added to the map | |||
Common Issues: | |||
------------ | |||
1. Page doesn't exist | |||
2. Invalid GeoJSON format | |||
3. Missing or incorrect coordinates | |||
4. Token authentication issues | |||
5. Marker creation failures | |||
Additional Commands: | |||
----------------- | |||
- showLoadPinsHelp(): Show this help message | |||
`); | |||
}; | |||
console.log('Debug tools loaded. Type debugLoadPins() to start debugging or showLoadPinsHelp() for instructions.'); | |||
////////// | |||
window.savePopupContent = savePopupContent; | window.savePopupContent = savePopupContent; |