0

I am completely new to OpenLayers.

I created a GML using QGIS and would like to call data from it. It isn't stylized (specific icons per attribute). I would like to stylize/symbolize the data using HTML for my openlayers map.

I've created two rules, where one rule pulls an image if satisfying the first rule, and another image if it satisfies the other rule.

I've looked online as whatever I use for some reason is not working.

 var rule_lease = new OpenLayers.Rule({
    filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "asset_type",
        value: "lease",
    }),
    symbolizer: {
        externalGraphic: "location_of_file1.png",
                graphicWidth: 40,
                graphicHeight: 40,
                graphicYOffset: -25,
                //rotation: "${angle}",
                fillOpacity: 0.75
    });
        var rule_crown = new OpenLayers.Rule({
    filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "asset_type",
        value: "Crown-owned",
    }),
    symbolizer: {
        externalGraphic: "location_of_file2.png",
                graphicWidth: 40,
                graphicHeight: 40,
                graphicYOffset: -25,
                //rotation: "${angle}",
                fillOpacity: 0.75
    });

    style.addRules([rule_lease, rule_crown]);

    map.addLayer(vector);

If my rule is as written above (note that I haven't included a default style), how do I call a GML file for it read the data from? I know I got to include it before the rules, but I am unsure of the correct syntax. Does it look like this:

var vector = new OpenLayers.Layer.Vector("", {
    protocol: new OpenLayers.Protocol.HTTP({
        url: "location_of_gml.GML",
        format: new OpenLayers.Format.GML
    }),
    strategies: [new OpenLayers.Strategy.Fixed()],
    styleMap: new OpenLayers.StyleMap({

OR THIS:

 var layer = new OpenLayers.Layer.GML("Layer Name",                
 "http://example.com/url/of/data.txt", { format: OpenLayers.Format.gml });  
 map.addLayer(layer); map.zoomToMaxExtent();

I've tried both but I seem to be doing something wrong.

1 Answer 1

1

The OpenLayers GML example at: http://dev.openlayers.org/examples/gml-layer.html has the following method:

...
map.addLayer(new OpenLayers.Layer.Vector("GML", {
    protocol: new OpenLayers.Protocol.HTTP({
        url: "gml/polygon.xml",
        format: new OpenLayers.Format.GML()
    }),
...

perhaps helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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