4

I started in the mapping. I would like to view a map of France with a layer on top that would be personalized.

I already have the custom layer with shapefile format. I do not know at all if I have to create an OpenStreetMap server or if I can use the web application directly.

Can you give me a starting point for mapping display with my extra layer shapefile format?

I guess the task is complex, but you have to start somewhere by ...

thank you very much

Bob
  • 1,011
  • 3
  • 12
  • 28

4 Answers4

8

It depends on what you want to do. Is it a big Shapefile?

You can do a few things while create an openlayers map:

  • use the public openstreetmap server for background-tiles (the default OSM Layer implementation) and add your feature layer (points, polygons, whatever is in there) as a Vector feature layer in OSM. To get your vector features out of your shapefile you can:
    • preload them in your database in a decent GIS based format. This allows you to serve your features while doing bounding box queries, and is required if you have more than 1000/10000 features.
    • convert the shapefile to a format readable by openlayers (either in browser using https://github.com/wavded/js-shapefile-to-geojson , or preconvert them with a tool like ogr2ogr)
  • or, if you don't require interaction with these features, you can combine your data with OSM data, and create your custom tiles. This is more light-weight for the browser, but it's quite complex (read all OSM data in a DB, generate tiles with mapnik)
ivy
  • 5,539
  • 1
  • 34
  • 48
2

If you wish to add a OpenStreetMap (OSM) over your shapefile layer, simply add the following line of code,

var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);

Though I did not understand, why do you need to create a OpenStreetMap server for?

Sam007
  • 8,397
  • 4
  • 24
  • 34
1

You don't need to create an OpenStreetMap server by your own.

If you want to display your custom layer on a map then use google or openstreetmap as a base layer and display your layer (comes from shape file) on the map.

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77
0

You can use gipong/shp2geojson : first, you convert the shp file into geojson data Then you add your data to your map

   var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    target: 'map',
    view: new ol.View({
        center: [0, 0],
        zoom: 5
    })
});

loadshp({
    url: 'demo/10tnvillage.zip',
    encoding: 'big5',
    EPSG: 3826
}, function(data) {
    var feature = new ol.format.GeoJSON().readFeatures(data, {
        featureProjection: 'EPSG:3857'
    });
    var layer = new ol.layer.Vector({
        source: new ol.source.Vector({
            features: feature
        })
    });
    map.addLayer(layer);

    var extent = layer.getSource().getExtent();
    map.getView().fit(extent, map.getSize());
});