Hot answers tagged

42

I found this response - written by a Google employee - this would probably be the most accurate one: This won't be accurate, because the resolution of a map with the mercator projection (like Google maps) is dependent on the latitude. It's possible to calculate using this formula: metersPerPx = 156543.03392 * Math.cos(latLng.lat() * Math.PI / 180) / ...


25

It's simple: create L.Map with scrollWheelZoom: false option, then add a listener: map.once('focus', function() { map.scrollWheelZoom.enable(); }); If you need to toggle zooming: map.on('click', function() { if (map.scrollWheelZoom.enabled()) { map.scrollWheelZoom.disable(); } else { map.scrollWheelZoom.enable(); } });


19

You can do it now, as of version 0.7 there is an additional option called 'maxNativeZoom' after which it will interpolate tiles. Here's a link to the latest documentation for maxNativeZoom Here's the info: minZoom Number 0 Minimum zoom number. maxZoom Number 18 Maximum zoom number. maxNativeZoom Number null Maximum zoom number the tiles source ...


17

Open Preferences > Options menu and go to Cartographic Tools (see the screenshot below - in French). The Zoom factor will be available on the main window. Notice that the minimal value is 1.1 ... 1 would just do nothing and a value < 1 would just unzoom.


14

Sure it is. Depending on what you need: zoom to whole layer right click on layer in Layers list and first item is "Zoom to layer" zoom to selected feature(s) select feature in map and click on icon "Zoom to selection" in the main toolbar or right click on layer in layers list and choose "Open Attribute Table" (there is also icon in the main toolbar/...


13

You need to uninstall 'Tile Map Scale Plugin' :) If you don't have this plugin installed, perhaps the same problem can be caused by another plugin, so try uninstalling all plugins and see if that fixes the problem.


13

More of a comment/improvement on the toggle component of the accepted answer, which is great (thanks). But. When interacting with a map, for many use cases the user also needs to click the map to perform their task, so this: map.on('click', function() { if (map.scrollWheelZoom.enabled()) { map.scrollWheelZoom.disable(); } else { map....


12

Straightforward authoritative correct answer: 591657550.500000 / 2^(level-1) it gives you the table above, entering the zoom level. Try it live on jsfiddle.net Because the question is only for Google MAPS, not EARTH, the OP doesn't care about 3D geometry. Google maps are ALREADY flattened so 1 pixel is always the same distance (in DEGREES, which is what ...


12

All right. I came up with a solution using a layer: var shelter1 = L.marker([55.08, 11.62], {icon: shelterIcon}); var shelterMarkers = new L.FeatureGroup(); shelterMarkers.addLayer(shelter1); map.on('zoomend', function() { if (map.getZoom() <7){ map.removeLayer(shelterMarkers); } else { map.addLayer(shelterMarkers); ...


10

You need to use Rule based style to set the scale for primary, secondary and tertiary network, as you can see below (but with different data): You can double-click each styled label to get more details:


9

Probably: markers.on("click", function (event) { // Assuming the clicked feature is a shape, not a point marker. map.fitBounds(event.layer.getBounds()); }); You may want to detect if the clicked feature is a marker (point feature), and act accordingly, as it will not have the getBounds() method. References: Event object event.layer Note: in the ...


8

One way of doing that (don't know if it's the only way) is by passing an array of available resolutions to the map constructor via the options parameter. Something like... var map = new OpenLayers.Map('map', { resolutions: [0.02197265625, 0.0439453125, 0.17578125] }); A way to get the resolutions you are interested in could be: 1) zoom your map to a ...


8

Your code is not actually selecting anything, you are making a subset view of your data with the MakeFeatureLayer tool. You need to run the selectbyattribute tool on your layer. The desktop help suggests if you want to zoom to selected features in a specific layer you should use this code: df.extent = lyr.getSelectedExtent()


8

you can use it adding to any trigger: var dataExtent = vectors.getDataExtent(); map.zoomToExtent(dataExtent); briefly : map.zoomToExtent(vectors.getDataExtent()); . getDataExtent getDataExtent: function () Calculates the max extent which includes all of the features. . zoomToExtent zoomToExtent: function( bounds, closest ) Zoom ...


8

Something like below should work. vLayer = iface.activeLayer() canvas = iface.mapCanvas() extent = vLayer.extent() canvas.setExtent(extent)


8

If you want to disable doubleClickZoom after map initialization, here is the way: var dblClickInteraction; // find DoubleClickZoom interaction map.getInteractions().getArray().forEach(function(interaction) { if (interaction instanceof ol.interaction.DoubleClickZoom) { dblClickInteraction = interaction; } }); // remove from map map.removeInteraction(...


8

In QGIS 2.14.7 LTR there is an option to completely disable zooming using the mouse wheel from Settings -> Options -> Map Tools -> Panning and Zooming, you need to change Mouse wheel action to Nothing as you can see below: However, the same option is not available in QGIS 2.16.3. But there is a new option called Magnification. When you lock the ...


8

You can pan the map by first selecting it. Then using the "Move item content" tool: While this tool is active as well you can also use the mouse wheel to zoom in and out on the map.


7

Radius @ Equator 6,378,137 meters exact (WGS-84) Circumference at Equator = 40,075,017 meters (2πr) Zoom level 24 uses 2 to the 32 power (4,294,967,296) pixels at circumference. Equatorial Circumference / 2 32 = .009330692 meters per pixel Unit at Latitude = (Cosine of Latitude) X (Unit at Equator) Zoom level doubles each increment. 1 foot (...


7

In OlpenLayers 3 you can just initialize your view with the desired zoom constraints: var map = new ol.Map({ target: 'map', // ... view: new ol.View({ maxZoom: 8, minZoom: 6, zoom: 7 }) });


7

okay. I would go like this: map.on('zoomend', function() { var zoomlevel = map.getZoom(); if (zoomlevel <10){ if (map.hasLayer(points)) { map.removeLayer(points); } else { console.log("no point layer active"); } } if (zoomlevel >= 10){ if (map.hasLayer(points)){ console....


7

In QGIS you can specify macros that will be executed on project startup. To do so go to Project > Project Properties > Macros and enable the checkbox at the top. Then modify the openProject() function like this: def openProject(): from qgis.utils import iface iface.mapCanvas().zoomScale(1000) The "1000" in the zoomScale() function represents your ...


6

When setting up your labels, you'll need to define new label classes, then set up the labels appropriately for each class. Go to the layer properties, then click the Labels tab. Under Method, select this: Then Add a new class, specify the appropriate Scale Range and Label Field - then just rinse and repeat for as many scale-specific labels as you need. ...


6

This now zooms in: mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] lyr = arcpy.mapping.ListLayers(mxd, "Siteslyr", df)[0] arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", ' "gid" = 2739 ') df.zoomToSelectedFeatures()


6

Leaflet.Sleep will make your job easy, and it's plenty configurable Basically, it turns off scroll events when they're not needed and "wakes" your map when they are. I'd post code, but the defaults seem to get it right, so you likely won't need anything beyond <script src="path/to/leaflet-sleep.js"></script> and you'll have a map like this.


6

I have test it a bit and seems to work correct. Inspired from this var res = getResolutionFromScale(200000); alert(res); function getResolutionFromScale(scale){ var units = map.getView().getProjection().getUnits(); var dpi = 25.4 / 0.28; var mpu = ol.proj.METERS_PER_UNIT[units]; var resolution = scale/(mpu * 39.37 * dpi); return ...


6

first you'll have to create your html elements ( buttons, radio, ... ) where you want to put + and -, here is an example using buttons : <button id="zoom-out">-</button> <button id="zoom-in">+</button> then you add a control on each one: var zoomType; document.getElementById('zoom-out').onclick = function() { zoomType="zoom-out"...


6

First, a note about map scales. A map scale represented as a unitless factor (e.g. 1:50000) means that a map unit represents X map units (e.g. a meter in the map = 50 km in reality). This kind of scale is simply impossible to achieve in web maps, as you cannot be sure of the physical screen size. Think about a laptop connected to a projector screen, having ...


6

Yes, I guess the mouse wheel action has become a default setting in QGIS 2.16.x. If you go to Settings > Options > Map Tools > Zoom factor, you will see the minimum value possible is 1.1. Makes sense since a factor of 1 for a given value will remain the same. So let's change the zoom factor to 1 using Python! Paste the following in the Python ...


6

There is no need to alter settings, you can change the zoom factor for the current QGIS session. For QGIS <= v2.18 (see Wheel actions enum): zoomFactor = 3 iface.mapCanvas().setWheelAction( 0, zoomFactor ) # Wheel action, Zoom factor For upcoming QGIS 3, there is a new method (wheel actions have been removed): zoomFactor = 3 iface.mapCanvas()....


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