I am using deck.gl to render a geojsonlayer using their geojsonlayer function, where the source of data is a geojson file.
Now I want display an infowindow to show area & perimeter of each feature, when clicked on them on the map. I have managed to fetch the properties object of a particular feature and show its reverse geocode address and display them in the infoWindow (pic below),
which also gives me access to the geofence coordinates of that particular feature. But I am not able to find any function from the documentation that allows us to calculate the area. Is there anything I missed here? Or Do I have to calculate it manually based on cartesian space and spheroid?
I found turf.js that does the job for calculating area and perimeter of a geojson feature.
Related
I have a list of geojson polygons that i am showing on my map, i am trying to determine, based on the current bounds of the map, if any part of the polygon is on the map. Any ideas as far as functions in the api to determine this?
I have tried the bounds.contains() method but it looks like that needs a specific point rather than an area.
Eric, I think you can get a center point of each polygon and set marker to it. So you can use it to represent a polygon.
In my GEOJSON data layer I have a set of about 20 regions. Each Feature has a GeometryCollection with two geometries: a Polygon to define the region, and a Point that gives the centre of the region.
I want the Polygons to be invisible, but show the Points on the map as markers.
Additionally, I want to be able to set the region markers as visible or invisible depending on zoom level.
Is it possible to show just the Points on the map, and set them visible / invisible separate to the Polygons? I know I can add them to the map as markers the normal way, e.g.
new google.maps.Marker(etc)
but ideally I want to use the stock data layer so I can turn the markers off and on without looping through an array.
GEOJson is basically a "features collection", which means it can contain various features (and feature types: Point, MultiPoint, Polygon, etc.).
In your use case, you could have your Polygons and your points as separate features. You can then do various things with each feature separately. You can remove a feature, or you can override its style.
You can use map.data.getFeatureById('your_feature_id'); then use one of the available methods of the Data layer, for example remove or overrideStyle.
As an example, please check this fiddle that demonstrates how you can add a few points (MultiPoint) and a Polygon to the Data layer, then hide/show only one feature.
Hope this helps.
I need to get features in a certain radius around specific point. Let's say i have an address and need to count all metro stations near this address.
Metro stations are uploaded to mapbox side as a dataset.
How can i list fetch and process these features using mapbox API?
Additional question:
Is there any possibility to get them from mapbox style (layer) attached to map after style is loaded. I can't find right event for fetching renderedFeatures (there is multiple edge cases, when user can zoomin and renderedFeatures will contain less points then fit in 1km radius)
You can access your dataset using the Mapbox Dataset API. This doesn't require Mapbox-GL-JS - it's a totally separate API, and the dataset doesn't need to be displayed anywhere.
You can then use the Turf library to filter points within a certain distance of the address, using the distance() function.
Update
The correct answer these days is to use the tileQuery API, which takes a radius parameter.
i´m trying to create a map based on LeafletJS. I need some shapes rendered in the map.
I need - for example "Kreis Wesel" (part of germany) in my map. I downloaded shapefiles from http://www.gadm.org/country and imported them into OpenJump. Fine - they are displayed correctly in the GUI.
When i copy the area to clipboard an format id as JSON (with my texteditor) and parse it width 'L.polygon(var).addTo(map', the polygon is created correctly - but in the Indian Ocean, not in Germany.
Any ideas wheres my fault?
Well it seems you can find info in that previous thread
first two lines: " Is there a service that can provide custom tiles in the EPSG:4326 projection? I've looked at Cloudmade and it would be the ideal solution but their tiles are using Spherical Mercator"
The shapes you downloaded are in lat/lon coordinates epsg:4326 whereas your base layer OpenStreetMap uses Spherical mercator epsg:3857
Change your shape's epsg with your favorite GIS software.
I have a polygon and polyline created dynamically. Now I need to check whether they both intersect each other or not.
When a user comes and places a marker i'm creating a polygon with some radius as the buffer distance. I have the polylines(routes) pre defined in my database. I need to get that polylines and check whether they are intersecting or not.
I didn't find any kind of methods in the google maps v3 API. someone please help me for the same.
Thanks,
Karthik Reddy
Good starting point is checking if a point is in a polygon. Below is a link which shows it done for a point. Since a line is a collection of points you have to check an array of points would have to modify the code below to check an array of points (your polyline)
https://web.archive.org/web/20160414021100/http://blog.appdelegateinc.com/point-in-polygon-checking-with-google-maps.html
(note this works with api v2) but it could be easily converted to v3