Skip to content

Commit

Permalink
(Android / iOS / browser) Add: Ability to change clickability of POI m…
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 authored and paulnagle committed Jan 29, 2023
1 parent be6c1f5 commit 382b32a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
26 changes: 24 additions & 2 deletions src/android/plugin/google/maps/PluginMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
private String mapId;
private boolean isVisible = true;
private boolean isClickable = true;
private boolean clickableIcons = true;
private final String TAG = mapId;
private String mapDivId;
public Map<String, PluginEntry> plugins = new ConcurrentHashMap<String, PluginEntry>();
Expand Down Expand Up @@ -412,6 +413,15 @@ public void onClick(View v) {
}


if (preferences.has("clickableIcons")) {
clickableIcons = preferences.getBoolean("clickableIcons");
}


if (preferences.has("building")) {
map.setBuildingsEnabled(preferences.getBoolean("building"));
}

}

// Set event listener
Expand Down Expand Up @@ -1334,6 +1344,13 @@ public void run() {
}
}

if (preferences.has("building")) {
map.setBuildingsEnabled(preferences.getBoolean("building"));
}

if (preferences.has("clickableIcons")) {
clickableIcons = preferences.getBoolean("clickableIcons");
}

if (preferences.has("restriction")) {
Object target = preferences.get("restriction");
Expand All @@ -1355,15 +1372,15 @@ public void run() {
if (zoom.has("minZoom")) {
map.setMinZoomPreference((float)zoom.getDouble("minZoom"));
} else {
map.setMinZoomPreference(0);
map.setMinZoomPreference(2);
}
if (zoom.has("maxZoom")) {
map.setMaxZoomPreference((float) zoom.getDouble("maxZoom"));
} else {
map.setMaxZoomPreference(23);
}
} else {
map.setMinZoomPreference(0);
map.setMinZoomPreference(2);
map.setMaxZoomPreference(23);
}
map.setLatLngBoundsForCameraTarget(null);
Expand Down Expand Up @@ -2956,6 +2973,11 @@ public void onIndoorLevelActivated(IndoorBuilding building) {
}
@Override
public void onPoiClick(PointOfInterest pointOfInterest) {
if (!this.clickableIcons) {
this.onMapClick(pointOfInterest.latLng);
return;
}

String js = String.format(Locale.ENGLISH, "javascript:if('%s' in plugin.google.maps){plugin.google.maps['%s']({evtName: '%s', callback:'_onMapEvent', args:['%s', \"%s\", new plugin.google.maps.LatLng(%f, %f)]});}",
mapId, mapId, "poi_click", pointOfInterest.placeId, pointOfInterest.name, pointOfInterest.latLng.latitude, pointOfInterest.latLng.longitude);
jsCallback(js);
Expand Down
21 changes: 9 additions & 12 deletions src/browser/PluginMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function PluginMap(mapId, options) {
minZoom: 2,
disableDefaultUI: true,
zoomControl: true,
center: {lat: 0, lng: 0}
center: {lat: 0, lng: 0},
clickableIcons: true
};

if (options) {
Expand Down Expand Up @@ -167,6 +168,10 @@ function PluginMap(mapId, options) {
mapInitOptions.maxZoom = options.preferences.zoom.maxZoom;
}
}

if ('clickableIcons' in options.preferences) {
mapInitOptions.clickableIcons = options.preferences.clickableIcons === true;
}
}
}

Expand Down Expand Up @@ -316,17 +321,9 @@ PluginMap.prototype.setOptions = function(onSuccess, onError, args) {
}
}

console.log(mapInitOptions);
// if ('restriction' in options.preferences) {
// var boundsLimit = null;
// if (options.preferences.restriction && options.preferences.restriction.length > 0) {
// boundsLimit = new google.maps.LatLngBounds();
// options.preferences.restriction.forEach(function(pos) {
// boundsLimit.extend(pos);
// });
// }
// map.set('boundsLimit', boundsLimit);
// }
if ('clickableIcons' in options.preferences) {
mapInitOptions.clickableIcons = options.preferences.clickableIcons === true;
}

}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ios/GoogleMaps/PluginMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ - (void)_setOptions:(NSDictionary *)initOptions requestMethod:(NSString *)reques
NSDictionary *restriction = [preferences objectForKey:@"restriction"];
[self _setCameraRestriction:restriction];
}

// building
if ([preferences valueForKey:@"building"] != nil) {
self.mapCtrl.map.buildingsEnabled = [[preferences valueForKey:@"building"] boolValue];
}
}

//styles
Expand Down

0 comments on commit 382b32a

Please sign in to comment.