openlayers-3

How do I add new line in olx.style.TextOptions text?

三世轮回 提交于 2019-12-24 03:27:20
问题 I have to create label with 2 rows. in OL 2 I've did it by adding '\n' in the text label but it seems that ol3 doesn't support it: new ol.style.Style({ text : new ol.style.Text(/** @type {olx.style.TextOptions} */ ({ text:'line 1 \n line 2' })) }) How can I break the line between 1 & 2 ? 回答1: There is no support in the library currently but people have discussed solutions in the ol3-dev Google group as well as pull requests such as: https://github.com/openlayers/ol3/pull/3538 来源: https:/

GeoJSON feature coordinates not displaying on OpenLayers map

泪湿孤枕 提交于 2019-12-24 01:59:19
问题 I'm trying to display a GeoJSON polygon on a map. I've used the example provided by OpenLayers with the following data, but only the second polygon is displayed: var geojsonObject = { "type": "FeatureCollection", "crs": { "type": "name", }, "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[[103.92240800000013,21.69931],[100.93664,21.66959500000013],[108.031899,18.67076]]] } }, { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[[-5e6, -1e6

openlayers3 how to always enable freehand draw

守給你的承諾、 提交于 2019-12-23 19:36:54
问题 In OpenLayers3 v3.5, how do you always enable freehand draw? The default for enabling freehand draw is done through the freehandCondition property of ol.interaction.Draw , which is currently set to the shift key by default. draw = new ol.interaction.Draw({ source: drawLayer.getSource(), type: 'LineString', freehandCondition: ol.events.condition.shiftKeyOnly }); But I dont want that. I dont want the shift key to be pressed to enable freehand. I want freehand to be enabled by click-and-drag

Openlayers 3. How to make tootlip for feature

浪子不回头ぞ 提交于 2019-12-23 19:13:15
问题 Now I'm moving my project from openlayers 2 to openlayers 3. Unfortunately I can't find how to show title (tooltip) for feature. In OL2 there was a style named graphicTitle . Could you give me advice how to implement tooltip on OL3? 回答1: This is example from ol3 developers. jsfiddle.net/uarf1888/ var tooltip = document.getElementById('tooltip'); var overlay = new ol.Overlay({ element: tooltip, offset: [10, 0], positioning: 'bottom-left' }); map.addOverlay(overlay); function displayTooltip(evt

click event still triggered underneath div

廉价感情. 提交于 2019-12-23 18:04:29
问题 This is a PhoneGap app I'm building that I am testing on my laptop and then on an iphone using PhoneGap cli. I have an openlayers 3 map that records click events on it. I also have a div that masks the whole map when a menu shows. The idea being that when this masking div is clicked/tapped it hides itself but the map below DOES NOT register the click event. What is happening is that the map IS registering the click event so the masking div is hidden but the map then does something else

How do I set crossOrigin attribute when using canvas.toDataURL?

旧巷老猫 提交于 2019-12-23 10:20:05
问题 So I'm trying to create a print map function for an OpenLayers 3 application I'm building. I'm aware of their example but whenever I attempt to use it I run into the dreaded tainted canvas issue. I've read the whole internet and come across folks saying first to set CORS correctly (done and done) but also to do: var img = new Image(); img.setAttribute('crossOrigin', 'anonymous'); img.src = url; The above is described here. My question is, I've never really used toDataURL() before and I'm not

Get all features from the Openlayers 3 viewport

不问归期 提交于 2019-12-23 10:06:50
问题 I am trying to find out all the features which are visible (viewport) on a layer in Openlayers 3. I am able to find out a single feature if I add a click event to the map which is as follows. But I am not able to find all the features which are visible in the viewport. Could anyone help with this? map.on('click', function(evt) { var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) { return feature; }); }); 回答1: I propose that first you get the extent of the view : var

Adding geojson layer to openlayers 3

跟風遠走 提交于 2019-12-23 05:17:17
问题 I have gone through a few different examples on this and nothing ever seems to work. I am trying to simply draw a point on the map using GeoJSON as the source. Here is what I currently have: var staticGeo = new ol.source.GeoJSON(({ object: { type: 'Feature Collection', crs: { type: 'name', properties: {name: 'EPSG:4326'} }, features: [{ type: 'Feature', geometry: { type: 'Point', coordinates: [0,0] } }] }, projection: 'EPSG:3857' })); var vectorSource = new ol.source.Vector({ source:

How to get a pixel's color value from an Openlayers 3 layer?

こ雲淡風輕ζ 提交于 2019-12-23 01:29:14
问题 Is there a way to read pixel color values of an Openlayers 3 layer? Something like this: layerid.getPixelColor(x, y); I'm aware of the getImageData() method used with the canvas, but as far as I can see, this only allows you to get the proper color values of the top layer with 100% alpha. I want to get the colors from lower or even hidden layers. (WMS tiles from same domain.) 回答1: You can set a postcompose handler directly on a layer and read the pixel value from there. I made a small example

How to reload WMTS Tiles after progromattically changing the map center and zoom?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 01:19:12
问题 I'm implementing a feature for users to select a list item that corresponds to a point on the map. I am currently able to set the correct map center and the zoom level but the map tiles are blank until I cause a MouseWheelZoom interaction to occur on the map. How do I get my WMTS layers to update to the new zoom level and map extent? 回答1: In principle, changing the tileUrlFunction of a WMTS source will trigger a refresh, because that clears the tile cache. If you're lucky and your WMTS server