📜 ⬆️ ⬇️

2GIS API 2.0

We told about the new 2GIS almost everything. More precisely, almost everything that the user faces. It is time to talk about what he has "under the hood." Guess it's about API 2GIS.

If you have used the new 2GIS since its appearance, you have already seen 2GIS API 2.0 in action. Today, he came out of beta status and became available to everyone. Separately, we want to thank those who participated in the testing: guys, thank you, you helped make the product exactly the way it turned out. That is more than good.

If you can not wait to try the new API, then look here . Those who like not only to watch but also to read, look under the cat.
')



What's inside?


API 2.0 is based on the Leaflet open-source library. It is simple, fast and actively developing. The amount of code has been noticeably reduced, without any damage to the functionality.

For example, a typical case of using API cards is to display a marker and open a balloon when clicking on it.

It was (API 1.0):

var position = new DG.GeoPoint(82.89, 54.98); var marker = new DG.Markers.MarkerWithBalloon({ geoPoint: position, balloonOptions: { contentHtml: ' !' } }); map.markers.add(marker); 

It became (API 2.0):

 DG.marker([54.98, 82.89]).addTo(map).bindPopup(' !'); 

Changes for the better are visible not only to developers, but also to users. Animations when moving or scaling maps have become beautiful and smooth.

Also, new basic functions appeared in API 2.0, which were absent in the first version - from the ability to specify HTML code instead of a marker image and to read data in GeoJSON format.

Design


The appearance of the product is important for us not less accurate and complete information. And she is very important to us.

Therefore, we draw the map down to the smallest details. Simulated famous buildings in 3D. Picked up colors to focus on the most necessary, depending on the selected scale.

And they made two colors for the interface: dark and light. You just have to choose the one that fits better with the design of your site.

The choice of themes is made at the API connection stage using the skin parameter:

 <script src="http://maps.api.2gis.ru/2.0/loader.js?skin=light" data-id="dgLoader"></script> 





Modularity


It happens that to solve the problem, all API functions are not required. Therefore, we have made the new API modular. We offer two ready-made packages - full and basic.

The basic package contains the basic functions:

- map;
- markers;
- baluns;
- raster layers;
- GeoJSON layer;
- geometry;
- groups;
- full screen control;
- scale bar.

The full package additionally includes:

- tips;
- a ruler for measuring distances;
- control geolocation;
- function to work with Ajax;
- class for working with WKT-format;
- geokliker.

But if you need a unique set of functions, you can build to fit your needs.

And besides the modules from the pre-installed packages, you can connect any external module of the Leaflet library, for example, Clusterizer or Heatmap . Or even develop your own module that will cover your specific needs.

Easier, easier, faster


All JS-and CSS-code of the new version of the API is two times less than the old one. This dramatically accelerated the loading of pages with the map:

Loader (KB)Javascript code (kb)CSS (KB)
API 1.01.967159.0
API 2.0 (Full package)2.437744.9
API 2.0 (Basic package)2.421424.9

The data are for the Google Chrome browser. Maps API 2.0 CSS also includes base64-encoded images.

Device and browser support


We strive to ensure that the card works equally well both on large monitors and small screens of mobile devices. She is ready to control with her fingers: we made support for inertia, multitouch and all major gestures.

Fullscreen mode, which is especially useful on small screens, works using the fullscreen API (in those browsers where this is possible). And the positions of the controls are adjusted to the type of device so that it is convenient to click on them:



Geoclicker and building entrances


As before, the user can click on any building and find out complete information about it. Information painstakingly collected by our experts and verified several times a year. For example, which organizations are located in the building:



Further, you can see detailed information about each of them:



But we went even further. Now 2GIS helps the user not only to find an organization, but also to get into it. Our employees visited more than 1 million companies and found out where the entrances to them are. Even such:



Finally, it became possible to send long text descriptions in the spirit of the story in the spirit of “to get to our company, go straight from the gateway, up and turn right at the pillar” and replace them with one button “Find Entry”.

Openness


2GIS supports the Open Source movement. Developers should like the fact that we have opened the source code of the API maps. This means that anyone can easily study it and develop their own module.

There is no need to wait for the correction of one or another error in the code or documentation: you can send a pull request, we will consider and accept it. All API map code is available on GitHub .

Data quality


Nothing has changed here - we still keep the level of quality at the highest level. On the 2GIS map you will find not only all buildings, but also parks, streets, fountains, fences, garages and strange structures that exist in any city.

Examples of using


The new version of the API has already taken advantage of the first partners. Formally, our online 2GIS is also one of them. You can get into the list of partners and you are waiting for you here .

Source: https://habr.com/ru/post/229097/


All Articles