Create Polygon on Google Map By dragging mouse - c#

I am first time using Google Map..
I have to add the Google Map in my web application with following functionality.
User can create polygon on the Map by using Mouse.
Then the values of polygon's Lat/Lon will be saved in the Database.
Like wise he can create multiple polygons but with the restriction that any polygons should not be overlapped.
Please help me on it..
Thaks in advance

As far as rendering the polys I would consider using a open source tool kit that already does that . Open Layers is a nice javascript library that works with Google Maps enables you to draw overlays and collect lat lon information, etc. As far as the database entries and overlapping issues see the comments on your question.

Related

How to map a user location to a not true to realism map?

I'm sorry if this question is broad but I have not been able to find any real solutions to the problem I must solve. I need to solve the problem of mapping a user's location to an image that represents a map (like an amusement park map).
One possible solution would be to define GPS coordinates to different parts of the image and then snap the user's location to the closest defined location.
Something else I saw was Geospatial PDF's but I couldn't find much on implementing a way to read Geospatial information from the PDF.
How can I take an image that represents lets say a theme park and map a user's location to it?
Short answer:
You can't, by which I mean you can't just take a regular image and snap co-ordinates to it's pixels.
Long answer:
You can, but it takes a lot of work and preparation, here's the basics of what you need to do.
STEP 1 - Georefrence the image
To do this you need some GIS software, and an existing map of the area that's registered in the correct co-ordinate space.
If you have the budget, then you should consider using professional software such as Autodesk map 3D or the ESRI suite of tools. If you don't have a budget, you can do this using free tools such as QGIS.
I'll assume QGis for this description.
Load the existing map that you have for the area (The one that's already referenced) into your GIS Package. (How and where you get this map from is entirely up to you, if your lucky you might have one someone else did, or the builders of your park might have site plans you can use, without this source map however, you can forget any chance of matching the image to it unless you have a list of all the points you want to reference) [SIDE NOTE: It's perfectly feasible to go out with a GPS device and record your points manually, esp if the site your mapping is not to big and you have full access to it, since your only referencing an image of your own, and not building anything then super, duper 1000% accuracy is not needed]
Assuming the use of QGis, go up to the "Raster" menu, and select the "GeoReferencer" tool
Once the tool loads, you'll be presented with a child window that allows you to load your "Un-referenced" map image into it. (The load button is marked with a red arrow)
Once you have your raster image loaded, you then need to use the already referenced map you loaded into QGis (Sorry no space to document this part, there are a multitude of ways, depending on what data you have) and pick points from it that match the raster, in your georeferencer tool.
Make sure the georeferencer tool is in add point mode.
Then click on the image that you loaded into your geo-referencing tool, at the location where you want your first point.
The enter map co-ordinates box will pop open.
If you already know the location of these points (For example because you went out with a GPS, or you have some survey data) then you can simply just type them in. If not, then click the button marked "from map canvas", and the geo-reference tool will switch to the already referenced map you have loaded, and ask you to click on the same location on the referenced map.
Once you click on the referenced map, QGis will then switch back to the Geo-reference tool with the co-ordinates filled in
At this point, you can click "OK" and the point will be registered on your un-referenced raster image as a referenced point (Small red dot)
Repeat this process, until you have as many locations as you want referenced. You don't have to do everything, but key locations, such as park entrances, corners around the main site outline, centers of prominent buildings and road junctions should be done.
The more points you reference, the more accurate the final referenced raster image will be.
Once you've finished adding the points to your image to reference it, you then need to click the yellow cog wheel, and fill in the options for the output raster, target SRS and other things that will turn this into a map.
Now, at this stage I've not mentioned a VERY, VERY, VERY important concept, and that's the "SRS" otherwise known as the "Spatial Reference System"
You may have noticed in my screen shots above, when the co-ordinates were entered in the dialog by clicking on the map, that they did not look like the usual latitude/longitude pair that a phone or GPS unit might produce.
That's because ALL of my maps are in an SRS known as "OSGB36" (or EPSG:27700), which is the local spatial reference system for the united kingdom.
I could have if I'd wanted to, used the standard GPS system (Known as WGS84 or 'EPSG:4326') but because I'm working only within the UK, doing that would actually have cause errors in my calculations.
If your working with something a small as an Amusement park, then for best results you NEED to find what your local geographic co-ordinate system is, using standard GPS co-ordinates will cause too many errors, and might even lead to incorrect location plotting when you finally plot your point on your image.
There's simply far too much info for me to put into an SO post, so I would strongly suggest that you grab a free copy of the EBook I've written on the subject from here:
https://www.syncfusion.com/resources/techportal/details/ebooks/gis
That will fill in a large amount of the background knowledge you need, in order to do this.
Once you've set your settings, and added all your reference points, your then ready to create your referenced raster image, by simply clicking on the green triangle
Once you get to this point, and your referenced image is saved, you will now have a map/image that should be referenced in your local co-ordinates, and can understand a point given to it in the same co-ordinate system, and know where to plot it on a map.
That however, is only the start of your journey.
STEP 2 - Build a map server
Once you have the image, you then need to host in something called a WMS server.
Again, describing how to do this from the ground up in an SO post is simply just not practical, what you need is something like "geoserver" (A Java based easy to use map server system) or something like a bare bones linux system, with apache webserver installed and the mapserver CGI binary application to run under it.
Once you have a map server set up, and serving maps using the WMS protocol, you can then move onto the final stage
STEP3 - Creating your application to display the map
The final part of the equation is to build an application to display the map from your WMS server, and then take the location of the person or item you want to plot, optionally convert the co-ordinates to the local SRS that matches your image, then plots the dot over the image in the correct location.
If your doing this in a web/mobile application, then you'll most likely want to investigate the use of openlayers.js or leaflet.js, if your doing this in a C# application, then GreatMaps or SharpMap are the toolkits you want to be looking at.
Wrap up
Many folks think that plotting locations onto a map image is a quite straight forward and simple task, I can tell you now it's not.
Iv'e built many GIS systems over the years, and even the simplest of them has taken me over 3 months.
Even a simple idea such as the one your asking about, takes tremendous amounts of planning and analysis, there is no quick way of doing this unless you simply just want to host a google maps image on your web page, and match your device co-ordinates up to that.
The second you start to produce custom maps, you automatically set yourself up for a lot of work, that's going to take you time and patience to get it right.
Pixels in images simply don't match up to real world co-ordinates, and the truth of the matter is simple. There's a reason why mapping and GIS companies charge as much as they do to create systems like this.
References and further reading
http://www.qgistutorials.com/en/docs/georeferencing_basics.html
http://www.digital-geography.com/qgis-tutorial-i-how-to-georeference-a-map/
http://glaikit.org/2011/03/27/image-georeferencing-with-qgis/
http://geoserver.org/
http://mapserver.org/uk/index.html
http://openlayers.org/
All the best with your project, and please know this, your in for a lot of work, but your also going to have a lot of fun, and learn heaps of new stuff, the world of GIS is by it's very nature complicated, but it's also a very fascinating subject, especially when you start drawing your own maps from scratch :-)
Shawty
If your map image represents a not so large area, then I would think of this as a rectangle.
It would be just a matter of transforming your Lat/Lng coordinates to (x,y) coordinates inside your image.
Lat2 |----------------------------|
| |
Lat1 |----------------------------|
Long1 Long2
Assign the real world Lat/Long coordinates to each corner of your map:
Bottom Left Corner = Lat1, Long1
Bottom Right Corner = Lat1, Long2
Upper Left Corner = Lat2, Long1
Upper Right Corner = Lat2, Long2
Given the user longitude and latitude and knowing the width and height of your image, you can calculate the transformed (x,y) coordinates over the image:
x = User Longitude * Image Width / |Long2 - Long1|
y = User Latitude * Image Height / |Lat2 - Lat1|
You should now be able to put a pin over that (x,y) position.

Remove labels in gmap.net

I'm building an application where I'm using gMap.net (not google maps). I need a totally physical map where there are no labels. All the mapProviders are showing labels. As in the attached picture you can see few landmarks are there. Is there any way to remove them.
Afaik the map data is provided as is, there's no option of actually peeking into the map layers delivered by the map providers.
If the satellite-only imagery is not an option, have you looked at either of those:
ArcGIS_World_Physical_Map
ArcGIS_World_Shaded_Relief_Map
ArcGIS_World_Terrain_Base_Map
Depending on the zoom level these might be a neutral option.

Show Leaflet images in C# app

I have a Leaflet website that uses a custom tile set for a game map.
I want to display in my C# client app, tiles from the Leaflet map using basically the same algorithm, as if re-creating leaflet in C#.
I already have the placeholder tiles layed out in a grid and have basic navigation, but running into the problem of knowing the tile values to use for the URL (from leaflet docs):
'http://map.somedomain.com/{layer}/{z}/{x}/{y}.png'
I have the layers names, and I want to know the exact X,Y for each tile from a provided zoom level.
How can I calculate this so that when I send out a download request it doesn't hit file not found?
Hope that makes sense.
Thank you.
PS: I don't have access to windows forms, I am using Unity3D engine, if that makes a difference.
I think you would be best off by going over the sourcecode of L.GridLayer which L.TileLayer is extended from. The _pruneTiles function would be a good starting point:
https://github.com/Leaflet/Leaflet/blob/master/src/layer/tile/GridLayer.js#L204
You Can find a tutorial for embedding Leaflet in a C# app in this book:
Leaflet.js Essentials - Chapter 6

how to draw polygons over shape files in c#.net?

I have some shape files (shp,shx,dbf) and I want to load them in a division using c#.net, currently I am using easy Gis for web, I want to add the ability for the user to be able to draw a polygon over map so that a closed area is defined , and I want this polygon coordinates so that I can define whether some places are in polygon or not.
Any Idea what is the best plugin or anything for .net , is it possible to be done in Easy GIS?
I would appreciate your help.thanks
P.S:
I should mention that I need this to be done on a webpage, so desktop softwares are useless.
after days of searching ,I found the follwoing link very useful: wiki.openstreetmap.org/wiki/OpenLayers_Local_Tiles_Example OpenLayers is a free javascript libray that gives you lots of functionality like drawing polygons and etc ...

How to create an interactive Map using Images

I have a couple of images that I would like to create an interactive map of in Silverlight and WPF. The pictures are of States and counties. I tried doing some search on how this is done but have not been able to find a good example on how to go about accomplishing this. So I would appreciate your help. Thanks in advance.
I was involved in creating a Xaml World map from scratch (below) and that alone took nearly a day for a stylised polygon version (no fine detail)....
I have since purchased a Wacom Bamboo tablet & stylus and found that to be about 5 times faster to work with compared with a mouse.
Quoting myself: "You import a map as a background image and use the pen tool to dot-to-dot trace around the country. Combine all those path segments into a single path. Then create a separate poly-path for each state (close them to allow for a fill)."
Once you create them you can name the individual country polygons and connect up mouse logic to make them all glow on mouse over or change colour on press etc.
Basically all the other stuff on that screen are user controls and custom controls. Work out the behaviour you want and create controls to suit your own needs.
In your instance you can use less accurate polygons as they will only be for hit-testing and highlighting and you will want to retain the actual map images under the polygons.

Categories