Loading app/src/js/LayerCollection.js +28 −24 Original line number Diff line number Diff line Loading @@ -193,14 +193,17 @@ export default L.LayerCollection = L.Class.extend({ version: "1.1.0", request: "GetFeature", typename: map.target().toUpperCase() + "_POLY", outputFormat: "application/json; subtype=geojson" outputFormat: "application/json; subtype=geojson", PropertyName: "clean_feature", Filter: "<Filter><PropertyIsLike wildcard='*' singleChar='.' escape='!'><PropertyName>clean_feature</PropertyName><Literal>*</Literal></PropertyIsLike></Filter>" }; let customParams = { bbox: map.getBounds().toBBoxString() }; // let customParams = { // bbox: map.getBounds().toBBoxString() // }; let parameters = L.Util.extend(defaultParameters, customParams); let parameters = L.Util.extend(defaultParameters); console.log(geoJsonUrl + L.Util.getParamString(parameters)); let thisContext = this; Loading @@ -211,29 +214,30 @@ export default L.LayerCollection = L.Class.extend({ // MapServer is having problems returning a JSON when requesting polygon features. // Adds XML at the end for some reason. error: function(response) { let lines = response.responseText.split("\n"); // error: function(response) { // let lines = response.responseText.split("\n"); // Remove lines in XML format let numLines = lines.length; let lineCount = 0; while (lineCount < numLines) { if (lines[lineCount].includes("Content-type")) { break; } lineCount++; } lines.splice(lineCount, numLines - 1); let jsonString = lines.join("\n"); // // Remove lines in XML format // let numLines = lines.length; // let lineCount = 0; // while (lineCount < numLines) { // if (lines[lineCount].includes("Content-type")) { // break; // } // lineCount++; // } // lines.splice(lineCount, numLines - 1); // let jsonString = lines.join("\n"); let data = $.parseJSON(jsonString); let sortedFeatures = thisContext.sortFeatures(data["features"]); data["features"] = sortedFeatures; thisContext._wfsLayer.clearLayers(); thisContext._wfsLayer.addData(data); }, // let data = $.parseJSON(jsonString); // let sortedFeatures = thisContext.sortFeatures(data["features"]); // data["features"] = sortedFeatures; // thisContext._wfsLayer.clearLayers(); // thisContext._wfsLayer.addData(data); // }, success: function(data) { console.log("GOT HERE"); let sortedFeatures = thisContext.sortFeatures(data["features"]); data["features"] = sortedFeatures; thisContext._wfsLayer.clearLayers(); Loading jupyter/examples/Example.ipynb +58 −39 Original line number Diff line number Diff line %% Cell type:code id: tags: ``` python # This is used to install all the correct packages using pip import sys !{sys.executable} -m pip install ipywidgets !{sys.executable} -m pip install ipyleaflet !{sys.executable} -m pip install geojson !{sys.executable} -m pip install shapely ``` %% Cell type:code id: tags: ``` python import os import sys module_path = os.path.abspath(os.path.join('../src/')) if module_path not in sys.path: sys.path.append(module_path) ``` %% Cell type:code id: tags: ``` python def click_handler(feature=None, **kwargs): click_handler.counter += 1 if click_handler.counter == 1: # try: # Duplicates onclick call and second call passes in feature as None # if feature["geometry"]["type"] == "Point": # location = feature["geometry"]["coordinates"] # else: # location = feature["geometry"]["coordinates"][0][0] click_handler.feature = feature if feature['name'] == 'Olympus Mons': print("FOUND OLYMPUS") # popup = ipyleaflet.Popup( # location=location, # child=ipywidgets.HTML(feature['name']), # close_button=True, # auto_close=True, # close_on_escape_key=False # ) # map.planet_map.add_layer(popup) elif click_handler.counter == 2: # except Exception as e: location = kwargs['coordinates'] popup = ipyleaflet.Popup( location=location, child=ipywidgets.HTML(click_handler.feature['name']), close_button=True, auto_close=True, close_on_escape_key=False ) map.planet_map.add_layer(popup) click_handler.counter = 0 return click_handler.counter = 0 click_handler.feature = None ``` %% Cell type:code id: tags: ``` python import CartoCosmos as l import urllib.request import json import ipyleaflet import ipywidgets map = l.planetary_maps('mars') # map.add_wkt("POLYGON ((-187.03125 22.851563, -187.03125 35.15625, -167.34375 35.15625, -167.34375 22.851563, -187.03125 22.851563))") map.display_map() # geoJsonUrl = "https://astrocloud.wr.usgs.gov/dataset/data/nomenclature/" + "MARS" + "/WFS" def hover_handler(event=None, feature=None, id=None, properties=None): label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) label.value = properties['name'] geoJsonUrl = "https://astrocloud.wr.usgs.gov/dataset/data/nomenclature/MERCURY/WFS?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&srsName=EPSG%3A4326&MAXFEATURES=2" with urllib.request.urlopen(geoJsonUrl) as url: jsonp = json.loads(url.read()) geo_json = ipyleaflet.GeoJSON(data=jsonp) geo_json.on_click(hover_handler) map.planet_map.add_layer(geo_json) break_out = False while(not break_out): try: with urllib.request.urlopen(geoJsonUrl) as url: jsonp = json.loads(url.read()) geo_json = ipyleaflet.GeoJSON(data=jsonp, name="WFS") geo_json.point_style = { 'fillOpacity': 1, 'radius': 3 } geo_json.on_click(click_handler) map.planet_map.add_layer(geo_json) break_out = True except: continue ``` %% Output --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-71051d1a3868> in hover_handler(event, feature, id, properties) 13 14 def hover_handler(event=None, feature=None, id=None, properties=None): ---> 15 label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) 16 label.value = properties['name'] 17 AttributeError: module 'ipyleaflet' has no attribute 'Label' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) TypeError: hover_handler() got an unexpected keyword argument 'type' --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-71051d1a3868> in hover_handler(event, feature, id, properties) 13 14 def hover_handler(event=None, feature=None, id=None, properties=None): ---> 15 label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) 16 label.value = properties['name'] 17 AttributeError: module 'ipyleaflet' has no attribute 'Label' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) TypeError: hover_handler() got an unexpected keyword argument 'type' %% Cell type:code id: tags: ``` python ``` Loading
app/src/js/LayerCollection.js +28 −24 Original line number Diff line number Diff line Loading @@ -193,14 +193,17 @@ export default L.LayerCollection = L.Class.extend({ version: "1.1.0", request: "GetFeature", typename: map.target().toUpperCase() + "_POLY", outputFormat: "application/json; subtype=geojson" outputFormat: "application/json; subtype=geojson", PropertyName: "clean_feature", Filter: "<Filter><PropertyIsLike wildcard='*' singleChar='.' escape='!'><PropertyName>clean_feature</PropertyName><Literal>*</Literal></PropertyIsLike></Filter>" }; let customParams = { bbox: map.getBounds().toBBoxString() }; // let customParams = { // bbox: map.getBounds().toBBoxString() // }; let parameters = L.Util.extend(defaultParameters, customParams); let parameters = L.Util.extend(defaultParameters); console.log(geoJsonUrl + L.Util.getParamString(parameters)); let thisContext = this; Loading @@ -211,29 +214,30 @@ export default L.LayerCollection = L.Class.extend({ // MapServer is having problems returning a JSON when requesting polygon features. // Adds XML at the end for some reason. error: function(response) { let lines = response.responseText.split("\n"); // error: function(response) { // let lines = response.responseText.split("\n"); // Remove lines in XML format let numLines = lines.length; let lineCount = 0; while (lineCount < numLines) { if (lines[lineCount].includes("Content-type")) { break; } lineCount++; } lines.splice(lineCount, numLines - 1); let jsonString = lines.join("\n"); // // Remove lines in XML format // let numLines = lines.length; // let lineCount = 0; // while (lineCount < numLines) { // if (lines[lineCount].includes("Content-type")) { // break; // } // lineCount++; // } // lines.splice(lineCount, numLines - 1); // let jsonString = lines.join("\n"); let data = $.parseJSON(jsonString); let sortedFeatures = thisContext.sortFeatures(data["features"]); data["features"] = sortedFeatures; thisContext._wfsLayer.clearLayers(); thisContext._wfsLayer.addData(data); }, // let data = $.parseJSON(jsonString); // let sortedFeatures = thisContext.sortFeatures(data["features"]); // data["features"] = sortedFeatures; // thisContext._wfsLayer.clearLayers(); // thisContext._wfsLayer.addData(data); // }, success: function(data) { console.log("GOT HERE"); let sortedFeatures = thisContext.sortFeatures(data["features"]); data["features"] = sortedFeatures; thisContext._wfsLayer.clearLayers(); Loading
jupyter/examples/Example.ipynb +58 −39 Original line number Diff line number Diff line %% Cell type:code id: tags: ``` python # This is used to install all the correct packages using pip import sys !{sys.executable} -m pip install ipywidgets !{sys.executable} -m pip install ipyleaflet !{sys.executable} -m pip install geojson !{sys.executable} -m pip install shapely ``` %% Cell type:code id: tags: ``` python import os import sys module_path = os.path.abspath(os.path.join('../src/')) if module_path not in sys.path: sys.path.append(module_path) ``` %% Cell type:code id: tags: ``` python def click_handler(feature=None, **kwargs): click_handler.counter += 1 if click_handler.counter == 1: # try: # Duplicates onclick call and second call passes in feature as None # if feature["geometry"]["type"] == "Point": # location = feature["geometry"]["coordinates"] # else: # location = feature["geometry"]["coordinates"][0][0] click_handler.feature = feature if feature['name'] == 'Olympus Mons': print("FOUND OLYMPUS") # popup = ipyleaflet.Popup( # location=location, # child=ipywidgets.HTML(feature['name']), # close_button=True, # auto_close=True, # close_on_escape_key=False # ) # map.planet_map.add_layer(popup) elif click_handler.counter == 2: # except Exception as e: location = kwargs['coordinates'] popup = ipyleaflet.Popup( location=location, child=ipywidgets.HTML(click_handler.feature['name']), close_button=True, auto_close=True, close_on_escape_key=False ) map.planet_map.add_layer(popup) click_handler.counter = 0 return click_handler.counter = 0 click_handler.feature = None ``` %% Cell type:code id: tags: ``` python import CartoCosmos as l import urllib.request import json import ipyleaflet import ipywidgets map = l.planetary_maps('mars') # map.add_wkt("POLYGON ((-187.03125 22.851563, -187.03125 35.15625, -167.34375 35.15625, -167.34375 22.851563, -187.03125 22.851563))") map.display_map() # geoJsonUrl = "https://astrocloud.wr.usgs.gov/dataset/data/nomenclature/" + "MARS" + "/WFS" def hover_handler(event=None, feature=None, id=None, properties=None): label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) label.value = properties['name'] geoJsonUrl = "https://astrocloud.wr.usgs.gov/dataset/data/nomenclature/MERCURY/WFS?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&srsName=EPSG%3A4326&MAXFEATURES=2" with urllib.request.urlopen(geoJsonUrl) as url: jsonp = json.loads(url.read()) geo_json = ipyleaflet.GeoJSON(data=jsonp) geo_json.on_click(hover_handler) map.planet_map.add_layer(geo_json) break_out = False while(not break_out): try: with urllib.request.urlopen(geoJsonUrl) as url: jsonp = json.loads(url.read()) geo_json = ipyleaflet.GeoJSON(data=jsonp, name="WFS") geo_json.point_style = { 'fillOpacity': 1, 'radius': 3 } geo_json.on_click(click_handler) map.planet_map.add_layer(geo_json) break_out = True except: continue ``` %% Output --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-71051d1a3868> in hover_handler(event, feature, id, properties) 13 14 def hover_handler(event=None, feature=None, id=None, properties=None): ---> 15 label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) 16 label.value = properties['name'] 17 AttributeError: module 'ipyleaflet' has no attribute 'Label' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) TypeError: hover_handler() got an unexpected keyword argument 'type' --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-71051d1a3868> in hover_handler(event, feature, id, properties) 13 14 def hover_handler(event=None, feature=None, id=None, properties=None): ---> 15 label = ipyleaflet.Label(layout=ipyleaflet.Layout(width='100%')) 16 label.value = properties['name'] 17 AttributeError: module 'ipyleaflet' has no attribute 'Label' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) TypeError: hover_handler() got an unexpected keyword argument 'type' %% Cell type:code id: tags: ``` python ```