I have a problem and I don't know very well to solve.
var deletedFeatures = [];
var nuevaRegionId = -1;
var featureID = -1;
var extent = [0, 0, 650, 366];
var projection = new ol.proj.Projection({
code: 'xkcd-image',
units: 'pixels',
extent: extent
});
var map = new ol.Map({
layers: [
new ol.layer.Image({
source: new ol.source.ImageStatic({
attributions: [
new ol.Attribution({
html: '<a href="http://www.somepage.com/">More</a>'
})
],
url: "<?php echo $img ?>",
projection: projection,
imageExtent: extent
})
})
],
target: 'map',
view: new ol.View({
projection: projection,
center: ol.extent.getCenter(extent),
zoom: 2,
minZoom: 1,
maxZoom: 4
})
});
The problem is that I have the features saved from an image of 700px x 500px
When I add this feature it isn't drawn at the corresponding pixel of the image.
[[[432.275390625,268.188476562],[407.51953125,56.8115234375],[469.091796875,53.0029296875],[484.9609375,262.475585938],[432.275390625,268.188476562]]]
If i draw manually has different values.
Is there any way to draw features in pixels and not in openlayers metrics?
To save the features:
var features = featureOverlay.getSource().getFeatures();
var format = new ol.format["GeoJSON"]();
data = format.writeFeatures(features);
I solved my problem with var extent = [0, 0, 650, 366]; this has to be the same as the image width and height and the other problem was te axis, for me was X,Y from botton-left to up, and for them from top-left to bottom
var extent = [0, 0, 650, 366]; --> this needs to be same as the image, get the height and width and enter there.
Then in my case, the x,y coord I recieved where from top-left(0,0) and in OpenLayers the (0,0) was bottom-left
for example: If the image was 500x500, and the rectangle coord I recieved was: [0,0][0,100],[100,100],[100,0] for me the correct coords in OpenLayers where: [[0,0],[0,400],[0,400],[100,400],[0,0]] for me the Y was = 500-y = 400.