Google Maps v3 Polygon, Polyline intersection - javascript

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

Related

Calculate area & perimeter of a geojson feature of GeojsonLayer in deck.gl

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.

Is there a way to check if any part of a data layer in google maps is within the bounds of the map?

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.

Exact same coordinates on Google Maps API

I am using the Google Maps API through the Biostall Library. I am also using the MarkerClusterer function in it.But if I have a couple markers on the exact same location the markers won't split up. What would be the best way to solve this? I was thinking of adding a small random number to those exact same coordinates so that they would be seperate.
Why do you think they should split up?
If they are closer than MarkerClusterer's minimum distance (a configurable option) and you are above the maximum zoom (also a configurable option) and your minimum cluster size is 2 (yup, configurable too) then those two markers should appear as a blue cluster of two.
If you zoom enough, you won't see the cluster anymore, just the markers (which is an indication that MarkerClusterer is showing you the original markers). And if the clusters are in the same position, then it isn't up to MarkerClusterer to split them.
Perhaps you should give a look at OverlappingMarkerSpiderifier for that funcionality.

Map layer in Leaflet.js not appearing - why?

I've got a brief query and hope you can help. I'm trying to create a map and thought Leaflet.js provided a simple method for a non-developer to illustrate some data I want to plot.
You can see the results here:
http://www.thisisstaffordshire.co.uk/images/localpeople/ugc-images/275796/binaries/WarGraves3.html
The data points land just as they need to, but the underlying map doesn't show. Can anyone see why?
I've got an API key but the map layer doesn't appear to load.
What have I done wrong?
Regards
David
The underlying map is drawn but the tiles are getting mixed up. (You can see this when you zoom out of the map.)
You mixed up the tiling parameters of the CloudMade URL. You have:
http://{s}.tile.cloudmade.com/{your-key}/997/256/{x}/{y}/{z}.png
But it should be:
http://{s}.tile.cloudmade.com/{your-key}/997/256/{z}/{x}/{y}.png
This is important because the parameters specify the tile that is loaded by the URL. Z is the zoom level. X and Y the appropriate tile.

Google MAPS API V3 -- > How Can I count the number of Markers inside a Polygon?

i think the question is clear enough .
I have some polygons in my Map , I have also some markers .
I want to count the amount of markers that are in every Polyogn .
The only way of doing this without prior preparation is to iterate through your collection of markers and use point-in-polygon analysis with each polygon until you find which polygon contains that marker. Keep a running total for each polygon.
Prior preparation to make this easier would be to maintain a record of which polygon contained the marker when you added that marker. You could do that with a custom attribute of the marker — marker.containedBy, for example — or the polygon (add the marker to an array attached to the polygon: something like polygon.containsMarkers=[]). Or even both.

Categories

Resources