GithubHelp home page GithubHelp logo

map's Introduction

Map 0.x for Express Lane

Map provides an API for generating the various endpoints needed to generate TileLive and StyleWriter maps in the context of a web app. It provides helpers to prop up endpoints for:

  1. OL wax) JSON for configuring OpenLayers maps with proper interactive data when using polygon based TileLive layers.
  2. TileLive MML styles with Cascadenik style rules based on the data in your webapp.
  3. GeoJSON output of data in your webapp that can be used by TileLive.

Requirements

Client side:

Using map

Maps should be defined in settings.js or a sub module file required by the main expresslane settings file like settings.map.js. Map expects an object keyed by map name to be present at require('settings').map:

module.exports = {
    map: {
        // Defines the `home` map
        home: {
            world: {
                type: 'OpenLayers.Layer.MapBox',
                visibility: "true",
                extension: "png",
                mapbox: true,
                layername: "world-glass",
                baselayer: true,
                resolutions: '4891.96980938,2445.98490469,1222.99245234,611.496226172,305.748113086,152.874056543,76.4370282715'
            }
            // ... more layers
        }
        // ... more maps
    }
    // ... settings for other expresslane modules
};

Defining layers

Each map object contains a keyed list of layer objects. Each layer object can have the following attributes:

  • title: String, title of the layer.
  • type: String, OL layer type.
  • visibility: String, initial layer visibility state.
  • extension: String, tile image extension.
  • mapbox: Boolean, whether this layer is a mapbox layer or not.
  • layername: String, mapbox layername.
  • baselayer: Boolean, whether this layer is a baselayer or not.
  • legend: String, legend to use for this layer.
  • resolutions: String, OL resolutions for this layer.
  • stylewriter: Object, a display field configuration object for stylewriter layers.

@TODO: These obviously need better organization and modularity. Fix.

Usage

The main function exposed by map is map(req, urlSchema, map, layer, resource, rows):

  • req: The request object for the current request.
  • urlSchema: A route string representing the URL schema for map endpoints.
  • map: String name of the map configuration to use, e.g. home.
  • layer: String name of a specific layer to generate a map resource for.
  • resource: String map resource to generate. May be: json, geojson or mml for their respective endpoint resources.
  • rows: An array of CouchDB rows returned by a query.

Returns an object that can be rendered (geojson, json or mml) using the render(res, resource, built) method:

  • res: The response object for the current request.
  • resource: String map resource to generate. May be: json, geojson or mml for their respective endpoint resources.
  • map: Object built map from map().

To simplify usage, the fromRoute(req, urlSchema, rows) method is provided that will detect the ommitted parameters (map, layer, resource) from the request object assuming that you use equivalently named request params.

Providing a router endpoint

The URL schema defined should match the route path used in express and should contain :map, :layer and :resource params as well as any other parameters you will need for loading data.

app.get('/map/:map/:layer.:resource', function(req, res, next) {
    var map = require('map');
    var rows = someLoader();
    var built = map.fromRoute(req, '/map/:map/:layer.:resource', rows);
    var resource = req.param('resource');
    map.render(res, resource, built);
});

The router rule above would respond to the following example requests:

  • /map/home/world.json OL Wax JSON for the home map with only configuration for the world layer. You could provide a JSON file by making the layer parameter optional by using :layer? in your route rule and requesting your JSON at /map/home.json.
  • /map/home/world.geojson geojson containing features from fields defined in the world layer.
  • /map/home/world.mml TileLive compatible MML file for the world layer.

map's People

Contributors

wrynearson avatar

Watchers

JT5D avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.