在这里渲染地图2.5.3时,标记突然丢失

时间:2014-03-23 15:24:11

标签: javascript jquery maps here-api

我开发了一个应用程序,它在navteq地图上显示市场集合。当我使用navteq maps 2.2.3时,一切正常,但Navteq maps 2.2.3不支持Asynchronous behaviour我已切换到支持HereMaps 2.5.3行为的Asynchronous

现在切换到最新版本后,我面临一个奇怪的问题。这是在地图上渲染标记时突然已经渲染的点/标记(某些点)消失了。这个问题有时会发生,如果再次尝试在地图上生成市场,它可以正常工作。

所以我认为我需要在渲染之前正确处理一些Display事件。

示例图片如下:

图片1:正确呈现标记

Properly Rendered Markers

图片2:已呈现但缺少某些内容

enter image description here

MyCode如下:

以下功能负责在地图上显示标记。

function displayAllPoints(arrLightPointCoordinats, totalLightPoints, selectedSegmentId,
                                        totalSegmentsCount, segmentColorcode) 
{
    var MyTheme1 = function () {
    };
    segmentColorcode = segmentColorcode.substring(2, segmentColorcode.length - 1);
    MyTheme1.prototype.getNoisePresentation = function (dataPoint) {
        var markerLightPoint = new nokia.maps.map.Marker(dataPoint, {
            icon: new nokia.maps.gfx.BitmapImage("..//Images//Lightpoint//" + segmentColorcode + ".png"),
            anchor: {
                x: 12,
                y: 12
            }
        });
        return markerLightPoint;
    };
    MyTheme1.prototype.getClusterPresentation = function (data) {
        var markerLightPoint = new nokia.maps.map.StandardMarker(data.getBounds().getCenter(), {
            icon: new nokia.maps.gfx.BitmapImage("..//Images//SegmentController/" + 
                                    segmentColorcode + ".png", null, 66, 65),
            text: data.getSize(),
            zIndex: 2,
            anchor: {
                x: 12,
                y: 12
            }
        });
        return markerLightPoint;
    };
    var indexes = new nokia.maps.clustering.Index();
    var lightpointsDataSet1 = new Array();

    for (var i = 0; i < totalLightPoints; i++) {
        lightpointsDataSet1[i] = { latitude: arrLightPointCoordinats[i][0],
        longitude: arrLightPointCoordinats[i][1], title: 'LightPoint ' + (i + 1) };
        indexes.add([arrLightPointCoordinats[i][0], arrLightPointCoordinats[i][1]]);
    }
    var ClusterProvider = nokia.maps.clustering.ClusterProvider,
        theme = new MyTheme1(),
        clusterProvider = new ClusterProvider(map, {
            eps: 0.00000000001,
            minPts: 1000000,
            strategy: nokia.maps.clustering.ClusterProvider.STRATEGY_DENSITY_BASED,
            index: indexes,
            theme: theme,
            dataPoints: []
        });
    clusterProvider.addAll(lightpointsDataSet1);
    clusterProvider.cluster();
    map.update(-1, 0);
    //set zoom level here

    setCenterAndZoom(13, arrSegmentControllerIds[0]);
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

在开始群集之前,我使用了Display Ready事件:

        map.addListener("displayready", function()
        {
            mapContainer.style.display = 'block';

            // load the photos as cluster data
            url = "http://developer.here.com/apiexplorer/examples/res/clustering/photos.js";
            script = document.createElement("script");
            script.src = url;
            document.body.appendChild(script);
        });

        onDataReceive = function(data)
        {
            displayAllPoints(data);
        }

        function displayAllPoints(arrLightPointCoordinates) 
        {           {
            var MyTheme1 = function (){};
            MyTheme1.prototype.getNoisePresentation = function (dataPoint) {
                var markerLightPoint = new nokia.maps.map.Marker(dataPoint, {
                    icon: new nokia.maps.gfx.BitmapImage("/res/marker_red.png"),
                    anchor: {
                        x: 12,
                        y: 12
                    }
                });
                return markerLightPoint;
            };

            MyTheme1.prototype.getClusterPresentation = function (data) {
                var markerLightPoint = new nokia.maps.map.StandardMarker(data.getBounds().getCenter(), {
                    icon: new nokia.maps.gfx.BitmapImage("/res/marker_green.png", null, 66, 65),
                    text: data.getSize(),
                    zIndex: 2,
                    anchor: {
                        x: 12,
                        y: 12
                    }
                });
                return markerLightPoint;
            };
/*              
            var indexes = new nokia.maps.clustering.Index();
            var lightpointsDataSet1 = new Array();

            for (var i = 0; i < totalLightPoints; i++) {
                lightpointsDataSet1[i] = { latitude: arrLightPointCoordinats[i][0],
                longitude: arrLightPointCoordinats[i][1], title: 'LightPoint ' + (i + 1) };
                indexes.add([arrLightPointCoordinats[i][0], arrLightPointCoordinats[i][1]]);
            }
*/
            var ClusterProvider = nokia.maps.clustering.ClusterProvider,
                theme = new MyTheme1(),
                clusterProvider = new ClusterProvider(map, {
                    eps: 0.00000000001,
                    minPts: 1000000,
                    strategy: nokia.maps.clustering.ClusterProvider.STRATEGY_DENSITY_BASED,
                    // index: indexes,
                    theme: theme,
                    dataPoints: []
                });
            clusterProvider.addAll(arrLightPointCoordinates);
            clusterProvider.cluster();
            map.update(-1, 0);
            //set zoom level here
            // setCenterAndZoom(13, arrSegmentControllerIds[0]);
        }

希望有所帮助。您也可以查看最新版本2.5.4。

最好,

的Dom