Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

im trying to apply rules, where the data is fetched from an external database. This is my code:

// create a new style and add rules var defStyle = new OpenLayers.Style({ strokeWidth: 1 });

        defStyle.addRules([

            new OpenLayers.Rule({
                symbolizer: {
                    fillColor: "#ffeecc"
                },
                filter: new OpenLayers.Filter.Comparison({
                    type: OpenLayers.Filter.Comparison.LESS_THAN,
                    property: "order07",
                    value: "04000"
                })
            }),

            new OpenLayers.Rule({
                symbolizer: {
                    fillColor: "#ffcc99"
                },
                filter: new OpenLayers.Filter.Comparison({
                    type: OpenLayers.Filter.Comparison.BETWEEN,
                    property: "order07",
                    lowerBoundary: "04000",
                    upperBoundary: "08000"
                })
            }),
            new OpenLayers.Rule({
                symbolizer: {
                    fillColor: "#ff9966"
                },
                filter: new OpenLayers.Filter.Comparison({
                    type: OpenLayers.Filter.Comparison.BETWEEN,
                    property: "order07",
                    lowerBoundary: "08000",
                    upperBoundary: "11000"
                })
            }),
        ]);



        var selStyle = new OpenLayers.Style({
            fillColor: "#ffaa00"
        });

        // combine styles in a style map
        var myStyleMap = new OpenLayers.StyleMap({
            "default": defStyle,
            "select": selStyle
        });

what i want to do is something like this:

I have a database with

ID| Name


1 | Bob

2 | Sam

and i want the rules getting applied according to one of those values. Is it possible to include external database information that is not in the shapefile ??

In spoken words the original rule is "Color all vectors where the property:order07 is less than value:04000 with the color #ffeecc"

and i want to change it into something like "Color the vectors where the property:fromDatabase xy: is value:xxyy with the color #xxxxxx"

share|improve this question
add comment

2 Answers

It is not clear where the shapefile is involved in your question.

You can join the database attributes to your features in a query, then load this view as your OpenLayers layer.

Then you can use attributes to create your styles: http://docs.openlayers.org/library/feature_styling.html#attribute-replacement-syntax

Alternatively you could generate a SLD file dynamically from a web service reading from the database and apply this to your map layers.

share|improve this answer
add comment

There is indeed a big gap between "desktop" data and vector rendering through OpenLayers in a web browser.

Bindings between desktop data (either in a shapefile or in a DMS) and OpenLayers can be taken care of by a "GIS enabled" web framework. This kind of framework relies on a Model View Controller pattern and is able to generate HTTP web services to access your data within the browser. OpenLayers's vector layers can then be plugged on such web services. In python GeoDjango or Mapfish are perfect matches.

It is not clear also why you would need both a shapefile and a database software : geometries can be imported next to other data into a postGIS/postgreSQL database.

I digressed a lot, but I hope I have filled some dark areas in the OP's question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.