0

执行此操作时,我在地图上得到两个点,但是当我缩放图像时,图像变得更小。

如何保持图像的大小固定?下面是javascript代码。

function init() {
    var feature_data = {
        "type":"FeatureCollection",
        "features": [{
            "type":"Feature",
            "id":4,
            "geometry": {
                "type":"Point",
                "coordinates": [65.216,33.677]
            },
            "properties": {
                "name":"Afghanistan",
                "population":25067407,
                "pop_0_14":47,
                "pop_15_59":49.3,
                "pop_60_above":3.7
            }
        },  
        {
           "type":"Feature",
           "id":8,
           "geometry": {
               "type":"Point",
               "coordinates":[20.068,41.143]
           },
           "properties: {
               "name":"Albania",
               "population":3153731,
               "pop_0_14":26.3,
               "pop_15_59":61.4,
               "pop_60_above":12.3
            }
        }]
    };

    var map = new OpenLayers.Map('map_element',{});
    var wms_layer = new OpenLayers.Layer.WMS('OpenLayers WMS',
        'http://vmap0.tiles.osgeo.org/wms/vmap0', 
        {layers: 'basic'},
        {}
    );

    var format_geojson = new OpenLayers.Format.GeoJSON({});
    var vector_strategies = new OpenLayers.Strategy.Cluster({});
    var vector_layer= new OpenLayers.Layer.Vector('bar graph visualization',
        {strategies: vector_strategies}
    );
    vector_layer.addFeatures(format_geojson.read(feature_data));
    map.addLayers([wms_layer,vector_layer]);
    if(!map.getCenter()) {
        map.zoomToMaxExtent();
    }
}
4

1 回答 1

0

您实际上希望在每次缩放更改后对点强制执行调整大小事件。

您可以侦听缩放事件并更新pointRadius样式属性

或者您可以监听缩放事件并使用调整大小功能调整每个点特征的大小

map.events.register("zoomend", map, function() {
    var currentZoom = map.getZoom();
    // check for desired zoom levels
    if (currentZoom == 5) {

        // update the style's pointRadius 
        // style.pointRadius = newRadius;

        // OR
        // resize each individual point feature 
        // loop through the point features
            // pointFeature.geometry.resize(scale, origin);

        // and after either strategy
        // redraw the point layer 

    } else if (currentZoom == 6) {
        ...
    } ...
}    
于 2014-05-07T04:51:36.910 回答