Trying to decide a better way of abstracting a 3rd party javascript API, specifically Google Maps API objects.
My first attempt was something like this:
nmap.Polygon = function () {
};
nmap.Polygon.prototype = new google.maps.Polygon();
This looks good until I try to act on the object with other parts of the Google Maps API. For example:
var poly = new nmap.Polygon(options);
poly.setMap(googleMapObject);
This fails silently.
Is my only other option to go with a composition pattern?
IE:
var Polygon = function(){
this.realPolygon = new google.maps.Polygon();
}
If what you want is a common abstraction for mapping APIs you should check out Mapstraction. Supports Google Maps v3 as well as about 15 other providers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.