[OpenLayers-Users] GeoJSON layer on top of google - repeated
load of features
Adorian Ardelean
mynature at gmail.com
Wed Jul 2 01:01:03 EDT 2008
Hi all,
I realize now that some parts of the code in my previous message included
bits from trials. So the correct and functional code for second version of
loading a GeoJSON file would be:
OpenLayers.loadURL("geojson.php", {}, null, onLoadgml, onLoadFailedgml);
function onLoadgml(r) {
if (r.status == 200) {
var p = new OpenLayers.Format.GeoJSON();
var f = p.read(r.responseText);
specimens.addFeatures(f);
}
}
In order to render the features correctly on a Google Map layer, I need to
include the following parameters :
{projection: new OpenLayers.Projection("EPSG:4326"), styleMap: new
OpenLayers.StyleMap(style)}
Question: is it possible to place these parameters in code above? and where?
The question and background presented about what is best strategy of loading
repeatedly a GeoJSON file remain valid.
Any hints are appreciated,
Adorian
On Wed, Jul 2, 2008 at 12:01 AM, Adorian Ardelean <mynature at gmail.com>
wrote:
> Hi,
>
> First of all thank you for the prompt suggestion. Worked perfectly and I
> was able to include also a style to work with properties defined within
> GeoJSON file:
> *
> specimens = new OpenLayers.Layer.GML("specimens", "geojson.php", {format:
> OpenLayers.Format.GeoJSON, projection: new
> OpenLayers.Projection("EPSG:4326"), styleMap: new
> OpenLayers.StyleMap(style)});*
>
> The situation I've encountered now is that data from this layer has to be
> regenerated with every zoomend event (I do some clustering on server side to
> limit the number of features to less than 100 points - the return could be
> easily in hundreds or more). The part with zoomend event I can handle.
> However, I do not know what is the best strategy to handle this situation
> further:
>
> 1. delete the whole layer and recreate a new GML layer (using code above)
> every time? This produces some problems in handling controls (as I interpret
> from reaction of the scripts). The controls dedicated to layer "specimens"
> does not function anymore. I have to redeclare it again.
>
> 2. create a vector layer and load and delete features with zoom events
> without removing layer and controls.
>
> For second solution I have found the piece of code below, (which also
> works) but returns me to the initial question how do I specify in this
> context projection an style parameters?:
>
> *OpenLayers.loadURL("geojson.php", {}, null, styleMap: new
> OpenLayers.StyleMap(style)}, onLoadgml, onLoadFailedgml);
>
> function onLoadgml(r) {
> if (r.status == 200) {
> var p = new OpenLayers.Format.GeoJSON();
> var f = p.read(r.responseText);
> specimens.addFeatures(f);
> }
> }*
> *
> ....
>
> *I would somehow prefer the second strategy. Could somebody give me a hint
> on how to include *{format: OpenLayers.Format.GeoJSON, projection: new
> OpenLayers.Projection("EPSG:4326")* in script so that OL renders vector
> features at the right place*?
>
> *All the best,
> Adorian
>
> On Sat, Jun 28, 2008 at 5:32 PM, Christopher Schmidt <
> crschmidt at metacarta.com> wrote:
>
>> On Sat, Jun 28, 2008 at 04:39:19PM +0200, Adorian Ardelean wrote:
>> > Hi,
>> >
>> > I am trying to load a GeoJSON file in a layer on top of a google map
>> > (OpenLayers 2.6).
>> >
>> > I used for now:
>> > var colfeatures = new OpenLayers.Layer.GML("specimens", "geojson.php",
>> > {format: OpenLayers.Format.GeoJSON});
>> > map.addLayer(colfeatures);
>> >
>> > Entities show up on the map somewhere close to 0,0. For other vector
>> > entities (coordinates) I push through code this is solved with
>> >
>> > var g = new OpenLayers.Projection("EPSG:4326");
>> > var p = new OpenLayers.Projection("EPSG:900913");
>> >
>> > and .tranform(g,p)
>> >
>> > but I do not know how to apply this directly on features read from
>> GeoJSON.
>> > Is there a way to loop through all entities in colfeatures and apply
>> > transform(g.p) or can somebody suggest me a better approach?
>> {format: OpenLayers.Format.GeoJSON} ->
>> { format: OpenLayers.Format.GeoJSON,
>> projection: new OpenLayers.Projection("EPSG:4326")
>> }
>>
>> Regards,
>> --
>> Christopher Schmidt
>> MetaCarta
>>
>
>
> http://mybiosis.info
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080702/f1c6c5fe/attachment.html
More information about the Users
mailing list