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"><<a href="mailto:punk.kish@gmail.com">punk.kish@gmail.com</a>></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>
> Right now I am creating a vector layer with features that are clickable, and show a popup window with the feature's attributes. My code is like so on the server side where I am selecting (fictitious) "meetings" from a database<br>
><br>
> while (meetings) {<br>
> push @features, {<br>
> type => "Feature",<br>
> properties => {<br>
> "long field1 name" => $field1,<br>
> "long field2 name" => $field2,<br>
> "long field3 name" => $field3<br>
> },<br>
> geometry => {<br>
> type => "Point",<br>
> coordinates => [$lng, $lat]<br>
> }<br>
> };<br>
> }<br>
> my %meetings = (<br>
> meetings => {type => "FeatureCollection", features => \@features}<br>
> );<br>
> my $res = to_json \%meetings;<br>
><br>
> and then, in the browser<br>
><br>
> // In my ajax call<br>
> success: function(data) {<br>
> var geojson_format = new OpenLayers.Format.GeoJSON();<br>
> ..<br>
> lyr.addFeatures(geojson_format.read(data["meetings"]));<br>
><br>
> lyr.events.on({<br>
> "featureselected": onFeatureSelect,<br>
> "featureunselected": onFeatureUnselect<br>
> });<br>
<br>
<br>
<br>
</div>pass additional data to the `onFeatureSelect` callback like so<br>
<br>
lyr.events.on({<br>
"featureselected": function(evt) {<br>
onFeatureSelect(evt, keymap);<br>
},<br>
"featureunselected": 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 = "";<br>
<br>
for (var i in feature.attributes) {<br>
</div> str += "<b>" + keymap[i] + ":</b> " + feature.attributes[i] + "<br />";<br>
}<br>
<br>
.. make popup window with str<br>
<div><div></div><div class="h5"> };<br>
<br>
<br>
> }<br>
><br>
><br>
> function onFeatureSelect(evt) {<br>
> var feature = evt.feature;<br>
> var str = "";<br>
> for (var i in feature.attributes) {<br>
> str += "<b>" + i + ":</b> " + feature.attributes[i] + "<br />";<br>
> }<br>
><br>
> popup = new OpenLayers.Popup.FramedCloud(.. using str ..);<br>
> ..<br>
> map.addPopup(popup, true);<br>
> };<br>
><br>
> This works great, but for a few thousand features, all those "long fields names" 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>
><br>
> while (meetings) {<br>
> push @features, {<br>
> type => "Feature",<br>
> properties => {<br>
> a => $field1,<br>
> b => $field2,<br>
> c => $field3<br>
> },<br>
> geometry => {<br>
> type => "Point",<br>
> coordinates => [$lng, $lat]<br>
> }<br>
> };<br>
> }<br>
> my %meetings = (<br>
> keymap => {<br>
> a => "long field1 name",<br>
> b => "long field2 name",<br>
> c => "long field3 name"<br>
> },<br>
> meetings => {type => "FeatureCollection", features => \@features}<br>
> );<br>
> my $res = to_json \%meetings;<br>
><br>
> But, I am at a loss as to how to modify my JavaScript code to use this keymap. `evt.feature` seems to have an "attributes" key that has been automatically mapped to the "properties" 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>