How to apply bounding box filter in leaflet WMS? - maps

There is a working example in leaflet site for adding WMS Layer in leaflet map at :
http://leafletjs.com/reference.html#tilelayer-wms. But I don't see methods to provide the filter for bounding box.
Is there a way to provide bounding box filters for Leaflet WMS ?

Just add bbox: [-180,-90,180,90] to the L.tileLayer.wms options.
Example:
var layer_SOEST_SurfaceTemp = L.tileLayer.wms("http://...............", {
layers: 'tmpsfc',
format: 'image/png',
transparent: true,
opacity: 0.5,
crs: L.CRS.EPSG4326,
bbox: [-180,-90,180,90],
styles: 'boxfill/alg',
attribution: "SOEST Hawaii",
time : forecast_datetime,
version : '1.3.0'
});

Just add the desired parameters to your L.tileLayer.wms options even if not shown in the API... Thoses parameters will be passed anyway to your map server and if this server support bbox or any others parameters provided it will return you the correct tiles...

You can use the option bounds to filter.
If set, tiles will only be loaded inside the set LatLngBounds.
L.TileLayer and L.TileLayer.WMS are both extending L.GridLayer, so the same options can used: https://leafletjs.com/reference-1.7.1.html#gridlayer-bounds
var nexrad = L.tileLayer.wms("URL.COM", {
layers: 'LAYER_NAME',
format: 'image/png',
transparent: true,
attribution: "Weather data © 2012 IEM Nexrad",
bounds: L.latLngBounds([[1,0],[0,1]])
});

Related

When a tile is 404, openlayers zoom in the previous tile image instead of hide it

I am using OpenLayers with OSM and Geoportail. I display OSM at the bottom and Geoportail on top.
In France I have no problem but in others country Geoportail has no tiles for big zoom. In this case Geoportail return 404, openLayers keep the previous tile/image and zoom inside :/
I wish to hide the Geoportail tile when the tile doesn't exist, this way I will see the OSM tile.
Any idea how to do it ?
My code to add the both layers :
layers: [
new OlTile({
'title': 'OSM',
source: new OlOSM()
}),
new OlTile({
source : new WMTS({
url: 'https://wxs.ign.fr/pratique/geoportail/wmts',
layer: 'ORTHOIMAGERY.ORTHOPHOTOS',
matrixSet: 'PM',
format: 'image/jpeg',
projection: 'EPSG:3857',
tileGrid: new WMTSTileGrid({
origin: [-20037508, 20037508],
resolutions: resolutions,
matrixIds: matrixIds,
}),
style: 'normal'
})
})
],
Thank you
As Mike say it in his comment : using "useInterimTilesOnError: false" solve the problem.

Is it possible to display mapbox coordinates inside a dynamic url?

I'm working on a mapbox app and I need to make a dynamic URL to reflect mapbox info like lat, long and zoom level.
ex: /?city=London&zoom=1&lat=30&lng=140. On page load map should be centred and zoomed accordingly. How to read/write page URL?
Just activate the hash : true in the Map initial settings
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/outdoors-v11',
center: [128, 47],
zoom: 16.5,
pitch: 60,
hash: true // just add this
});
It’s not the same param names but you’ll have the same information

Mapbox react - Display route with adjustments to nearest road using list of location points

I'm using mapbox with the wrapper react-map-gl.
I'm trying to draw a route with my array of lat lang points,
I found a partial solution from:
https://github.com/visgl/react-map-gl/issues/591#issuecomment-454307294
The issue is that the presented route doesn't match the nearest road.
The current route is the green line and I'm trying to change it to be like the orange line
The best solution I have found is to use the react-map-gl with the deck.gl libraries.
decl.gl,
react-map-gl
install the libraries
Create a function using the Matching API from Mapbox:
https://docs.mapbox.com/help/tutorials/get-started-map-matching-api/#add-the-map-matching-api
Use the geometries=geojson option param (inside the URL of the matching call)
return the geometry object from Matching API response (data.matchings[0].geometry)
Create GeoJsonLayer with the new geometry object:
const layerRoute = new GeoJsonLayer({
id: "geojson-layer",
data: getMatchingGeometry(),
filled: true,
stroked: false,
extruded: true,
pickable: true,
lineJointRounded: true,
getRadius: 50,
getElevation: 30,
lineWidthScale: 20,})
Add the new layer to your map:
return (
<DeckGL layers={[layerRoute]} initialViewState={{ ...initialView }} controller={true}>
<StaticMap
height={height}
width={width}
mapStyle={mapboxstyle}
mapboxApiAccessToken={API_TOKEN}
/>
</DeckGL>)

How to use the new Grayscale maps

The Azure maps blog states Grayscale maps: A dark-gray map style is for users who want to have a darker scale representation of a map.
How can you enable this in the Javascript implementation?
see the code sample at https://codepen.io/azuremaps/pen/WKOQRq. We will have
documentation up soon.
style: "grayscale_dark"
You can set style: "grayscale_dark" when you define the map.
var map = new atlas.Map("map", {
center: mapCenterPosition,
zoom: 15,
style: "grayscale_dark"
});
You can also just create a control on the map that allows you to switch between different modes:
map.addControl(new atlas.control.StyleControl(), { position: "top-right" });

Google Maps GOverviewMapControl() and GAdsManager

I have a GMap2 object with a GOverviewMapControl and a GAdsManager, but they both appear in the lower right hand corner.
How can I get them to appear in different parts of the map?
Here's my Overview:
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GOverviewMapControl());
map.enableDoubleClickZoom();
here's my Ads
var adsManagerOptions = {
maxAdsOnMap: 2,
style: 'adunit',
channel: 'XXXXXXXXX'
};
adsManager = new GAdsManager(map, publisherID, adsManagerOptions);
adsManager.enable();
The position property of the GAdsManagerOptions class will allow you to set the position of the GAdsManager. The options are passed in to the GAdsManager constructor.
Unfortunately, the GOverviewMapControl is not as flexible. According to the documentation, "Unlike other controls, you can only place this control in the bottom right corner of the map (G_ANCHOR_BOTTOM_RIGHT)."
I have no way to test this at the moment, but your options will probably look something like:
var adsManagerOptions = {
maxAdsOnMap: 2,
style: 'adunit',
channel: 'XXXXXXXXX',
position: new GControlPosition(G_ANCHOR_BOTTOM_LEFT)
};

Resources