[OpenLayers-Users] drawing a geojson layer
christopher.schmidt at nokia.com
christopher.schmidt at nokia.com
Fri Sep 23 16:21:11 EDT 2011
On Sep 23, 2011, at 4:15 PM, ext Puneet Kishor wrote:
>
> On Sep 23, 2011, at 3:05 PM, <christopher.schmidt at nokia.com> wrote:
>
>> Are you using OSM? Did you reproject your coordinates anywhere?
>
>
> No, I am using Google Maps base layer. My data are in lat/lng, so I believe this s a re-projection issue.
>
> I redefined my map like so
>
> map = new OpenLayers.Map("map", {
> controls: [
> new OpenLayers.Control.LayerSwitcher(),
> new OpenLayers.Control.MousePosition({div:document.getElementById("coords")})
> ],
> projection: new OpenLayers.Projection("EPSG:900913"),
> displayProjection: new OpenLayers.Projection("EPSG:4326")
> });
>
>
> and then
>
> var vector_layer = new OpenLayers.Layer.Vector(
> "vector layer",
> {projection: new OpenLayers.Projection("EPSG:4326")}
> );
> map.addLayer(vector_layer);
>
> and then
>
> var geojson_format = new OpenLayers.Format.GeoJSON();
> vector_layer.addFeatures(geojson_format.read(featurecollection));
>
> I am assuming that is not the right way, because that is not working. Do I have to transform every point one by one?
http://docs.openlayers.org/library/spherical_mercator.html#serializing-projected-data
(The same config options on the format apply to both serializing
and deserializing.)
-- Chris
>
>>
>> -- Chris
>>
>> On Sep 23, 2011, at 3:07 PM, ext Puneet Kishor wrote:
>>
>>> I have a fairly straightforward code like so, with the JSON data coming out of Pg. I am using OL 2.11
>>>
>>> var data = {
>>> "type" : "FeatureCollection"
>>> "features" : [
>>> {
>>> "geometry" : {
>>> "coordinates" : [[[x1, y1], [x2, y2], [x3, y3]]],
>>> "type" : "MultiLineString"
>>> },
>>> "type" : "Feature",
>>> "properties" : {"code" : 101, "desc" : "blah" }
>>> },
>>> {
>>> "geometry" : {
>>> "coordinates" : [[[x1, y1], [x2, y2], [x3, y3]]],
>>> "type" : "MultiLineString"
>>> },
>>> "type" : "Feature",
>>> "properties" : {"code" : 102, "desc" : "blah" }
>>> },
>>> {
>>> "geometry" : {
>>> "coordinates" : [[[x1, y1], [x2, y2], [x3, y3]]],
>>> "type" : "MultiLineString"
>>> },
>>> "type" : "Feature",
>>> "properties" : {"code" : 103, "desc" : "blah" }
>>> },
>>> ]
>>> }
>>>
>>> var geojson_format = new OpenLayers.Format.GeoJSON();
>>> var lyr = new OpenLayers.Layer.Vector("layer name");
>>> PK.vars.map.addLayer(lyr);
>>> trenches.addFeatures(geojson_format.read(data));
>>>
>>> Yet, no errors and no features drawn on the map. What am I doing wrong?
>>>
>>> Puneet._______________________________________________
>>> Users mailing list
>>> Users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>
More information about the Users
mailing list