Is there any way to transform from Zoomify (with a specific width and height) to [long, lat] coordinates ?
I saw the documentation (for 3.6) and it seems that ol.proj.transform method does not accept ZOOMIFY as ol.proj.ProjectionLike parameter.
Currently, I have some marker coordinates saved by LeafletJS library into database and I need to project them into [long, lat] coordinates to display them with a OpenLayer 3.6 map. The tiles for the map are the same as it was for Leaflet library.
If needed, here is the code for initiating the ol3 map:
var proj = new ol.proj.Projection({
code: 'ZOOMIFY',
units: 'pixels',
extent: [0, 0, width, height]
}),
map = new ol.Map({
target: this.get('view').$().attr('id'),
view: new ol.View({
projection: proj,
center: [width/2, - height/2],
zoom: 1,
extent: [0, -height, width, 0]
}),
controls: []
});
......
var layer = new ol.source.Zoomify({
url: url,
size: [width, height],
crossOrigin: 'anonymous'
});
map.addLayer(layer);
Also, the code that I'm using to add the markers is:
pos = ol.proj.transform([posX, posY], 'ZOOMIFY', 'EPSG:4326'),
marker = new ol.Overlay({
position: pos,
positioning: 'center-center',
element: domElement,
stopEvent: false
});
map.addOverlay(marker);
I need to mention that I am really new with this framework, so any hint can be helpful.
Thanks,
It seems that you did not need to transform the coordinates since the frameworks know that the coordinates are in the ZOOMIFY format (from the map creation, see above lines).
I solved the problem with the following code:
pos = [posX, posY],
marker = new ol.Overlay({
position: pos,
positioning: 'center-center',
element: domElement,
stopEvent: false
});
map.addOverlay(marker);
Related
I have a map I have created in QGIS 3.8. It is using OSM as the base map and I have a simple raster layer which is a georeferenced map.
QGIS has a useful plugin qgis2web that exports a complete set of files for Openlayers (and Leaflet).
Once in Openlayer format and viewed in a browser it is possible to rotate the complete view to rotate say the north-point 40 degrees (i.e. about 0.7 Radians) east by using Alt+Shift+Drag. You can see a demo of this working here: https://openlayers.org/en/latest/examples/rotation.html
What I am trying to do is to modify the generated code to show the map already rotated to the required angle. (This is because the georeferenced map does not have its north point at the top of the page.)
This is the layers.js code that I am trying to modify, presumably, I need a rotation: 0.7 but I cannot figure out where!
var wms_layers = [];
var lyr_OpenStreetMap_0 = new ol.layer.Tile({
'title': 'OpenStreetMap',
'type': 'base',
'opacity': 1.000000,
source: new ol.source.XYZ({
attributions: '',
url: 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png'
})
});var lyr_MyMap = new ol.layer.Image({
opacity: 1,
title: "King's Park",
source: new ol.source.ImageStatic({
url: "./layers/MyMap.png",
attributions: '',
projection: 'EPSG:3857',
alwaysInRange: true,
imageExtent: [-100073.533268, 6847294.601171, -93832.319311, 6852417.437192]
})
});
lyr_OpenStreetMap_0.setVisible(true);lyr_MyMap.setVisible(true);
var layersList = [lyr_OpenStreetMap_0,lyr_MyMap];
Thank you pavlos
Just adding one line at the end of the body of html file sorted it:
<script>map.getView().setRotation(Math.PI / 2.6 );</script>
I want to limit rendering of a vector layer to a bounding box, but the extent property on ol.layer.Vector does not change the geographic bounds of what is rendered in the vector layer.
Here is a simple example:
var base = new ol.layer.Vector({
source: new ol.source.Vector({
format: new ol.format.TopoJSON(),
url: 'https://gist.githubusercontent.com/quizzicol/7068241/raw/4f6ced3a2412a48141843bee07f6ae2034eea21b/world110.json'
}),
extent: [-180, 0, 180, 70]
});
var map = new ol.Map({
layers: [base],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 1
})
});
And here it is in action: http://codepen.io/mikeskaug/pen/XKOGLN. I expected this to limit rendering to objects in the northern hemisphere, yet the entire world is still rendered.
What am I missing? I'm using OpenLayers 3.17.1
I'm using Openlayer 3.5 and load an OSM map "EPSG:3857".
var extent = [116.826673, 4.854776, 126.748593, 18.697146];
var philiExtent = ol.extent.applyTransform(extent, ol.proj.getTransform("EPSG:4326", "EPSG:3857"));
var view = new ol.View({
center: ol.proj.transform([121.787633, 11.775961], 'EPSG:4326', 'EPSG:3857'),
zoom: 0,
extent: philiExtent,
resolutions: [2560, 1280, 640, 320, 160, 80, 40, 20, 10, 5, 2.5, 1.2, 0.6],
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map'
});
But my features from webService are in "EPSG:4326"
function showData(data) {
var format = new ol.format.WKT();
var feature;
$.each(data, function (i, link) {
feature = format.readFeature(link.geom);
wktTraffic.addFeature(feature);
})
console.log('done load map');
}
So how I make the map be on 4326 or the new feature be on 3857.
I prefer first option.
Check out the FAQ section: http://openlayers.org/en/master/doc/faq.html#how-do-i-change-the-projection-of-my-map-
How do I change the projection of my map?
There is a good chance that you want to change the default projection of OpenLayers to something more appropriate for your region or your specific data.
The projection of your map can be set through the view-property. Here are some examples:
// OpenLayers comes with support for the World Geodetic System 1984, EPSG:4326:
var map = new ol.Map({
view: new ol.View({
projection: 'EPSG:4326'
// other view properties like map center etc.
})
// other properties for your map like layers etc.
});
// To use other projections, you have to register the projection in OpenLayers:
//
// By default OpenLayers does not know about the EPSG:21781 (Swiss) projection.
// So we create a projection instance for EPSG:21781 and pass it to
// ol.proj.addProjection to make it available to the library for lookup by its
// code.
var swissProjection = new ol.proj.Projection({
code: 'EPSG:21781',
// The extent is used to determine zoom level 0. Recommended values for a
// projection's validity extent can be found at http://epsg.io/.
extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
units: 'm'
});
ol.proj.addProjection(swissProjection);
// we can now use the projection:
var map = new ol.Map({
view: new ol.View({
projection: swissProjection
// other view properties like map center etc.
})
// other properties for your map like layers etc.
});
We recommend to lookup parameters of your projection (like the validity extent) over at epsg.io.
To reproject your features to EPSG:3857, you can set the options dataProjection and featureProjection when parsing the features from the WKT string. See also ol.format.WKT#readFeature
var format = new ol.format.WKT();
var feature;
$.each(data, function (i, link) {
feature = format.readFeature(link.geom, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
wktTraffic.addFeature(feature);
})
How is it possible to change the rotation icon (picture), points (Feature) after creating and adding to the map?
Set the rotation icons on create a point I know, but how to change the rotation later?
For uses such as icons, which follows the direction of rotation?
How to do this correctly with respect to performance? (set point again all parameters???)
thanks... very much
Live demonstration:
http://jsfiddle.net/91mLh1j7/
JS Code:
var map = new ol.Map({
target: 'mapID',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({
layer: 'osm'
})
})],
view: new ol.View({
center: ol.proj.transform([14, 50], 'EPSG:4326', 'EPSG:3857'),
zoom: 11
})
});
var Features = [];
// define style for features
var iconStyle = {
src: "http://google-maps-icons.googlecode.com/files/library-publ.png",
anchorOrigin: "bottom-left", // v KML je počítáno od levého spodního rohu
anchor: [0.5, 0],
anchorXUnits: "fraction",
anchorYUnits: "fraction",
scale: 0.9,
opacity: 0.75,
rotation: 45 * 0.01745329251, // in rad / 360° = 6.28318531 rad = 2PI rad
rotateWithView: "true"
};
var point1 = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([14.01, 50.01], 'EPSG:4326',
'EPSG:3857')),
name: 'Point One'
});
point1.setStyle(new ol.style.Style({
image: new ol.style.Icon(iconStyle)
}));
var point2 = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([13.99, 49.99], 'EPSG:4326',
'EPSG:3857')),
name: 'Point Two'
});
point2.setStyle(new ol.style.Style({
image: new ol.style.Icon(iconStyle)
}));
// add point1, point2 to Features
Features.push(point1);
Features.push(point2);
var vectorSource = new ol.source.Vector({
features: Features // add an array of features
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource // add source for vectorLayer
});
map.addLayer(vectorLayer) // add vectorLayer to map
////////////////////
// how to change the rotation of one point (feature) ? after cration point and add it on map
////////////////////
The ol.style.Image class, which the ol.style.Icon extends, has a setRotation method you can use to set the rotation of the icon. You can try this in your example by adding:
Feature1.getStyle().getImage().setRotation(135 * 0.01745329251);
See live on the updated fiddle: http://jsfiddle.net/91mLh1j7/1/
I am trying to make web map application with openlayers 3. I have a problem which i want to fix.
I am loading OSM layer as my base map of the application. But the problem with the OSM layer is that it shows whole world and I can pan my map all around the world.
I want my application to be fixed in certain part. I have map extent set but still it doesn't work.
I am using minZoom but it doesn't help.
Is there any other way to fix this prolem?
var centerpos = [84.2, 28.2];
var newpos = ol.proj.transform(centerpos,'EPSG:4326','EPSG:900913');
var baseLayerOSM = new ol.layer.Tile({
source: new ol.source.MapQuest({
layer: 'osm'
}),
isBaseLayer:true
});
var map = new ol.Map({
layers: [baseLayerOSM],
target: 'map',
controls: [new CustomControl()],
view: new ol.View({
extent:[80.05844110726194,26.34796712822462,88.2015218371264,30.44742963310623],
projection : 'EPSG:900913', // OSM projection
center : newpos,
minZoom:7,
zoom: 7
})
});
This is my code.
AJ
Basically your example should work, but I think you forgot to transform your extent to EPSG:900913 / EPSG:3857 as well.
var maxExtent = [80.05844110726194,26.34796712822462,88.2015218371264,30.44742963310623];
var map = new ol.Map({
layers: [baseLayerOSM],
target: 'map',
controls: [new CustomControl()],
view: new ol.View({
extent: ol.proj.transformExtent(maxExtent, 'EPSG:4326', 'EPSG:900913'),
projection : 'EPSG:900913', // OSM projection
center : newpos,
minZoom:7,
zoom: 7
})
});