Bob
Bob

Reputation: 1061

OpenLayer + OpenStreetMap + Custom ShapeFile

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

Upvotes: 4

Views: 10348

Answers (4)

Yogesh Prajapati
Yogesh Prajapati

Reputation: 4870

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.

Upvotes: 1

sara GHOZALI
sara GHOZALI

Reputation: 1

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());
});

Upvotes: 0

ivy
ivy

Reputation: 5559

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)

Upvotes: 8

Sam007
Sam007

Reputation: 8767

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?

Upvotes: 2

Related Questions