第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

從 ajax 請求發(fā)出 mapbox geojson 數(shù)據(jù)

從 ajax 請求發(fā)出 mapbox geojson 數(shù)據(jù)

PHP
哈士奇WWW 2023-04-02 10:43:32
我有一張用 mapbox 創(chuàng)建的世界地圖。在那張地圖上,我想顯示我跑步/騎行/遠(yuǎn)足的路線。這些路線(折線)的數(shù)據(jù)存儲在數(shù)據(jù)庫中。根據(jù)用戶選擇的活動(dòng)(跑步、騎行、遠(yuǎn)足......),我調(diào)用一個(gè) ajax 請求(php 文件)來為地圖提供所需的路線。地圖顯示正確,但地圖上沒有顯示路線。php 文件返回正確的 json 數(shù)據(jù)(使用 JSONLint 測試)。現(xiàn)在,如果我復(fù)制我的 php 文件返回的數(shù)據(jù)并在我創(chuàng)建地圖的 javascript 中手動(dòng)復(fù)制它,而不是使用我的 ajax 請求,那么所有路線都會正確顯示。我無法弄清楚我的 ajax 請求/php 文件有什么問題。這是我的javascript:mapboxgl.accessToken = '...';var map = new mapboxgl.Map({    container: 'map',    style: 'mapbox://styles/dudanesk/ck9yhkakw2f3a1imzd1qpbs6a',    center: [0, 20],    zoom: 1.25,});// Add zoom and rotation controls to the map.map.addControl(new mapboxgl.NavigationControl());const queryString = window.location.search;const urlParams = new URLSearchParams(queryString);const athleteID = urlParams.get('athleteID');$.ajax({    url: "test.php",    type: "POST",    proccessData: false,    dataType: "JSON",    success: function (json) {        map.on('load', function(){            // Add a new source from our GeoJSON data             map.addSource('route', {                type: 'geojson',            data: json            });            // Create layer from source            map.addLayer({                'id': 'route',                'type': 'line',                'source': 'route',                'layout': {                    'line-join': 'round',                    'line-cap': 'round'                },                'paint': {                    'line-color': 'red',                    'line-width': 2                }            });        });    },    error: function(xhr, status, error){        var errorMessage = xhr.status + ': ' + xhr.statusText        alert('Error - ' + errorMessage);    },});誰能看出為什么路線不會出現(xiàn)在我的地圖上?我沒有任何錯(cuò)誤信息。感謝您的時(shí)間和幫助
查看完整描述

1 回答

?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

好的,我想我得到了修復(fù)。如果我在開始 ajax 查詢之前移動(dòng)map.on('load', function(){,而不是將它放在我的 ajax 成功函數(shù)中,那么我的代碼似乎可以正常工作:


map.on('load', function(){

    $.ajax({

        url: "test.php",

        type: "POST",

        proccessData: false,

        dataType: "JSON",

        success: function (json) {

            //alert(JSON.stringify(json));

            // Add a new source from our GeoJSON data 

            map.addSource('route', {

                type: 'geojson',

                data: json

            });


            // Create layer from source

            map.addLayer({

                'id': 'route',

                'type': 'line',

                'source': 'route',

                'layout': {

                    'line-join': 'round',

                    'line-cap': 'round'

                },

                'paint': {

                    'line-color': 'red',

                    'line-width': 2

                }

            });

        },

        error: function(xhr, status, error){

            var errorMessage = xhr.status + ': ' + xhr.statusText

            alert('Error - ' + errorMessage);

        },

    });

});



查看完整回答
反對 回復(fù) 2023-04-02
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號