#AddTo
Related
October 31, 2026 at 6:22 PM
I must addto tha "be carefol' commints, head injuries are no joke
October 27, 2026 at 9:57 PM
Editing a GeoJSON layer that I just added to the map
I have created a Leaflet map and added a GeoJSON layer like this. var map_rgb = L.map("map_rgb",{center: [userLat, userLon],crs: L.CRS.EPSG3857,zoom:'{{zoom}}',zoomControl: true,preferCanvas: false,}); var tile_layer_google_map = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', { maxZoom: 23, subdomains:['mt0','mt1','mt2','mt3'],"attribution": "Google Satellite"}).addTo(map_rgb); var building_layer = L.geoJson(bldgs, {color: "#FF0000", weight: 3, fill: false}); var drawnItems = new L.FeatureGroup(); building_layer.addTo(drawnItems); map_rgb.addLayer(drawnItems); //drawnItems.enableEdit(); var drawControl = new L.Control.Draw({ draw: { polygon: { shapeOptions: { color: 'red', fill: false, }, allowIntersection: false, drawError: { color: 'orange', timeout: 1000 }, showArea: true, metric: false, repeatMode: true, }, edit: { featureGroup: drawnItems } }); map_rgb.addControl(drawControl); map_rgb.on(L.Draw.Event.CREATED, function (e) { var type = e.layerType, layer = e.layer; drawnItems.addLayer(layer); }); I would like to edit the polygons in the geojson building_layer (modify vertices of existing polygons and also add new polygons). However, when I click the edit button, the polygons in the building_layer are not showing as editable. I am only able to add new polgyons. How can I make the building_layer editable?
gis.stackexchange.com
October 16, 2026 at 8:03 AM
September 19, 2026 at 12:40 AM
Leaflet control search clash with map.on zoomend function
I would like to know how to solve the clash between Leaflet control plugin and map.on zoomend function The problem is related to this query: Displaying selected layers depending on zoom in Leaflet and as it has been solved, there is still one issue to fix. I discovered, that once the leaflet search plugin is attached to the map: L.control.search({ layer: L.layerGroup([job2]), initial: false, propertyName: 'myKey', zoom: 18, position: 'topleft' }).addTo(map); the map.on('zoomend', function() { doesn't work at the very initial stage (when open or refresh the map to default link). The problem is shown in the image below: Under the zoom level 7 all dots are still visible, whereas I set zoomend for zoom 9. When I start zooming in/out on the map, it starts work correctly as perr below: My code looks as follow: L.control.search({ layer: L.layerGroup([job2]), initial: false, propertyName: 'myKey', zoom: 18, position: 'topleft' }).addTo(map); map.on('zoomend', function() { if (map.getZoom() < 9){ if (map.hasLayer(job2)) map.removeLayer(job2); } else { if (document.querySelector("input[name=vm]").checked && !map.hasLayer(job2)) map.addLayer(job2); } }); When enter the leaflet-search.js plugin, I see the section, which I believe is responsible for this affliction: showLocation: function(latlng, title) { //set location on map from _recordsCache var self = this; /* self._map.once('moveend zoomend', function(e) { if(self._markerSearch) { self._markerSearch.addTo(self._map).setLatLng(latlng); } }); */ self._moveToLocation(latlng, title, self._map); //FIXME autoCollapse option hide self._markerSearch before visualized!! if(self.options.autoCollapse) self.collapse(); return self; } Regarding to this I switched off part of the code with: self._map.once('moveend zoomend', function(e) { but the problem remains the same. Could somebody advice how to remove this issue and make the layers hidden at the initial stage (after refreshing the map)? Link to my map is here: https://mariusz-krukar.mkrgeo.pl/en/workshop/media/MDU_demo.html#55.21022,-1.57385,6z Once open, you will see the dots still visible, whereas zoom level is 6. When yoyu turn into zoom 7 and back to zoom 6 they will be gone until refresh the map.
gis.stackexchange.com
September 18, 2026 at 6:01 AM
View vector GeoServer line layer in Leaflet
I have simple line layer created based on shapefiles. It can be viewed in GeoServer with OpenLayers preview: I also can be imported and correctly viewed in QGIS. I tried to visualize this layer over OSM map in my leaflet: var map = L.map('map', ); map.setView([35.6, 25], 8); L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: 'Map data &copy; OpenStreetMap contributors' }).addTo(map); var WMSe = "http://xx.xxx.xx.xxx:8080/geoserver/wms"; var OHLayer = L.tileLayer.wms(WMSe, { layers: 'fch:OHL-fch', format: 'image/png', transparent: true, format_options: 'layout:message', attribution: "Algum texto de teste", layout: 'message', }).addTo(map) where fch:OHL-fch in name of layer in layer preview in GeoServer. When I run this, all I get is OSM map without line layer. Any help in resolving this is appreciable. Geoserver preview request: http://xx.xxx.xx.xxx:8080/geoserver/fch/wms?service=WMS&version=1.1.0&request=GetMap&layers=fch%3AOHL-fch&bbox=23.6974544525146%2C35.0042533874512%2C26.1459541320801%2C35.4908332824707&width=768&height=330&srs=EPSG%3A4326&styles=&format=application/openlayers leaflet request(NOT working): URL: http://xx.xxx.xx.xxx:8080/geoserver/wms?service=WMS&request=GetMap&layers=%20fch%3AOHL-fch&styles=&format=image%2Fpng&transparent=true&version=1.1.1&format_options=layout%3Amessage&layout=message&height=256&width=256&srs=EPSG%3A3857&bbox=2191602.4749925733,4226661.916057106,2348145.5089206146,4383204.949985149 leaflet request(working): URL: http://xx.xxx.xx.xxy:8080/geoserver/wms?service=WMS&request=GetMap&layers=%20fch%3AOHL-fch&styles=&format=image%2Fpng&transparent=true&version=1.1.1&format_options=layout%3Amessage&layout=message&height=256&width=256&srs=EPSG%3A3857&bbox=2817774.6107047372,3913575.848201024,2974317.644632778,4070118.8821290666 Print of leaflet layer: _container: _crs: {latLngToPoint: function, pointToLatLng: function, project: function, unproject: function, scale: function, …} _events: {remove: Array} _fadeFrame: 163 _globalTileRange: {min: Object, max: Object, extend: function, getCenter: function, getBottomLeft: function, …} _initHooksCalled: true _leaflet_id: 83 _level: {el: , origin: Object, zoom: 8} _levels: {8: Object} _loading: false _map: e {options: Object, _container: , _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …} _mapToAdd: e {options: Object, _container: , _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …} _noPrune: false _onMove: function() _tileSize: {x: 256, y: 256, clone: function, add: function, _add: function, …} _tileZoom: 8 _tiles: {145:100:8: Object, 145:101:8: Object, 144:100:8: Object, 146:100:8: Object, 144:101:8: Object, …} _url: "http://xx.xxx.xx.xx:8080/geoserver/wms" _wmsVersion: 1.1 _wrapX: [0, 256] (2) _wrapY: undefined _zoomAnimated: true options: {layers: "fch:OHL-fch", format: "image/png", transparent: true, format_options: "layout:message", attribution: "Algum texto de teste", …} wmsParams: {service: "WMS", request: "GetMap", layers: "fch:OHL-fch", styles: "", format: "image/png", …}
gis.stackexchange.com
July 31, 2026 at 2:08 AM
Alt text
June 19, 2026 at 3:15 AM
Editing a GeoJSON layer that I just added to the map
I have created a Leaflet map and added a GeoJSON layer like this. var map_rgb = L.map("map_rgb",{center: [userLat, userLon],crs: L.CRS.EPSG3857,zoom:'{{zoom}}',zoomControl: true,preferCanvas: false,}); var tile_layer_google_map = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', { maxZoom: 23, subdomains:['mt0','mt1','mt2','mt3'],"attribution": "Google Satellite"}).addTo(map_rgb); var building_layer = L.geoJson(bldgs, {color: "#FF0000", weight: 3, fill: false}); var drawnItems = new L.FeatureGroup(); building_layer.addTo(drawnItems); map_rgb.addLayer(drawnItems); //drawnItems.enableEdit(); var drawControl = new L.Control.Draw({ draw: { polygon: { shapeOptions: { color: 'red', fill: false, }, allowIntersection: false, drawError: { color: 'orange', timeout: 1000 }, showArea: true, metric: false, repeatMode: true, }, edit: { featureGroup: drawnItems } }); map_rgb.addControl(drawControl); map_rgb.on(L.Draw.Event.CREATED, function (e) { var type = e.layerType, layer = e.layer; drawnItems.addLayer(layer); }); I would like to edit the polygons in the geojson building_layer (modify vertices of existing polygons and also add new polygons). However, when I click the edit button, the polygons in the building_layer are not showing as editable. I am only able to add new polgyons. How can I make the building_layer editable?
gis.stackexchange.com
May 31, 2026 at 8:08 PM
Interactivity in CartoDb with createLayer method?
I have a problem with my interactivity and I can't solve alone. When mouse hover are on any point I would like show by console.log any column of my dataset. With my code, only show me cartodb_id. var map; function init(){ // initiate leaflet map map = new L.Map('cartodb-map', { center: [40,-98], zoom: 4 }) L.tileLayer('https://dnv9my2eseobd.cloudfront.net/v3/cartodb.map-4xtxp73f/{z}/{x}/{y}.png', { attribution: 'Mapbox Terms &amp; Feedback' }).addTo(map); var layerUrl = 'https://mcnb.cartodb.com/api/v2/viz/85aef586-5c57-11e5-9915-0e73ffd62169/viz.json'; // change the query for the first layer var subLayerOptions = { sql: "SELECT * FROM mcnb_dev", cartocss: "#example_cartodbjs_1{marker-fill: #109DCD; marker-width: 5; marker-line-color: white; marker-line-width: 0;}" } cartodb.createLayer(map, layerUrl) .addTo(map) .on('done', function(layer) { layer.on('featureOver', function(e, pos, pixel, data) { // print data to console log console.log("Event #" + data.cartodb_id + ", Name " + data.name + ", Clase: " + data.class+ ",Incertidumbre(m.) " + data.coordinateuncertaintyinmeters ); }); // change the query for the first layer var subLayerOptions = { interactivity: "cartodb_id,class,coordinateuncertaintyinmeters", sql: "SELECT * FROM mcnb_dev", cartocss: "#example_cartodbjs_1{marker-fill: #109DCD; marker-width: 5; marker-line-color: white; marker-line-width: 0;}" } var sublayer = layer.getSubLayer(0); sublayer.set(subLayerOptions); // sublayer.infowindow.set('template', $('#infowindow_template').html()); sublayer.on('featureClick', function(e, latlng, pos, data) { alert("Hey! You clicked " + data.cartodb_id); }); }).on('error', function() { //log the error }); } SubLayer featureClick works but featureOver not.
gis.stackexchange.com
May 30, 2026 at 1:10 AM
Leaflet control search clash with map.on zoomend function
I would like to know how to solve the clash between Leaflet control plugin and map.on zoomend function The problem is related to this query: Displaying selected layers depending on zoom in Leaflet and as it has been solved, there is still one issue to fix. I discovered, that once the leaflet search plugin is attached to the map: L.control.search({ layer: L.layerGroup([job2]), initial: false, propertyName: 'myKey', zoom: 18, position: 'topleft' }).addTo(map); the map.on('zoomend', function() { doesn't work at the very initial stage (when open or refresh the map to default link). The problem is shown in the image below: Under the zoom level 7 all dots are still visible, whereas I set zoomend for zoom 9. When I start zooming in/out on the map, it starts work correctly as perr below: My code looks as follow: L.control.search({ layer: L.layerGroup([job2]), initial: false, propertyName: 'myKey', zoom: 18, position: 'topleft' }).addTo(map); map.on('zoomend', function() { if (map.getZoom() < 9){ if (map.hasLayer(job2)) map.removeLayer(job2); } else { if (document.querySelector("input[name=vm]").checked && !map.hasLayer(job2)) map.addLayer(job2); } }); When enter the leaflet-search.js plugin, I see the section, which I believe is responsible for this affliction: showLocation: function(latlng, title) { //set location on map from _recordsCache var self = this; /* self._map.once('moveend zoomend', function(e) { if(self._markerSearch) { self._markerSearch.addTo(self._map).setLatLng(latlng); } }); */ self._moveToLocation(latlng, title, self._map); //FIXME autoCollapse option hide self._markerSearch before visualized!! if(self.options.autoCollapse) self.collapse(); return self; } Regarding to this I switched off part of the code with: self._map.once('moveend zoomend', function(e) { but the problem remains the same. Could somebody advice how to remove this issue and make the layers hidden at the initial stage (after refreshing the map)? Link to my map is here: https://mariusz-krukar.mkrgeo.pl/en/workshop/media/MDU_demo.html#55.21022,-1.57385,6z Once open, you will see the dots still visible, whereas zoom level is 6. When yoyu turn into zoom 7 and back to zoom 6 they will be gone until refresh the map.
gis.stackexchange.com
May 13, 2026 at 2:14 AM