[OpenLayers-Users] Showing points from a database

Niccolò Dal Santo ncl.dalsanto at gmail.com
Sun Sep 21 10:49:42 PDT 2014


At first ,thanks a lot for the help.

Secondly, I don't know since this is an example downloaded by the internet.
However I have tried by inserting this line in my code

    map.setCenter(
        new OpenLayers.LonLat(0,0).transform(
            new OpenLayers.Projection("EPSG:4326"),
            map.getProjectionObject()
        ), 1
    );



So, this is my final code:

<html>
<head>
  <title>Prova GML</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
    <body>

<div id="ch3_cluster" style="width: 100%; height: 100%;"></div>


    <script type="text/javascript">


    var map = new OpenLayers.Map("ch3_cluster");

    var layer = new OpenLayers.Layer.OSM("OpenStreetMap");
    map.addLayer(layer);

    map.addControl(new OpenLayers.Control.LayerSwitcher());
//    map.setCenter(new OpenLayers.LonLat(0,0), 2);

    map.setCenter(
        new OpenLayers.LonLat(0,0).transform(
            new OpenLayers.Projection("EPSG:4326"),
            map.getProjectionObject()
        ), 1
    );

    // World Cities
    var citiesLayer = new OpenLayers.Layer.Vector("World Cities (GeoJSON)",
        {   protocol: new OpenLayers.Protocol.HTTP({
            url: "http://localhost/world_cities.json",
            format: new OpenLayers.Format.GeoJSON()
        }),
        strategies: [
            new OpenLayers.Strategy.Fixed(),
            new OpenLayers.Strategy.Cluster({distance: 15})
        ]
    });
    map.addLayer(citiesLayer);



</script>
</body>
</html>

Now I have also tried with another and easier example found in the web but
it doesn't work as well, so I was wondering whether I am missing something
like a basic requirement or a Java updating or whatever in order to use
these features. What I have done is to download the library ( but the
source in this code should be the web as the first script states). Do you
have any idea on that?

Thank you very much!

Niccolò


2014-09-21 19:19 GMT+02:00 Arnd Wippermann <arnd.wippermann at web.de>:

>  Hi,
>
> your map is in projection EPSG:900913 (OSM).
> Are your data also in this projection or perhaps in EPSG:4326 (lonlat)?
>
> If so, it could be that your data are shown (at x=0,y=0), but you only
> can't see them.
>
> Regards,
> Arnd
>
>  ------------------------------
> *Von:* openlayers-users-bounces at lists.osgeo.org [mailto:
> openlayers-users-bounces at lists.osgeo.org] *Im Auftrag von *Niccolò Dal
> Santo
> *Gesendet:* Freitag, 19. September 2014 23:11
> *An:* Mark Prins
> *Cc:* openlayers-users
> *Betreff:* Re: [OpenLayers-Users] Showing points from a database
>
>  Thank you very much for your answer. I have therefore started to
> investigate the possiblity to use the GeoJSON format, and now I am trying
> to train with this format with this example but it doesn't work
>
>      <script type="text/javascript">
>
>     var map = new OpenLayers.Map("my_map");
>
>     var layer = new OpenLayers.Layer.OSM("OpenStreetMap");
>     map.addLayer(layer);
>
>     map.addControl(new OpenLayers.Control.LayerSwitcher());
>     map.setCenter(new OpenLayers.LonLat(0,0), 2);
>
>     var citiesLayer = new OpenLayers.Layer.Vector("World Cities
> (GeoJSON)",
>         {   protocol: new OpenLayers.Protocol.HTTP({
>             url: "http://localhost/openlayers/world_cities.json",
>             format: new OpenLayers.Format.GeoJSON()
>         }),
>         strategies: [
>             new OpenLayers.Strategy.Fixed(),
>             new OpenLayers.Strategy.Cluster({distance: 15})
>         ]
>     });
>     map.addLayer(citiesLayer);
> </script>
>
> In order to make the protocol work I have installed nginx on my laptop and
> the url correctly points to the file world_cities.json in my browser.
> Anyway this example doesn't work, any idea why?
>
> Thanks!
> Niccolò
>
> 2014-09-19 15:54 GMT+02:00 Mark Prins <mc.prins at gmail.com>:
>
>> using plain text or (geo) json is much less error prone than using
>> GML, and probably gives better performance
>>
>> 2014-09-19 15:45 GMT+02:00 Niccolò Dal Santo <ncl.dalsanto at gmail.com>:
>> > Hi there,
>> >
>> > I am new of Openlayers and I need to show some points that come from a
>> > database on a map centred in Turin (Italy), with some information
>> related to
>> > this point (for instance an image). Searching on line I have found that
>> > Openlayers supports many formats of data like GML, KML, GeoJSON and many
>> > others. Could you suggest a format useful fror my problem and maybe some
>> > examples of how to use it?
>> >
>> > I have tried with this code generating a map of europe, but it doesn't
>> work
>> >
>> > <html>
>> > <head>
>> >   <title>Prova GML</title>
>> >     <script src="http://openlayers.org/api/OpenLayers.js"></script>
>> > </head>
>> >     <body>
>> >     <div id="ch3_gml" style="width: 100%; height: 100%;"></div>
>> >
>> >     <script type="text/javascript">
>> >
>> >         // Create the map using the specified DOM element
>> >         var map = new OpenLayers.Map("ch3_gml");
>> >
>> >         var layer = new OpenLayers.Layer.OSM("OpenStreetMap");
>> >         map.addLayer(layer);
>> >
>> >         map.addControl(new OpenLayers.Control.LayerSwitcher());
>> >         map.setCenter(new OpenLayers.LonLat(0,0), 2);
>> >
>> >         map.addLayer(new OpenLayers.Layer.Vector("Europe (GML)", {
>> >             protocol: new OpenLayers.Protocol.HTTP({
>> >                 url: "./europe.gml",
>> >                 format: new OpenLayers.Format.GML()
>> >             }),
>> >             strategies: [new OpenLayers.Strategy.Fixed()]
>> >         }));
>> >     </script>
>> > </body>
>> > </html>
>> >
>> > where europe.gml is a gml file in the same folder of this script, but
>> > nothing happens.
>> >
>> > Thank you very much for your help!
>> >
>> > Regards
>> >
>> > Niccolò
>> >
>> > --
>> > Niccolò Dal Santo
>> > +39 342 15 70 842
>> > ncl.dalsanto at gmail.com
>> >
>> > _______________________________________________
>> > Users mailing list
>> > Users at lists.osgeo.org
>> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>>
>>
>> --
>> Disclaimer;
>> This message is just a reflection of what I thought at the time of
>> sending. The message may contain information that is not intended for
>> you or that you don't understand.
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
>
>
> --
> Niccolò Dal Santo
> +39 342 15 70 842
> ncl.dalsanto at gmail.com
>
>
> ------------------------------
>    <http://www.avast.com/>
>
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
> <http://www.avast.com/> Schutz ist aktiv.
>
>


-- 
Niccolò Dal Santo
+39 342 15 70 842
ncl.dalsanto at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140921/6cca664e/attachment-0001.html>


More information about the Users mailing list