diff --git a/Use-cases.md b/Use-cases.md new file mode 100644 index 0000000..7445f17 --- /dev/null +++ b/Use-cases.md @@ -0,0 +1,41 @@ +# Vector Use Cases + +These use cases describe common scenarios for loading, rendering, and editing vector data. + +## Load data once from static file + +User has a static file (e.g. GeoJSON) hosted on the same origin as their application. User expects data to be loaded and rendered over a raster tile based layer (e.g. WMS). Data may be in a different coordinate reference system than map. + +**Alternative 1** + +```js +var raster = new ol.layer.TileLayer({ + source: new ol.source.TiledWMS({ + url: 'http://demo.opengeo.org/geoserver/wms', + params: {'LAYERS': 'topp:states', 'TILED': true} + }) +}); + +// assume features.json is a FeatureCollection in EPSG:4326 +var vector = new ol.layer.Vector({ + source: new ol.source.Vector({ + protocol: new ol.protocol.HTTP({ + url: './data/features.json' + }), + parser: new ol.parser.GeoJSON() + }) +}); + +var map = new ol.Map({ + layers: [raster, vector], + target: 'map', + view: new ol.View2D({ + projection: 'EPSG:1234', + center: ol.projection.transform( + new ol.Coordinate(139.7, 35.7), 'EPSG:4326', 'EPSG:1234'), + zoom: 9 + }) +}); +``` + +This alternative can be implemented if the layer knows the map projection. The vector layer would be responsible for calling `source.protocol.read({success: callback})` where the callback would call `source.parser.parseFeatures(data, {projection: projection})` (`data` is supplied to the callback and `projection` comes from the map's view).