Hot answers tagged

6

The order is important. You can't add something to the map before it is defined. Try in this sequence. First define the termini, metroStops var termini = ... ; var metroStops = ...; Then define the basemap, but don't add it to the map yet var osmBase = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'); var baseMaps = { "OSMBaseLayer": osmBase ...


5

As already pointed out in the comments, the problem is that you are directly opening the HTML file in your browser. This will show up like file:///C:/map.html in your address bar. The OSMGeocoder plugin is calling the URL location.protocol+//nominatim.openstreetmap.org/search (see source code). This works on webservers because the location.protocol is ...


3

[Final Answer] I bet you can easily resolve this by setting the map's maxBounds equal to its initial bounds immediately upon loading. :) Just add this to your initializing code once your map variable is ready. map.setMaxBounds(map.getBounds()); [Original Response] When you instantiate your Leaflet map, you just need to pass in a maxBounds option ...


3

Check the proj definition stored in the spatial_ref_sys, it should be different from the one used in the proj4js definition. For example, mine is the following: +proj=utm +zone=30 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs Also epsg.io gives the one with the towgs84 parameters, so I'd change the Proj4js def.


2

This may provide a partial answer. Use the map event listener to listen for zoomend to toggle the state of your bootstrap switch. map.on('zoomend', function (e) { // enable/disable based on zoom level if (map.getZoom()>=5) { $("[name='my-checkbox2']").bootstrapSwitch('disabled',false); } else if ...


2

Do you have "win_url" saved as a property on each feature in states geojson? If so, try: function onclick(e) { window.open(e.target.feature.properties.win_url); }


2

You can use setStyle within the mousemove function: layer.on({ 'mousemove': function (e) { //I want to make the point a red style ? this.setStyle({fillColor:"#ff0000"}); ... } )}


2

what this error tells you is that you've lost the reference to the L.geoJSON layer you have named geoJson. It is not in scope in the geoJsonBounds function. You need to either pass the geoJson layer to the function or define it in a scope this function has access to. Can you post the full code?


2

The basic idea is to listen for the geocoder.input and to create a point based on the result. geocoder.on('geocoder.input', function(ev) { map.getSource('single-point').setData(ev.result.geometry); }); Here's an example demonstrating it: https://www.mapbox.com/mapbox-gl-js/example/point-from-geocoder-result/


1

If any of your GeoJSON features has a code property that is not accounted for by your case statements, then your pointToLayer function will not return a feature, which can produce the error that you are seeing. Adding a default case will prevent this: var allbusinesses = L.geoJson(data, { style: allBusinessesStyle, onEachFeature: onEachFeature, ...


1

Check out turf.js, which should give you the geospatial capabilities to do what you need in browser. In particular, turf.squareGrid and turf.merge and (edited) the extension turf-overlaps. Something like this might get you most of the way there: var poly = <geoJSONPolygon>; var grid = turf.squareGrid(turf.extent(poly), cellWidth, unit); var ...


1

Your bounding box is 100% correct. But, presumably, your map is in EPSG:3857, so you can't use WGS coordinates directly. Transform it to 3857: var ext = ol.extent.boundingExtent([destLoc,currentLoc]); ext = ol.proj.transformExtent(ext, ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:3857')); map.getView().fit(ext,map.getSize());


1

What is the size of your geojson? I think you need to register 'layeradd' map event, this event will be called only after the geojson [or any other layer] is properly added to the map. In this event, you can get the layer object and its extent, and then call map.fitBounds(bounds) to zoom to the layer. Here is the basic code: map.on('layeradd', function (e) ...


1

If the endpoints of your segments are within 5000 km of each other, then pick some suitable midpoint (e.g., the point halfway between the 2 midpoints), and use this as the center of projection for GeographicLib's gnomonic projection. Map the two line segments into this projection and solve the resulting 2d intersection problem. This will give you a good ...


1

No, OpenLayers.js is the code for the openlayers library itself. Somewhere your application loads a .js file that specifies the various layers and map functionality (it is also possible that this is done inline in an HTML file). Try searching through all the files in your application for the text "new OpenLayers.Map" and whatever file contains that text ...


1

It is indeed the sprites. Your Mapbox Studio style probably contains the default sprite set, or none at all if you started with an empty map . If you are using Mapbox Studio, you will use prebuilt sprites provided by Mapbox, or you can upload custom SVG images to build your own sprite. (source) To view or change your sprites you can go to the editor ...


1

In the onClick functions for each, put some code that checks the state of the other check box. If the state of the other checkbox is checked, then perform the code to uncheck and remove the layer and load in the one you want. Apply the same logic for the other check boxes onclick function.


1

Your GeoJSON is not valid, remove the {'geojson': "[]"} wrapper. Not sure if that is the cause of your issue, but try with this GeoJSON instead, and see if that solves it: {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [74.886779, 33.571307]}, "properties": {"rastvalues": 9, "id": 1, "species": ...


1

Ideally, you should be using GeoJSON rather than your own arbitrary JSON. Then, take your Polygon geometries and create Multipolygon geometries—perhaps using the union capability of turf.js. This way, simple polygons that are in fact disconnected parts of the same multipolygon are linked. You can also do this upfront, but it's not clear how you are getting ...


1

I tested a few things in the "Classic 2.5D" version of OSMBuildings which integrates with Leaflet. I was able to achieve what you wanted by starting/loading OSMBuildings quite late. If you want to add circles late or during runtime, you will need to have a FeatureGroup with a dummy circle before calling new OSMBuildings(map).load(), or else they end up on ...



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