Wednesday 29 August 2018

Openlayers 4 WFS & vector select



I want to convert this project for other use from OL2 to OL4 but I can't convert the code and get back a map,


http://www.trafficorders.uk/


here the OL2 code:


  layer = new OpenLayers.Layer.WMS("UKMap", "http://www.trafficorders.uk/cgi-bin/wmsmaps", {
layers: "bgmap"
}, {
isBaseLayer: true,
transitionEffect: 'resize',
singleTile: false,
ratio: 1.1

});

var areaStyMap = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
fill: true,
fillOpacity: 1,
strokeColor: "#000000",
fillColor: "${MapColour}",
strokeWidth: 1


}),
"select": new OpenLayers.Style({
strokeColor: "#FFFFFF",
fillOpacity: 1,
strokeWidth: 2,
fillColor: "#FF9900",
label: "${Name}",
labelOutlineWidth: 3,
labelOutlineColor: '#ffffff',
fontSize: "12px",

fontFamily: "Arial, Courier New",
fontWeight: "bold"
})
});

var strat = new OpenLayers.Strategy.Fixed();
var pmproto = new OpenLayers.Protocol.WFS({
url: "http://www.trafficorders.uk/cgi-bin/mapserv?map=/var/www/vhosts/trafficorders.uk/httpdocs/maps/wfsareas.map",
featureType: "la_areas",
featureNS: "http://mapserver.gis.umn.edu/mapserver",

featurePrefix: "ms"
});
arealayer = new OpenLayers.Layer.Vector("la_areas", {
strategies: [strat],
protocol: pmproto,
styleMap: areaStyMap
});

and here my new code:


var vector = new ol.layer.Vector({

source: new ol.source.Vector({
url: 'http://www.traffwebdev.uk/cgi-bin/mapserv?map=/var/www/vhosts/traffwebdev.uk/httpdocs/hosted/maps/wfsareas.map',
format: new ol.format.WFS({
featureType: ["la_areas"],
featureNS: "http://mapserver.gis.umn.edu/mapserver",
featurePrefix: "ms"
})
})
});


the featureNS seems to do not works, I don't have nothing back while in the old code I have a collection of features.


What I want to achieve is something like this but with WFS instead of geoJson


https://openlayers.org/en/latest/examples/box-selection.html



Answer



You will find 2 solutions:



Normally according to the current code you should use the first solution e.g with map projection EPSG 27700 (surely related to the fact that your map is UK only)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...