[OpenLayers-Users] Cluster strategy and Google layer

mippon smarty at programmer.net
Thu Nov 6 12:07:13 EST 2008


I am trying to get cluster strategy to work with google layers but it just
shows up in the middle of the map at wrong coordinates. Only one point shows
up. I cannot seem to figure out what I am doing wrong. 
My script is as follows. 

<script type="text/javascript">
            var zoom = 5;
        var map, layer;

        function init(){
            var options = {
                projection: new OpenLayers.Projection("EPSG:900913"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                units: "m",
                maxResolution: 156543.0339,
                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                                 20037508.34, 20037508.34)
            };
            map = new OpenLayers.Map('map', options);
            var mapnik = new OpenLayers.Layer.TMS(
                "OpenStreetMap (Mapnik)",
                "http://tile.openstreetmap.org/",
                {
                    type: 'png', getURL: osm_getTileURL,
                    displayOutsideMaxExtent: true,
                    attribution: ' http://www.openstreetmap.org/
OpenStreetMap '
                }
            );
            map.addLayer(mapnik);
            map.addLayer(new
OpenLayers.Layer.Google("Google",{sphericalMercator:true}));
            var style = new OpenLayers.Style({
                    pointRadius: "${radius}",
                    fillColor: "#ffcc66",
                    fillOpacity: 0.8,
                    strokeColor: "#cc6633",
                    strokeWidth: 2,
                    strokeOpacity: 0.8
                }, {
                    context: {
                        radius: function(feature) {
                            return Math.min(feature.attributes.count, 7) +
3;
                        }
                    }
            });
           
            map.addLayer(new OpenLayers.Layer.Vector("GML", {
                    strategies: [
                        new OpenLayers.Strategy.Fixed(),
                        new OpenLayers.Strategy.Cluster()
                    ],
                    projection: map.displayProjection,
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "gml/owls.xml",
                        format: new OpenLayers.Format.GML()
                    }),
                    styleMap: new OpenLayers.StyleMap({
                        "default": style,
                        "select": {
                            fillColor: "#8aeeef",
                            strokeColor: "#32a8a9"
                        }
                    })
                }));

            map.zoomToExtent(new
OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906).transform(map.displayProjection,
map.projection));
            map.addControl(new OpenLayers.Control.LayerSwitcher());
        }
        function osm_getTileURL(bounds) {
            var res = this.map.getResolution();
            var x = Math.round((bounds.left - this.maxExtent.left) / (res *
this.tileSize.w));
            var y = Math.round((this.maxExtent.top - bounds.top) / (res *
this.tileSize.h));
            var z = this.map.getZoom();
            var limit = Math.pow(2, z);

            if (y < 0 || y >= limit) {
                return OpenLayers.Util.getImagesLocation() + "404.png";
            } else {
                x = ((x % limit) + limit) % limit;
                return this.url + z + "/" + x + "/" + y + "." + this.type;
            }
        }

        </script>
-- 
View this message in context: http://www.nabble.com/Cluster-strategy-and-Google-layer-tp20365309p20365309.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list