simply enabling gzip/deflate compression works really well in<br>reducing the transfer size for geoJSON... I often see a 10x win<br><br>using the keymap is also a good approach and saves runtime<br>memory in the browser<br>

<br><div class="gmail_quote">On Mon, Sep 26, 2011 at 3:33 AM, Mr. Puneet Kishor <span dir="ltr">&lt;<a href="mailto:punk.kish@gmail.com">punk.kish@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

solved... see below (might be of use to others)<br>
<div class="im"><br>
On Sep 25, 2011, at 11:35 AM, Mr. Puneet Kishor wrote:<br>
<br>
&gt; Right now I am creating a vector layer with features that are clickable, and show a popup window with the feature&#39;s attributes. My code is like so on the server side where I am selecting (fictitious) &quot;meetings&quot; from a database<br>


&gt;<br>
&gt;    while (meetings) {<br>
&gt;        push @features, {<br>
&gt;            type =&gt; &quot;Feature&quot;,<br>
&gt;            properties =&gt; {<br>
&gt;                &quot;long field1 name&quot; =&gt; $field1,<br>
&gt;                &quot;long field2 name&quot; =&gt; $field2,<br>
&gt;                &quot;long field3 name&quot; =&gt; $field3<br>
&gt;            },<br>
&gt;            geometry =&gt; {<br>
&gt;                type =&gt; &quot;Point&quot;,<br>
&gt;                coordinates =&gt; [$lng, $lat]<br>
&gt;            }<br>
&gt;        };<br>
&gt;    }<br>
&gt;    my %meetings = (<br>
&gt;        meetings =&gt; {type =&gt; &quot;FeatureCollection&quot;, features =&gt; \@features}<br>
&gt;    );<br>
&gt;    my $res = to_json \%meetings;<br>
&gt;<br>
&gt; and then, in the browser<br>
&gt;<br>
&gt;    // In my ajax call<br>
&gt;    success: function(data) {<br>
&gt;        var geojson_format = new OpenLayers.Format.GeoJSON();<br>
&gt;        ..<br>
&gt;        lyr.addFeatures(geojson_format.read(data[&quot;meetings&quot;]));<br>
&gt;<br>
&gt;        lyr.events.on({<br>
&gt;            &quot;featureselected&quot;: onFeatureSelect,<br>
&gt;            &quot;featureunselected&quot;: onFeatureUnselect<br>
&gt;        });<br>
<br>
<br>
<br>
</div>pass additional data to the `onFeatureSelect` callback like so<br>
<br>
        lyr.events.on({<br>
            &quot;featureselected&quot;: function(evt) {<br>
                 onFeatureSelect(evt, keymap);<br>
            },<br>
            &quot;featureunselected&quot;: onFeatureUnselect<br>
        });<br>
<br>
<br>
and then, in the callback<br>
<br>
        // !onFeatureSelect(evt)<br>
        function onFeatureSelect(evt, keymap) {<br>
<div class="im">            feature = evt.feature;<br>
            var str = &quot;&quot;;<br>
<br>
            for (var i in feature.attributes) {<br>
</div>                str += &quot;&lt;b&gt;&quot; + keymap[i] + &quot;:&lt;/b&gt; &quot; + feature.attributes[i] + &quot;&lt;br /&gt;&quot;;<br>
            }<br>
<br>
            .. make popup window with str<br>
<div><div></div><div class="h5">        };<br>
<br>
<br>
&gt;    }<br>
&gt;<br>
&gt;<br>
&gt;    function onFeatureSelect(evt) {<br>
&gt;        var feature = evt.feature;<br>
&gt;        var str = &quot;&quot;;<br>
&gt;        for (var i in feature.attributes) {<br>
&gt;            str += &quot;&lt;b&gt;&quot; + i + &quot;:&lt;/b&gt; &quot; + feature.attributes[i] + &quot;&lt;br /&gt;&quot;;<br>
&gt;        }<br>
&gt;<br>
&gt;        popup = new OpenLayers.Popup.FramedCloud(.. using str ..);<br>
&gt;        ..<br>
&gt;        map.addPopup(popup, true);<br>
&gt;    };<br>
&gt;<br>
&gt; This works great, but for a few thousand features, all those &quot;long fields names&quot; add up to a lot of wasteful data transfer. In the interest of reducing data transfer, I am hoping to implement a keymap for my attribute names (keys), and then send the keymap along with the new keys. Something like so on the server side (kinda like my own minification scheme) --<br>


&gt;<br>
&gt;    while (meetings) {<br>
&gt;        push @features, {<br>
&gt;            type =&gt; &quot;Feature&quot;,<br>
&gt;            properties =&gt; {<br>
&gt;                a =&gt; $field1,<br>
&gt;                b =&gt; $field2,<br>
&gt;                c =&gt; $field3<br>
&gt;            },<br>
&gt;            geometry =&gt; {<br>
&gt;                type =&gt; &quot;Point&quot;,<br>
&gt;                coordinates =&gt; [$lng, $lat]<br>
&gt;            }<br>
&gt;        };<br>
&gt;    }<br>
&gt;    my %meetings = (<br>
&gt;        keymap =&gt; {<br>
&gt;            a =&gt; &quot;long field1 name&quot;,<br>
&gt;            b =&gt; &quot;long field2 name&quot;,<br>
&gt;            c =&gt; &quot;long field3 name&quot;<br>
&gt;        },<br>
&gt;        meetings =&gt; {type =&gt; &quot;FeatureCollection&quot;, features =&gt; \@features}<br>
&gt;    );<br>
&gt;    my $res = to_json \%meetings;<br>
&gt;<br>
&gt; But, I am at a loss as to how to modify my JavaScript code to use this keymap. `evt.feature` seems to have an &quot;attributes&quot; key that has been automatically mapped to the &quot;properties&quot; key sent from the server. How do I get the data.keymap to my onFeatureSelect(evt) callback?<br>


<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Zac Spitzer <br>Solution Architect / Director<br>Ennoble Consultancy Australia<br><a href="http://www.ennoble.com.au">http://www.ennoble.com.au</a><br><a href="http://zacster.blogspot.com">http://zacster.blogspot.com</a><br>

+61 405 847 168<br><br><br><br>