Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
3

You need to use geometry:feature.getGeometry().clone() otherwise the features will share the same geometry object and a change to one will change both.


3

It will use the value of getStyle at the time vector is defined. For dynamic styling you need a style function var vector = new ol.layer.Vector({ style: function(){ return getStyle; }, source: new ol.source.Vector({ url: 'JS/getjson.json', format: new ol.format.GeoJSON() }), opacity: 1 }); or you could use vector.setStyle(getStyle);


3

Hard to answer without more info. Getting the data from the DB will be about the same in each case. Converting it to an image (WMS) or GeoJSON will depend on the number and size of the features. Transmitting the data to the client will again depend on the size and number of features, for small datasets GeoJSON will be faster but for larger or more ...


3

It is possible using more recent versions of OpenLayers. This will work in version 4.6.5 var pixelTolerance = 10; var modify = new ol.interaction.Modify({ source: vector.getSource(), pixelTolerance: pixelTolerance, condition: function(e){ var f = this.getMap().getFeaturesAtPixel(e.pixel,{ hitTolerance: pixelTolerance, ...


2

RegularShape only works for regular polygons. One way to display a point feature as a rectangle with different width and height would be to use a geometry function to produce a polygon from the point coordinates, for example new ol.style.Style({ geometry: function(feature) { var coordinate = feature.getGeometry().getCoordinates(); return ol....


2

The location may need adjusting by about 10km as tiles are not loading where you centered the view. The main problem was that EPSG:25831 needed to be defined using proj4. You will need to include the library <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script> proj4.defs("EPSG:25831","+proj=utm +zone=31 +ellps=...


2

is not possible get "outputFormat=application/json" It is not possible in the service you list. The service GetCapabilities response tells you what output formats are available: http://www.ign.es/wfs-inspire/unidades-administrativas?service=WFS&request=GetCapabilities <ows:Parameter name="outputFormat"> <ows:AllowedValues> &...


2

@Dataform's answer is correct but creating a new style object every time the function is called is inefficient and can, with large numbers of features, cause performance issues. It is better to predefine a style and set the text property as required let style = new ol.style.Style({ // ........... text: new ol.style.Text({ text: '' }) /...


2

You can pass a function to the style option of the vector layer. The function is called for each feature and must return a style object. let styleFunction = function (feature, resolution) { return new ol.style.Style({ // ........... text: new ol.style.Text({ text: feature.get("fieldname_for_plotnumber") }) // ........... }); } let ...


2

Since your styles are on the layer specifying the selected style when you create the Select interaction should be sufficient var select = new ol.interaction.Select({ style: style_selected, ... // any other options }); (and remove the line which sets the style on features)


2

You could draw an image on the canvas. For demo purposes try this which adds a semi-transparent fill while the layer is loading. If you have a suitable image use evt.context.drawImage instead. var loading = false; cadLayer = new ol.layer.Vector({ visible: true, source: new ol.source.Vector({ loader: function(extent) { ...


1

Adding a precompose before the rendercomplete to set a white background would avoid any transparent canvas which might be causing the problem. map.on('precompose', function(event) { event.context.fillStyle = 'white'; event.context.fillRect(0, 0, event.context.canvas.width, event.context.canvas.height); });


1

It's mentioned in the update notes https://github.com/openlayers/openlayers/blob/master/changelog/upgrade-notes.md A simple fix which the ol-ext library uses is to replace it with the something based on the old function var ol_ext_inherits = function(child,parent) { child.prototype = Object.create(parent.prototype); child.prototype.constructor = child; ...


1

You have to define vector layer before you can use it in select definition. Your select definition contains only first statement of vector layer definition, and it's also in the wrong place. First define layer outside select definition, then use it in select definition: var vectorLayer = new ol.layer.Vector( // vector layer defintion options ); var ...


1

I have solved my problem by adding application/json format to Allowed MIME types for a GetFeatureInfo request in geoserver. go to WMS and just add application/json format to Allowed MIME types for a GetFeatureInfo request in geoserver


1

You could simply use your coordinate array to create a linestring import LineString from 'ol/geom/LineString.js'; var route = new LineString(currPath).transform('EPSG:4326', 'EPSG:3857'); But if you need to create a polyline string from a coordinate array var polyline = new Polyline({ factor: 1e6 }).writeGeometry(new LineString(currPath));


1

Previous answer is right. I want only note that in Openlayers 5 this is changed. As noted at https://openlayers.org/en/latest/apidoc/module-ol_proj_Projection-Projection.html, in similar cases you must use proj4.defs('EPSG:2154', '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +...


Only top voted, non community-wiki answers of a minimum length are eligible