更新Google地图中的KML图层数据,而不生成新文件

时间:2013-11-22 13:24:52

标签: javascript json google-maps google-maps-api-3 kml

我正在使用Google Maps API开发地图,其中特定区域使用KML多边形进行勾画,并为其分配了某些(数字)值。这些区域(由ID提供)在KML文件中定义。对于每个区域,我想显示一个特定的金额,比如说,匹配特定查询过滤器的居民数量。

现在,问题是区域的多边形层可能是静态的 - 形状总是相同的。但是,我希望能够在收到新数据时动态更新其关联值,但目前这些值也在KML文件中设置。另一个问题是多边形填充颜色基于这些值,这些也在KML中定义。

目前,KML文件看起来像这样:

(...)
        <Placemark>
            <snippet></snippet>
            <description><![CDATA[<div class="googft-info-window">
<strong>Bedum</strong>: 62
</div>]]></description>
            <styleUrl>#Style2-polygon-1-map</styleUrl>
            <ExtendedData>
                <Data name='ID'>
                    <value>005</value>
                </Data>
                <Data name='REGION'>
                    <value>Bedum</value>
                </Data>
                <Data name='COUNT'>
                    <value>62</value>
                </Data>
            </ExtendedData><Polygon><outerBoundaryIs><LinearRing><coordinates>6.596591,53.348151 6.602419,53.341801 6.605422,53.341771 6.605371,53.339987 6.60532,53.338177 6.599265,53.336441 6.602115,53.33102 6.606643,53.331873 6.611121,53.330928 6.615495,53.32639 6.613943,53.324609 6.621189,53.315547 6.639193,53.315361 6.643511,53.309025 6.649538,53.309861 6.655538,53.309797 6.6305,53.27411 6.630323,53.273809 6.627348,53.26875 6.627296,53.266953 6.634608,53.260586 6.63595,53.25518 6.635872,53.252484 6.619341,53.250857 6.617894,53.25267 6.607407,53.252777 6.607412,53.252929 6.607458,53.254574 6.591365,53.256497 6.590857,53.258046 6.590566,53.258041 6.589825,53.258051 6.589813,53.258054 6.588051,53.25665 6.588296,53.257685 6.58973,53.26374 6.588933,53.263511 6.586707,53.262871 6.567202,53.262166 6.567276,53.264861 6.552241,53.26321 6.550815,53.26592 6.552312,53.270814 6.552459,53.271297 6.555579,53.27576 6.557394,53.28887 6.557443,53.289223 6.561151,53.31525 6.561241,53.315403 6.564299,53.320611 6.564414,53.320969 6.569219,53.335841 6.567742,53.336754 6.56789,53.342145 6.567969,53.342364 6.569515,53.346623 6.57557,53.34836 6.577071,53.348346 6.582923,53.344726 6.582978,53.344692 6.588958,53.343734 6.596591,53.348151</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark>
(...)

我的问题是:如何更新区域值及其相关颜色,而不必生成整个KML文件服务器端?理想情况下,我只需要加载KML文件一次,只是为了勾勒出区域。 我正在寻找像这样的解决方案:

  1. KML文件在页面加载时加载一次,仅包含多边形坐标和区域ID
  2. 与区域关联的值通过AJAX回调(即JSON格式)加载并分配给区域
  3. 多边形填充颜色会根据指定的值(例如从浅红色到深红色)自行更新
  4. 当用户点击某个区域时,会弹出一个包含区域ID和关联值的气球
  5. 这可能吗?如果我需要更具体,请告诉我。

0 个答案:

没有答案